3#ifndef TIME_SHIELD_HEADER_ASTRONOMY_JULIAN_CONVERSIONS_HPP_INCLUDED
4#define TIME_SHIELD_HEADER_ASTRONOMY_JULIAN_CONVERSIONS_HPP_INCLUDED
27 if (month == 1 || month == 2) {
31 const double a = std::floor(
static_cast<double>(
year) / 100.0);
32 const double b = 2.0 - a + std::floor(a / 4.0);
33 const double jd = std::floor(365.25 * (
static_cast<double>(
year) + 4716.0))
34 + std::floor(30.6000001 * (
static_cast<double>(month) + 1.0))
36 return static_cast<jd_t>(jd);
40 const int64_t a = (14LL - month) / 12LL;
41 const int64_t y =
year + 4800LL - a;
42 const int64_t m = month + 12LL * a - 3LL;
43 const int64_t jdn = day
44 + (153LL * m + 2LL) / 5LL
50 return static_cast<jdn_t>(jdn);
57 int millisecond)
noexcept {
58 return (
static_cast<double>(hour) / 24.0) +
59 (
static_cast<double>(minute) / (24.0 * 60.0)) +
60 ((
static_cast<double>(second) +
static_cast<double>(millisecond) / 1000.0)
70 return static_cast<jd_t>(2440587.5)
97 int millisecond = 0) noexcept {
100 static_cast<int64_t
>(month),
101 static_cast<int64_t
>(
year));
126 static_cast<int64_t
>(day),
127 static_cast<int64_t
>(month),
128 static_cast<int64_t
>(
year));
149 jd_t& out)
noexcept {
167 jdn_t& out)
noexcept {
171 const int64_t a = (14LL -
static_cast<int64_t
>(month)) / 12LL;
172 const int64_t y =
static_cast<int64_t
>(
year) + 4800LL - a;
173 const int64_t m =
static_cast<int64_t
>(month) + 12LL * a - 3LL;
174 const int64_t jdn =
static_cast<int64_t
>(day)
175 + (153LL * m + 2LL) / 5LL
184 out =
static_cast<jdn_t>(jdn);
constexpr int64_t SEC_PER_DAY
Seconds per day.
TIME_SHIELD_CONSTEXPR T year(ts_t ts=time_shield::ts())
Alias for year_of function.
int64_t ts_t
Unix timestamp in seconds since 1970‑01‑01T00:00:00Z.
double fts_t
Floating-point timestamp (fractional seconds since epoch).
uint64_t jdn_t
Julian Day Number (whole days since Julian epoch).
int64_t year_t
Year as an integer (e.g., 2024).
double mjd_t
Modified Julian Date (JD − 2400000.5).
double jd_t
Julian Date (days since -4713‑11‑24T12:00:00Z).
ts_t ts() noexcept
Get the current UTC timestamp in seconds.
TIME_SHIELD_CONSTEXPR bool is_valid_date(T1 year, T2 month, T2 day) noexcept
Checks the correctness of the specified date.
TIME_SHIELD_CONSTEXPR bool is_valid_time(T1 hour, T1 min, T1 sec, T2 ms=0) noexcept
Checks the correctness of the specified time.
jdn_t gregorian_dmy_to_jdn_unchecked(int64_t day, int64_t month, int64_t year) noexcept
double day_fraction_from_hms(int hour, int minute, int second, int millisecond) noexcept
jd_t gregorian_dmy_to_jd_unchecked(double day, int64_t month, int64_t year) noexcept
Main namespace for the Time Shield library.
mjd_t ts_to_mjd(ts_t ts) noexcept
Convert Unix timestamp (seconds) to Modified Julian Date (MJD).
mjd_t fts_to_mjd(fts_t ts) noexcept
Convert Unix timestamp (floating seconds) to Modified Julian Date (MJD).
bool try_gregorian_ymd_to_jd(year_t year, int month, int day, int hour, int minute, int second, int millisecond, jd_t &out) noexcept
Try converting Gregorian date/time components to Julian Date (JD) using year-first order.
jd_t fts_to_jd(fts_t ts) noexcept
Convert Unix timestamp (floating seconds) to Julian Date (JD).
jd_t ts_to_jd(ts_t ts) noexcept
Convert Unix timestamp (seconds) to Julian Date (JD).
bool try_gregorian_ymd_to_jdn(year_t year, int month, int day, jdn_t &out) noexcept
Try converting Gregorian date to Julian Day Number (JDN) using year-first order.
jdn_t gregorian_ymd_to_jdn(year_t year, int month, int day) noexcept
Convert Gregorian date to Julian Day Number (JDN) using year-first order.
jd_t gregorian_ymd_to_jd(year_t year, int month, int day, int hour=0, int minute=0, int second=0, int millisecond=0) noexcept
Convert Gregorian date/time components to Julian Date (JD) using year-first order.