3#ifndef _TIME_SHIELD_JULIAN_CONVERSIONS_HPP_INCLUDED
4#define _TIME_SHIELD_JULIAN_CONVERSIONS_HPP_INCLUDED
31 if (month == 1 || month == 2) {
35 const double a = std::floor(
static_cast<double>(
year) / 100.0);
36 const double b = 2.0 - a + std::floor(a / 4.0);
37 const double jd = std::floor(365.25 * (
static_cast<double>(
year) + 4716.0))
38 + std::floor(30.6000001 * (
static_cast<double>(month) + 1.0))
40 return static_cast<jd_t>(jd);
44 const int64_t a = (14LL - month) / 12LL;
45 const int64_t y =
year + 4800LL - a;
46 const int64_t m = month + 12LL * a - 3LL;
47 const int64_t jdn = day
48 + (153LL * m + 2LL) / 5LL
54 return static_cast<jdn_t>(jdn);
61 int millisecond)
noexcept {
62 return (
static_cast<double>(hour) / 24.0) +
63 (
static_cast<double>(minute) / (24.0 * 60.0)) +
64 ((
static_cast<double>(second) +
static_cast<double>(millisecond) / 1000.0)
74 return static_cast<jd_t>(2440587.5)
110 uint32_t millisecond = 0) noexcept {
113 static_cast<int>(hour),
114 static_cast<int>(minute),
115 static_cast<int>(second),
116 static_cast<int>(millisecond)),
117 static_cast<int64_t
>(month),
118 static_cast<int64_t
>(
year));
137 int millisecond = 0) noexcept {
140 static_cast<int64_t
>(month),
141 static_cast<int64_t
>(
year));
166 static_cast<int64_t
>(day),
167 static_cast<int64_t
>(month),
168 static_cast<int64_t
>(
year));
179 static_cast<int64_t
>(day),
180 static_cast<int64_t
>(month),
181 static_cast<int64_t
>(
year));
202 jd_t& out)
noexcept {
220 jdn_t& out)
noexcept {
224 const int64_t a = (14LL -
static_cast<int64_t
>(month)) / 12LL;
225 const int64_t y =
static_cast<int64_t
>(
year) + 4800LL - a;
226 const int64_t m =
static_cast<int64_t
>(month) + 12LL * a - 3LL;
227 const int64_t jdn =
static_cast<int64_t
>(day)
228 + (153LL * m + 2LL) / 5LL
237 out =
static_cast<jdn_t>(jdn);
Configuration macros for the library.
Header file with time-related constants.
constexpr int64_t SEC_PER_DAY
Seconds per day.
TIME_SHIELD_CONSTEXPR ts_t ts(year_t year, int month, int day)
Alias for to_timestamp.
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).
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).
jd_t gregorian_to_jd(double day, int64_t month, int64_t year) noexcept
Convert Gregorian date (with optional fractional day) to Julian Date (JD).
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.
jdn_t gregorian_to_jdn(uint32_t day, uint32_t month, uint32_t year) noexcept
Convert Gregorian date to Julian Day Number (JDN).
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.
Type definitions for time-related units and formats.
Header file with time-related validation functions.