|
Time Shield Library
C++ library for working with time
|
Stores a target local-time context backed by a named zone or fixed UTC offset. More...
#include <ZonedClock.hpp>
Public Member Functions | |
| ZonedClock () noexcept | |
| Construct UTC fixed-offset clock without NTP. | |
| ZonedClock (TimeZone zone, bool use_ntp=false) noexcept | |
| Construct clock for a named zone. | |
| ZonedClock (tz_t utc_offset, bool use_ntp=false) | |
| Construct clock for a fixed UTC offset. | |
| void | set_zone (TimeZone zone) noexcept |
| Set the stored named zone. | |
| bool | try_set_offset (tz_t utc_offset) noexcept |
| Set the stored fixed UTC offset. | |
| bool | try_set_zone (const std::string &zone_spec) noexcept |
| Parse and set a named zone or numeric offset from string. | |
| void | set_use_ntp (bool use_ntp) noexcept |
| Set preferred UTC source. | |
| bool | has_named_zone () const noexcept |
| Return true when the instance stores a named zone. | |
| TimeZone | zone () const noexcept |
| Return stored named zone or UNKNOWN for fixed-offset mode. | |
| bool | use_ntp () const noexcept |
| Return the preferred UTC source flag. | |
| bool | ntp_active () const noexcept |
| Return true when the global NTP service is active for this clock. | |
| tz_t | offset_now () const noexcept |
| Return effective UTC offset in seconds for the current UTC instant. | |
| tz_t | offset_at_utc_ms (ts_ms_t utc_ms) const noexcept |
| Return effective UTC offset in seconds for a specific UTC instant. | |
| bool | try_offset_at_utc_ms (ts_ms_t utc_ms, tz_t &out) const noexcept |
| Try to resolve effective UTC offset for a UTC instant. | |
| LocalTimeResolution | resolve_local_time_ms (ts_ms_t local_ms) const noexcept |
| Resolve a local timestamp in this clock's zone. | |
| ts_ms_t | to_utc_ms (ts_ms_t local_ms, AmbiguousTimePolicy ambiguous_policy=AmbiguousTimePolicy::error, NonexistentTimePolicy nonexistent_policy=NonexistentTimePolicy::error) const noexcept |
| Convert a local timestamp in this clock's zone to UTC. | |
| ts_t | utc_time_sec () const noexcept |
| Return current UTC time in seconds. | |
| ts_ms_t | utc_time_ms () const noexcept |
| Return current UTC time in milliseconds. | |
| ts_us_t | utc_time_us () const noexcept |
| Return current UTC time in microseconds. | |
| ts_t | local_time_sec () const noexcept |
| Return current local timestamp in seconds. | |
| ts_ms_t | local_time_ms () const noexcept |
| Return current local timestamp in milliseconds. | |
| ts_us_t | local_time_us () const noexcept |
| Return current local timestamp in microseconds. | |
| DateTime | now () const noexcept |
| Return current time snapshot with resolved fixed offset. | |
| DateTime | from_utc_ms (ts_ms_t utc_ms) const noexcept |
| Return a snapshot for a specific UTC instant in milliseconds. | |
| DateTime | from_utc_s (ts_t utc_s) const noexcept |
| Return a snapshot for a specific UTC instant in seconds. | |
| std::string | zone_name () const |
| Return short name of the stored named zone. | |
| std::string | zone_full_name () const |
| Return human-readable zone label. | |
| std::string | offset_string () const |
| Return effective numeric UTC offset as +HH:MM or -HH:MM. | |
| std::string | to_iso8601 () const |
| Return current local time formatted as ISO8601 with offset. | |
| std::string | to_iso8601_utc () const |
| Return current UTC time formatted as ISO8601 with Z. | |
| std::string | format (const std::string &fmt) const |
| Format current local time using the custom formatter grammar. | |
Static Public Member Functions | |
| static bool | try_from_offset (tz_t utc_offset, ZonedClock &out) noexcept |
| Try to build fixed-offset clock without throwing. | |
Private Member Functions | |
| ts_ms_t | current_utc_ms () const noexcept |
| ts_us_t | current_utc_us () const noexcept |
Static Private Member Functions | |
| static std::string | trim_ascii (const std::string &value) |
| static bool | is_ascii_space (char ch) noexcept |
| static std::string | offset_string_for_offset (tz_t utc_offset) |
Private Attributes | |
| TimeZone | m_zone |
| tz_t | m_offset |
| bool | m_is_named_zone |
| bool | m_use_ntp |
Stores a target local-time context backed by a named zone or fixed UTC offset.
The class resolves the effective offset on demand. Named zones are recalculated for the requested UTC instant, while numeric offsets remain fixed. Current UTC time can come from the local realtime clock or from the global NTP service.
Definition at line 33 of file ZonedClock.hpp.
|
inlinenoexcept |
Construct UTC fixed-offset clock without NTP.
Definition at line 36 of file ZonedClock.hpp.
|
inlineexplicitnoexcept |
Construct clock for a named zone.
Definition at line 45 of file ZonedClock.hpp.
|
inlineexplicit |
Construct clock for a fixed UTC offset.
| utc_offset | Fixed UTC offset in seconds. |
| use_ntp | Use NTP-backed UTC time when true. |
| std::invalid_argument | if utc_offset is outside the supported range. |
Definition at line 57 of file ZonedClock.hpp.
|
inlineprivatenoexcept |
Definition at line 347 of file ZonedClock.hpp.
|
inlineprivatenoexcept |
Definition at line 351 of file ZonedClock.hpp.
|
inline |
Format current local time using the custom formatter grammar.
| fmt | Formatting pattern. |
Definition at line 322 of file ZonedClock.hpp.
Return a snapshot for a specific UTC instant in milliseconds.
| utc_ms | UTC timestamp in milliseconds. |
Definition at line 278 of file ZonedClock.hpp.
Return a snapshot for a specific UTC instant in seconds.
| utc_s | UTC timestamp in seconds. |
Definition at line 285 of file ZonedClock.hpp.
|
inlinenoexcept |
Return true when the instance stores a named zone.
Definition at line 139 of file ZonedClock.hpp.
|
inlinestaticprivatenoexcept |
Definition at line 339 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current local timestamp in milliseconds.
Definition at line 259 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current local timestamp in seconds.
Definition at line 253 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current local timestamp in microseconds.
Definition at line 265 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current time snapshot with resolved fixed offset.
Definition at line 271 of file ZonedClock.hpp.
|
inlinenoexcept |
Return true when the global NTP service is active for this clock.
Definition at line 154 of file ZonedClock.hpp.
Return effective UTC offset in seconds for a specific UTC instant.
| utc_ms | UTC timestamp in milliseconds. |
Definition at line 170 of file ZonedClock.hpp.
|
inlinenoexcept |
Return effective UTC offset in seconds for the current UTC instant.
Definition at line 163 of file ZonedClock.hpp.
|
inline |
Return effective numeric UTC offset as +HH:MM or -HH:MM.
Definition at line 305 of file ZonedClock.hpp.
|
inlinestaticprivate |
Definition at line 343 of file ZonedClock.hpp.
|
inlinenoexcept |
Resolve a local timestamp in this clock's zone.
| local_ms | Local civil timestamp in milliseconds. |
Definition at line 195 of file ZonedClock.hpp.
|
inlinenoexcept |
Set preferred UTC source.
| use_ntp | Use NTP-backed UTC time when true. |
Definition at line 134 of file ZonedClock.hpp.
|
inlinenoexcept |
Set the stored named zone.
Definition at line 82 of file ZonedClock.hpp.
|
inline |
Return current local time formatted as ISO8601 with offset.
Definition at line 310 of file ZonedClock.hpp.
|
inline |
Return current UTC time formatted as ISO8601 with Z.
Definition at line 315 of file ZonedClock.hpp.
|
inlinenoexcept |
Convert a local timestamp in this clock's zone to UTC.
| local_ms | Local civil timestamp in milliseconds. |
| ambiguous_policy | Policy for DST-fold local times. |
| nonexistent_policy | Policy for DST-gap local times. |
Definition at line 222 of file ZonedClock.hpp.
|
inlinestaticprivate |
Definition at line 327 of file ZonedClock.hpp.
|
inlinestaticnoexcept |
Try to build fixed-offset clock without throwing.
| utc_offset | Fixed UTC offset in seconds. |
| out | Output clock on success. |
Definition at line 71 of file ZonedClock.hpp.
|
inlinenoexcept |
Try to resolve effective UTC offset for a UTC instant.
| utc_ms | UTC timestamp in milliseconds. |
| out | Receives offset in seconds on success. |
Definition at line 179 of file ZonedClock.hpp.
|
inlinenoexcept |
Set the stored fixed UTC offset.
| utc_offset | Fixed UTC offset in seconds. |
Definition at line 98 of file ZonedClock.hpp.
|
inlinenoexcept |
Parse and set a named zone or numeric offset from string.
| zone_spec | Input string with ASCII trimming applied before parsing. |
Definition at line 112 of file ZonedClock.hpp.
|
inlinenoexcept |
Return the preferred UTC source flag.
Definition at line 149 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current UTC time in milliseconds.
Definition at line 243 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current UTC time in seconds.
Definition at line 238 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current UTC time in microseconds.
Definition at line 248 of file ZonedClock.hpp.
|
inlinenoexcept |
Return stored named zone or UNKNOWN for fixed-offset mode.
Definition at line 144 of file ZonedClock.hpp.
|
inline |
Return human-readable zone label.
Definition at line 297 of file ZonedClock.hpp.
|
inline |
Return short name of the stored named zone.
Definition at line 291 of file ZonedClock.hpp.
|
private |
Definition at line 366 of file ZonedClock.hpp.
|
private |
Definition at line 365 of file ZonedClock.hpp.
|
private |
Definition at line 367 of file ZonedClock.hpp.
|
private |
Definition at line 364 of file ZonedClock.hpp.