Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
time_shield::detail Namespace Reference

Namespaces

namespace  anonymous_namespace{fast_date.hpp}
namespace  format_parse

Classes

struct  DaySplit
struct  FastDate
class  NtpClientCore
 Core NTP query logic that parses packets and computes offsets. More...
struct  NtpPacket
 NTP packet layout (48 bytes). More...
struct  UdpRequest
 UDP request parameters for NTP transactions. More...
class  IUdpTransport
 Abstract UDP transport interface for NTP queries. More...
class  UdpTransportPosix
 POSIX UDP transport for NTP queries. More...
class  UdpTransportWin
 Windows UDP transport for NTP queries. More...
struct  NtpTimeServiceSingleton
struct  NtpTimeServiceTestAccess
class  FakeNtpRunner
 Fake runner for tests without network access. More...
struct  ZoneNameEntry
struct  TimerState
 Internal state shared between Timer and TimerScheduler. More...
struct  RunningTimerScope
struct  ScheduledTimer
 Data stored in the priority queue of scheduled timers. More...
struct  ScheduledComparator
 Comparator that orders timers by earliest fire time. More...
struct  DueTimer
 Helper structure that represents a timer ready to run. More...

Typedefs

using PlatformUdpTransport = UdpTransportWin
using TimerClock = std::chrono::steady_clock
using TimerCallback = std::function<void()>

Enumerations

enum  NtpProtoError {
  NTP_EPROTO_BASE = -10000 , NTP_E_BAD_MODE = NTP_EPROTO_BASE - 1 , NTP_E_BAD_VERSION = NTP_EPROTO_BASE - 2 , NTP_E_BAD_LI = NTP_EPROTO_BASE - 3 ,
  NTP_E_BAD_STRATUM = NTP_EPROTO_BASE - 4 , NTP_E_KOD = NTP_EPROTO_BASE - 5 , NTP_E_BAD_TS = NTP_EPROTO_BASE - 6
}
 Protocol-level error codes for NTP parsing. More...

Functions

TIME_SHIELD_CONSTEXPR DaySplit split_unix_day (ts_t p_ts) noexcept
 Split UNIX seconds into whole days and seconds-of-day.
TIME_SHIELD_CONSTEXPR int64_t fast_days_from_date_constexpr (int64_t p_year, int p_month, int p_day) noexcept
 Convert date to days since Unix epoch using a fast constexpr algorithm.
int64_t fast_days_from_date (int64_t p_year, int p_month, int p_day) noexcept
 Convert date to days since Unix epoch using a fast algorithm.
TIME_SHIELD_CONSTEXPR FastDate fast_date_from_days_constexpr (int64_t p_days) noexcept
 Convert days since Unix epoch to date using a fast constexpr algorithm.
FastDate fast_date_from_days (int64_t p_days) noexcept
 Convert days since Unix epoch to date using a fast algorithm.
TIME_SHIELD_CONSTEXPR int64_t fast_year_from_days_constexpr (int64_t p_days) noexcept
 Convert days since Unix epoch to year using a fast constexpr algorithm.
int64_t fast_year_from_days (int64_t p_days) noexcept
 Convert days since Unix epoch to year using a fast algorithm.
template<class T>
TIME_SHIELD_CONSTEXPR T floor_div (T a, T b) noexcept
 Floor division for positive divisor.
template<class T>
TIME_SHIELD_CONSTEXPR T floor_mod (T a, T b) noexcept
 Floor-mod for positive modulus (returns r in [0..b)).
TIME_SHIELD_CONSTEXPR uint64_t mul_hi_u64_constexpr (uint64_t p_a, uint64_t p_b) noexcept
 Return the high 64 bits of a 64x64-bit multiplication (constexpr variant).
uint64_t mul_hi_u64 (uint64_t p_a, uint64_t p_b) noexcept
 Return the high 64 bits of a 64x64-bit multiplication.
uint64_t mul_shift_u64 (uint64_t p_x, uint64_t p_c) noexcept
 Alias for mul_hi_u64 used for shift-by-64 operations.
TIME_SHIELD_CONSTEXPR uint64_t mul_shift_u64_constexpr (uint64_t p_x, uint64_t p_c) noexcept
 Alias for mul_hi_u64_constexpr used for shift-by-64 operations.
