3#ifndef _TIME_SHIELD_ASTRONOMY_CONVERSIONS_HPP_INCLUDED
4#define _TIME_SHIELD_ASTRONOMY_CONVERSIONS_HPP_INCLUDED
31 return static_cast<jd_t>(2440587.5)
49 if (month == 1 || month == 2) {
53 const double a = std::floor(
static_cast<double>(
year) / 100.0);
54 const double b = 2.0 - a + std::floor(a / 4.0);
55 const double jdn = std::floor(365.25 * (
static_cast<double>(
year) + 4716.0))
56 + std::floor(30.6000001 * (
static_cast<double>(month) + 1.0))
58 return static_cast<jd_t>(jdn);
77 uint32_t millisecond = 0) noexcept {
79 (
static_cast<double>(hour) / 24.0) +
80 (
static_cast<double>(minute) / (24.0 * 60.0)) +
81 ((
static_cast<double>(second) +
static_cast<double>(millisecond) / 1000.0)
84 static_cast<int64_t
>(month),
85 static_cast<int64_t
>(
year));
109 const uint64_t a = (14ULL -
static_cast<uint64_t
>(month)) / 12ULL;
110 const uint64_t y =
static_cast<uint64_t
>(
year) + 4800ULL - a;
111 const uint64_t m =
static_cast<uint64_t
>(month) + 12ULL * a - 3ULL;
112 const uint64_t jdn =
static_cast<uint64_t
>(day)
113 + (153ULL * m + 2ULL) / 5ULL
119 return static_cast<jdn_t>(jdn);
128 constexpr MoonPhaseSineCosine(
double phase_sin_value,
double phase_cos_value,
double phase_angle_rad_value) noexcept
140 double temp = (
static_cast<double>(
fts_to_jd(
ts)) - 2451550.1) / 29.530588853;
141 temp = temp - std::floor(temp);
142 if (temp < 0.0) temp += 1.0;
159 const auto result = calculator.
compute(
static_cast<double>(
ts));
Geocentric Moon phase calculator and result helpers.
Moon phase calculator (geocentric approximation).
bool is_new_moon_window(double unix_utc_s, double window_seconds=kDefaultQuarterWindow_s) const noexcept
Check whether timestamp is inside a window around new moon.
bool is_first_quarter_window(double unix_utc_s, double window_seconds=kDefaultQuarterWindow_s) const noexcept
Check whether timestamp is inside a window around first quarter.
MoonPhaseResult compute(double unix_utc_s) const noexcept
Compute full set of Moon phase parameters for given UTC timestamp.
MoonQuarterInstants quarter_instants_unix(double unix_utc_s) const noexcept
Quarter instants around the provided timestamp as a structured result (Unix UTC seconds).
static constexpr double kDefaultQuarterWindow_s
Default window around phase events (12h).
bool is_last_quarter_window(double unix_utc_s, double window_seconds=kDefaultQuarterWindow_s) const noexcept
Check whether timestamp is inside a window around last quarter.
bool is_full_moon_window(double unix_utc_s, double window_seconds=kDefaultQuarterWindow_s) const noexcept
Check whether timestamp is inside a window around full moon.
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).
double mjd_t
Modified Julian Date (JD − 2400000.5).
double jd_t
Julian Date (days since -4713‑11‑24T12:00:00Z).
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).
double moon_age_days_jd_approx(fts_t ts) noexcept
Get lunar age in days (~0..29.53) using a simple Julian Day approximation.
bool is_new_moon_window(fts_t ts, double window_seconds=astronomy::MoonPhase::kDefaultQuarterWindow_s) noexcept
Check if timestamp falls into the new moon window (default \pm12h).
jd_t fts_to_jd(fts_t ts) noexcept
Convert Unix timestamp (floating seconds) to Julian Date (JD).
bool is_last_quarter_window(fts_t ts, double window_seconds=astronomy::MoonPhase::kDefaultQuarterWindow_s) noexcept
Check if timestamp falls into the last quarter window (default \pm12h).
double moon_age_days(fts_t ts) noexcept
Get lunar age in days (~0..29.53).
jd_t ts_to_jd(ts_t ts) noexcept
Convert Unix timestamp (seconds) to Julian Date (JD).
double moon_phase(fts_t ts) noexcept
Get lunar phase in range [0..1) using the geocentric MoonPhase calculator.
double moon_phase_jd_approx(fts_t ts) noexcept
Get lunar phase in range [0..1) using a simple Julian Day approximation.
bool is_full_moon_window(fts_t ts, double window_seconds=astronomy::MoonPhase::kDefaultQuarterWindow_s) noexcept
Check if timestamp falls into the full moon window (default \pm12h).
jdn_t gregorian_to_jdn(uint32_t day, uint32_t month, uint32_t year) noexcept
Convert Gregorian date to Julian Day Number (JDN).
astronomy::MoonQuarterInstants moon_quarters(fts_t ts) noexcept
Quarter instants around the provided timestamp.
double moon_illumination(fts_t ts) noexcept
Get illuminated fraction in range [0..1] using the geocentric MoonPhase calculator.
bool is_first_quarter_window(fts_t ts, double window_seconds=astronomy::MoonPhase::kDefaultQuarterWindow_s) noexcept
Check if timestamp falls into the first quarter window (default \pm12h).
MoonPhaseSineCosine moon_phase_sincos(fts_t ts) noexcept
Get sin/cos of the lunar phase angle (continuous signal without wrap-around).
sin/cos helper for the Moon phase angle.
double phase_sin
sin(phase angle), continuous around 0/2pi.
constexpr MoonPhaseSineCosine()=default
double phase_angle_rad
Phase angle in radians [0..2*pi).
double phase_cos
cos(phase angle), continuous around 0/2pi.
constexpr MoonPhaseSineCosine(double phase_sin_value, double phase_cos_value, double phase_angle_rad_value) noexcept
double phase
Phase fraction in [0..1). 0=new moon, 0.5=full moon.
double age_days
Age of the Moon in days since new moon (approx).
double illumination
Illuminated fraction in [0..1].
Lunar quarter instants (Unix UTC seconds, floating).
Type definitions for time-related units and formats.