Antkeeper  0.0.1
gregorian.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_PHYSICS_TIME_GREGORIAN_HPP
21 #define ANTKEEPER_PHYSICS_TIME_GREGORIAN_HPP
22 
24 
25 namespace physics {
26 namespace time {
27 
29 namespace gregorian {
30 
46 template <class T>
47 T to_jd(int year, int month, int day, int hour, int minute, T second, T utc)
48 {
49  T jdn = static_cast<T>((1461 * (year + 4800 + (month - 14) / 12)) / 4 + (367 * (month - 2 - 12 * ((month - 14) / 12))) / 12 - (3 * ((year + 4900 + (month - 14) / 12) / 100)) / 4 + day - 32075);
50  return jdn + static_cast<T>(hour - 12) / T(24) + static_cast<T>(minute) / T(1440) + static_cast<T>(second) / T(86400) - utc / T(24);
51 }
52 
66 template <class T>
67 T to_ut1(int year, int month, int day, int hour, int minute, T second, T utc)
68 {
69  return physics::time::jd::to_ut1<T>(to_jd<T>(year, month, day, hour, minute, second, utc));
70 }
71 
72 } // namespace gregorian
73 
74 } // namespace time
75 } // namespace physics
76 
77 #endif // ANTKEEPER_PHYSICS_TIME_GREGORIAN_HPP
T to_jd(int year, int month, int day, int hour, int minute, T second, T utc)
Calculates the JD time from a Gregorian date and time.
Definition: gregorian.hpp:47
T to_ut1(int year, int month, int day, int hour, int minute, T second, T utc)
Calculates the UT1 time from a Gregorian date and time.
Definition: gregorian.hpp:67
Physics.
Definition: constants.hpp:23