jd_t gregorian_dmy_to_jd_unchecked (double day, int64_t month, int64_t year) noexcept
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
static uint8_t ntp_li (uint8_t li_vn_mode) noexcept
 Extract leap indicator from LI/VN/Mode field.
static uint8_t ntp_vn (uint8_t li_vn_mode) noexcept
 Extract version number from LI/VN/Mode field.
static uint8_t ntp_mode (uint8_t li_vn_mode) noexcept
 Extract mode from LI/VN/Mode field.
static uint64_t ntp_frac_to_us (uint32_t frac_net) noexcept
 Convert NTP fractional seconds to microseconds.
static bool ntp_ts_to_unix_us (uint32_t sec_net, uint32_t frac_net, uint64_t &out_us) noexcept
 Convert NTP timestamp parts to Unix microseconds.
static void fill_client_packet (NtpPacket &pkt, uint64_t now_us)
 Fill an NTP client request packet using local time.
static bool parse_server_packet (const NtpPacket &pkt, uint64_t arrival_us, int64_t &offset_us, int64_t &delay_us, int &stratum, int &out_error_code) noexcept
 Parse server response and compute offset and delay.
TIME_SHIELD_CONSTEXPR bool oadate_can_cast_to_i64 (oadate_t value) noexcept
TIME_SHIELD_CONSTEXPR oadate_t oadate_abs (oadate_t value) noexcept
TIME_SHIELD_CONSTEXPR oadate_t oadate_trunc_toward_zero (oadate_t value) noexcept
TIME_SHIELD_CONSTEXPR oadate_t oadate_floor_value (oadate_t value) noexcept
TIME_SHIELD_CONSTEXPR bool oadate_has_fraction (oadate_t value) noexcept
TIME_SHIELD_CONSTEXPR oadate_t linear_days_to_oadate (oadate_t linear_days) noexcept
TIME_SHIELD_CONSTEXPR oadate_t oadate_to_linear_days (oadate_t oa) noexcept
std::string trim_copy_ascii (const std::string &s)
 Trim ASCII whitespace from both ends.
std::string_view trim_view_ascii (std::string_view v)
 Trim ASCII whitespace from both ends (string_view).
void normalise_month_token_lower (const std::string &month, std::string &output)
 Normalize month token to lower-case ASCII using current locale facet.
void normalise_month_token_lower (std::string_view month, std::string &output)
 Normalize month token to lower-case ASCII using current locale facet (string_view).
bool try_parse_month_index (const std::string &month, int &value)
 Try parse month name token into month index (1..12).
bool try_parse_month_index (std::string_view month, int &value)
 Try parse month name token into month index (1..12), string_view overload.
int parse_month_index (const std::string &month)
 Parse month name token into month index (1..12).
int parse_month_index (std::string_view month)
 Parse month name token into month index (1..12), string_view overload.
const std::array< ZoneNameEntry, 25 > & time_zone_name_entries () noexcept
 Return supported strict named-zone entries.
bool try_parse_time_zone_name_token (const char *data, std::size_t length, TimeZone &zone) noexcept
 Parse strict named-zone token without trimming.
TIME_SHIELD_CONSTEXPR bool is_ascii_space (char c) noexcept
 Check whether character is ASCII whitespace.
TIME_SHIELD_CONSTEXPR bool is_ascii_digit (char c) noexcept
 Check whether character is ASCII digit.
TIME_SHIELD_CONSTEXPR void skip_spaces (const char *&p, const char *end) noexcept
 Skip ASCII whitespace.
TIME_SHIELD_CONSTEXPR bool parse_2digits (const char *&p, const char *end, int &out) noexcept
 Parse exactly 2 digits into int.
TIME_SHIELD_CONSTEXPR bool parse_4digits_year (const char *&p, const char *end, year_t &out) noexcept
 Parse exactly 4 digits into year_t (via int).
TIME_SHIELD_CONSTEXPR bool parse_fraction_to_ms (const char *&p, const char *end, int &ms_out) noexcept
 Parse fractional seconds (1..9 digits) and convert to milliseconds.
ts_t cet_to_gmt_impl (ts_t cet)
ts_t gmt_to_cet_impl (ts_t gmt)
ts_t european_local_to_gmt (ts_t local, int standard_offset_hours)
ts_t gmt_to_european_local (ts_t gmt, int standard_offset_hours)
bool is_us_eastern_dst_local (const DateTimeStruct &dt)
bool fixed_zone_offset (TimeZone zone, tz_t &utc_offset)
ts_ms_t zone_to_gmt_ms_by_seconds (ts_ms_t local_ms, TimeZone zone)
ts_ms_t gmt_to_zone_ms_by_seconds (ts_ms_t gmt_ms, TimeZone zone)
TimerState *& current_timer_state ()

Typedef Documentation

◆ PlatformUdpTransport

◆ TimerCallback

using time_shield::detail::TimerCallback = std::function<void()>

Definition at line 41 of file TimerScheduler.hpp.

◆ TimerClock

using time_shield::detail::TimerClock = std::chrono::steady_clock

Definition at line 40 of file TimerScheduler.hpp.

Function Documentation

◆ cet_to_gmt_impl()

ts_t time_shield::detail::cet_to_gmt_impl ( ts_t cet)
inline

Definition at line 25 of file time_zone_conversions.hpp.

◆ current_timer_state()

TimerState *& time_shield::detail::current_timer_state ( )
inline

Definition at line 57 of file TimerScheduler.hpp.

◆ day_fraction_from_hms()

double time_shield::detail::day_fraction_from_hms ( int hour,
int minute,
int second,
int millisecond )
inlinenoexcept

Definition at line 57 of file julian_conversions.hpp.

◆ european_local_to_gmt()

ts_t time_shield::detail::european_local_to_gmt ( ts_t local,
int standard_offset_hours )
inline

Definition at line 134 of file time_zone_conversions.hpp.

◆ fast_date_from_days()

FastDate time_shield::detail::fast_date_from_days ( int64_t p_days)
inlinenoexcept

Convert days since Unix epoch to date using a fast algorithm.

Note
Inspired by the algorithm described in: https://www.benjoffe.com/fast-date-64 This implementation is written from scratch (no code copied).

Definition at line 156 of file fast_date.hpp.

◆ fast_date_from_days_constexpr()

TIME_SHIELD_CONSTEXPR FastDate time_shield::detail::fast_date_from_days_constexpr ( int64_t p_days)
inlinenoexcept

Convert days since Unix epoch to date using a fast constexpr algorithm.

Note
Inspired by the algorithm described in: https://www.benjoffe.com/fast-date-64 This implementation is written from scratch (no code copied).

Definition at line 118 of file fast_date.hpp.

◆ fast_days_from_date()

int64_t time_shield::detail::fast_days_from_date ( int64_t p_year,
int p_month,
int p_day )
inlinenoexcept

Convert date to days since Unix epoch using a fast algorithm.

Note
Inspired by the algorithm described in: https://www.benjoffe.com/fast-date-64 This implementation is written from scratch (no code copied).

Definition at line 90 of file fast_date.hpp.

◆ fast_days_from_date_constexpr()

TIME_SHIELD_CONSTEXPR int64_t time_shield::detail::fast_days_from_date_constexpr ( int64_t p_year,
int p_month,
int p_day )
inlinenoexcept

Convert date to days since Unix epoch using a fast constexpr algorithm.

Note
Inspired by the algorithm described in: https://www.benjoffe.com/fast-date-64 This implementation is written from scratch (no code copied).

Definition at line 59 of file fast_date.hpp.

◆ fast_year_from_days()

int64_t time_shield::detail::fast_year_from_days ( int64_t p_days)
inlinenoexcept

Convert days since Unix epoch to year using a fast algorithm.

Note
Inspired by the algorithm described in: https://www.benjoffe.com/fast-date-64 This implementation is written from scratch (no code copied).

Definition at line 220 of file fast_date.hpp.

◆ fast_year_from_days_constexpr()

TIME_SHIELD_CONSTEXPR int64_t time_shield::detail::fast_year_from_days_constexpr ( int64_t p_days)
inlinenoexcept

Convert days since Unix epoch to year using a fast constexpr algorithm.

Note
Inspired by the algorithm described in: https://www.benjoffe.com/fast-date-64 This implementation is written from scratch (no code copied).

Definition at line 194 of file fast_date.hpp.

◆ fill_client_packet()

void time_shield::detail::fill_client_packet ( NtpPacket & pkt,
uint64_t now_us )
inlinestatic

Fill an NTP client request packet using local time.

Definition at line 83 of file ntp_packet.hpp.

◆ fixed_zone_offset()

bool time_shield::detail::fixed_zone_offset ( TimeZone zone,
tz_t & utc_offset )
inline

Definition at line 192 of file time_zone_conversions.hpp.

◆ floor_div()

template<class T>
TIME_SHIELD_CONSTEXPR T time_shield::detail::floor_div ( T a,
T b )
inlinenoexcept

Floor division for positive divisor.

Definition at line 14 of file floor_math.hpp.

◆ floor_mod()

template<class T>
TIME_SHIELD_CONSTEXPR T time_shield::detail::floor_mod ( T a,
T b )
inlinenoexcept

Floor-mod for positive modulus (returns r in [0..b)).

Definition at line 20 of file floor_math.hpp.

◆ gmt_to_cet_impl()

ts_t time_shield::detail::gmt_to_cet_impl ( ts_t gmt)
inline

Definition at line 98 of file time_zone_conversions.hpp.

◆ gmt_to_european_local()

ts_t time_shield::detail::gmt_to_european_local ( ts_t gmt,
int standard_offset_hours )
inline

Definition at line 138 of file time_zone_conversions.hpp.

◆ gmt_to_zone_ms_by_seconds()

ts_ms_t time_shield::detail::gmt_to_zone_ms_by_seconds ( ts_ms_t gmt_ms,
TimeZone zone )
inline

Definition at line 262 of file time_zone_conversions.hpp.

◆ gregorian_dmy_to_jd_unchecked()

jd_t time_shield::detail::gregorian_dmy_to_jd_unchecked ( double day,
int64_t month,
int64_t year )
inlinenoexcept

Definition at line 30 of file julian_conversions.hpp.

◆ gregorian_dmy_to_jdn_unchecked()

jdn_t time_shield::detail::gregorian_dmy_to_jdn_unchecked ( int64_t day,
int64_t month,
int64_t year )
inlinenoexcept

Definition at line 43 of file julian_conversions.hpp.

◆ is_ascii_digit()

TIME_SHIELD_CONSTEXPR bool time_shield::detail::is_ascii_digit ( char c)
inlinenoexcept

Check whether character is ASCII digit.

Definition at line 278 of file time_parser.hpp.

◆ is_ascii_space()

TIME_SHIELD_CONSTEXPR bool time_shield::detail::is_ascii_space ( char c)
inlinenoexcept

Check whether character is ASCII whitespace.

Definition at line 273 of file time_parser.hpp.

◆ is_us_eastern_dst_local()

bool time_shield::detail::is_us_eastern_dst_local ( const DateTimeStruct & dt)
inline

Definition at line 142 of file time_zone_conversions.hpp.

◆ linear_days_to_oadate()

TIME_SHIELD_CONSTEXPR oadate_t time_shield::detail::linear_days_to_oadate ( oadate_t linear_days)
inlinenoexcept

Definition at line 67 of file ole_automation_conversions.hpp.

◆ mul_hi_u64()

uint64_t time_shield::detail::mul_hi_u64 ( uint64_t p_a,
uint64_t p_b )
inlinenoexcept

Return the high 64 bits of a 64x64-bit multiplication.

Definition at line 35 of file mul_hi.hpp.

◆ mul_hi_u64_constexpr()

TIME_SHIELD_CONSTEXPR uint64_t time_shield::detail::mul_hi_u64_constexpr ( uint64_t p_a,
uint64_t p_b )
inlinenoexcept

Return the high 64 bits of a 64x64-bit multiplication (constexpr variant).

Definition at line 19 of file mul_hi.hpp.

◆ mul_shift_u64()

uint64_t time_shield::detail::mul_shift_u64 ( uint64_t p_x,
uint64_t p_c )
inlinenoexcept

Alias for mul_hi_u64 used for shift-by-64 operations.

Definition at line 47 of file mul_hi.hpp.

◆ mul_shift_u64_constexpr()

TIME_SHIELD_CONSTEXPR uint64_t time_shield::detail::mul_shift_u64_constexpr ( uint64_t p_x,
uint64_t p_c )
inlinenoexcept

Alias for mul_hi_u64_constexpr used for shift-by-64 operations.

Definition at line 52 of file mul_hi.hpp.

◆ normalise_month_token_lower() [1/2]

void time_shield::detail::normalise_month_token_lower ( const std::string & month,
std::string & output )
inline

Normalize month token to lower-case ASCII using current locale facet.

Parameters
monthInput token.
outputOutput lower-case token (overwritten).

Definition at line 99 of file time_parser.hpp.

◆ normalise_month_token_lower() [2/2]

void time_shield::detail::normalise_month_token_lower ( std::string_view month,
std::string & output )
inline

Normalize month token to lower-case ASCII using current locale facet (string_view).

Parameters
monthInput token view.
outputOutput lower-case token (overwritten).

Definition at line 112 of file time_parser.hpp.

◆ ntp_frac_to_us()

uint64_t time_shield::detail::ntp_frac_to_us ( uint32_t frac_net)
inlinestaticnoexcept

Convert NTP fractional seconds to microseconds.

Definition at line 68 of file ntp_packet.hpp.

◆ ntp_li()

uint8_t time_shield::detail::ntp_li ( uint8_t li_vn_mode)
inlinestaticnoexcept

Extract leap indicator from LI/VN/Mode field.

Definition at line 53 of file ntp_packet.hpp.

◆ ntp_mode()

uint8_t time_shield::detail::ntp_mode ( uint8_t li_vn_mode)
inlinestaticnoexcept

Extract mode from LI/VN/Mode field.

Definition at line 63 of file ntp_packet.hpp.

◆ ntp_ts_to_unix_us()

bool time_shield::detail::ntp_ts_to_unix_us ( uint32_t sec_net,
uint32_t frac_net,
uint64_t & out_us )
inlinestaticnoexcept

Convert NTP timestamp parts to Unix microseconds.

Definition at line 74 of file ntp_packet.hpp.

◆ ntp_vn()

uint8_t time_shield::detail::ntp_vn ( uint8_t li_vn_mode)
inlinestaticnoexcept

Extract version number from LI/VN/Mode field.

Definition at line 58 of file ntp_packet.hpp.

◆ oadate_abs()

TIME_SHIELD_CONSTEXPR oadate_t time_shield::detail::oadate_abs ( oadate_t value)
inlinenoexcept

Definition at line 38 of file ole_automation_conversions.hpp.

◆ oadate_can_cast_to_i64()

TIME_SHIELD_CONSTEXPR bool time_shield::detail::oadate_can_cast_to_i64 ( oadate_t value)
inlinenoexcept

Definition at line 33 of file ole_automation_conversions.hpp.

◆ oadate_floor_value()

TIME_SHIELD_CONSTEXPR oadate_t time_shield::detail::oadate_floor_value ( oadate_t value)
inlinenoexcept

Definition at line 49 of file ole_automation_conversions.hpp.

◆ oadate_has_fraction()

TIME_SHIELD_CONSTEXPR bool time_shield::detail::oadate_has_fraction ( oadate_t value)
inlinenoexcept

Definition at line 60 of file ole_automation_conversions.hpp.

◆ oadate_to_linear_days()

TIME_SHIELD_CONSTEXPR oadate_t time_shield::detail::oadate_to_linear_days ( oadate_t oa)
inlinenoexcept

Definition at line 76 of file ole_automation_conversions.hpp.

◆ oadate_trunc_toward_zero()

TIME_SHIELD_CONSTEXPR oadate_t time_shield::detail::oadate_trunc_toward_zero ( oadate_t value)
inlinenoexcept

Definition at line 42 of file ole_automation_conversions.hpp.

◆ parse_2digits()

TIME_SHIELD_CONSTEXPR bool time_shield::detail::parse_2digits ( const char *& p,
const char * end,
int & out )
inlinenoexcept

Parse exactly 2 digits into int.

Returns
true on success.

Definition at line 291 of file time_parser.hpp.

◆ parse_4digits_year()

TIME_SHIELD_CONSTEXPR bool time_shield::detail::parse_4digits_year ( const char *& p,
const char * end,
year_t & out )
inlinenoexcept

Parse exactly 4 digits into year_t (via int).

Returns
true on success.

Definition at line 307 of file time_parser.hpp.

◆ parse_fraction_to_ms()

TIME_SHIELD_CONSTEXPR bool time_shield::detail::parse_fraction_to_ms ( const char *& p,
const char * end,
int & ms_out )
inlinenoexcept

Parse fractional seconds (1..9 digits) and convert to milliseconds.

Uses first 3 digits, scales if fewer.

Returns
true on success.

Definition at line 324 of file time_parser.hpp.

◆ parse_month_index() [1/2]

int time_shield::detail::parse_month_index ( const std::string & month)
inline

Parse month name token into month index (1..12).

Parameters
monthMonth token.
Returns
Month index [1..12].
Exceptions
std::invalid_argumentif token is invalid.

Definition at line 189 of file time_parser.hpp.

◆ parse_month_index() [2/2]

int time_shield::detail::parse_month_index ( std::string_view month)
inline

Parse month name token into month index (1..12), string_view overload.

Parameters
monthMonth token view.
Returns
Month index [1..12].
Exceptions
std::invalid_argumentif token is invalid.

Definition at line 202 of file time_parser.hpp.

◆ parse_server_packet()

bool time_shield::detail::parse_server_packet ( const NtpPacket & pkt,
uint64_t arrival_us,
int64_t & offset_us,
int64_t & delay_us,
int & stratum,
int & out_error_code )
inlinestaticnoexcept

Parse server response and compute offset and delay.

Definition at line 95 of file ntp_packet.hpp.

◆ skip_spaces()

TIME_SHIELD_CONSTEXPR void time_shield::detail::skip_spaces ( const char *& p,
const char * end )
inlinenoexcept

Skip ASCII whitespace.

Definition at line 283 of file time_parser.hpp.

◆ split_unix_day()

TIME_SHIELD_CONSTEXPR DaySplit time_shield::detail::split_unix_day ( ts_t p_ts)
inlinenoexcept

Split UNIX seconds into whole days and seconds-of-day.

Definition at line 39 of file fast_date.hpp.

◆ time_zone_name_entries()

const std::array< ZoneNameEntry, 25 > & time_shield::detail::time_zone_name_entries ( )
inlinenoexcept

Return supported strict named-zone entries.

Definition at line 217 of file time_parser.hpp.

◆ trim_copy_ascii()

std::string time_shield::detail::trim_copy_ascii ( const std::string & s)
inline

Trim ASCII whitespace from both ends.

Definition at line 77 of file time_parser.hpp.

◆ trim_view_ascii()

std::string_view time_shield::detail::trim_view_ascii ( std::string_view v)
inline

Trim ASCII whitespace from both ends (string_view).

Definition at line 87 of file time_parser.hpp.

◆ try_parse_month_index() [1/2]

bool time_shield::detail::try_parse_month_index ( const std::string & month,
int & value )
inline

Try parse month name token into month index (1..12).

Parameters
monthMonth token (e.g. "Jan", "January", case-insensitive).
valueOutput month index in range [1..12].
Returns
True if token matches a supported month name, false otherwise.

Definition at line 127 of file time_parser.hpp.

◆ try_parse_month_index() [2/2]

bool time_shield::detail::try_parse_month_index ( std::string_view month,
int & value )
inline

Try parse month name token into month index (1..12), string_view overload.

Parameters
monthMonth token view (e.g. "Jan", "January", case-insensitive).
valueOutput month index in range [1..12].
Returns
True if token matches a supported month name, false otherwise.

Definition at line 158 of file time_parser.hpp.

◆ try_parse_time_zone_name_token()

bool time_shield::detail::try_parse_time_zone_name_token ( const char * data,
std::size_t length,
TimeZone & zone )
inlinenoexcept

Parse strict named-zone token without trimming.

Definition at line 249 of file time_parser.hpp.

◆ zone_to_gmt_ms_by_seconds()

ts_ms_t time_shield::detail::zone_to_gmt_ms_by_seconds ( ts_ms_t local_ms,
TimeZone zone )
inline

Definition at line 249 of file time_zone_conversions.hpp.