|
Time Shield Library 2.0.0
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.
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 30 of file ZonedClock.hpp.
|
inlinenoexcept |
Construct UTC fixed-offset clock without NTP.
Definition at line 33 of file ZonedClock.hpp.
|
inlineexplicitnoexcept |
Construct clock for a named zone.
| zone | Supported named zone. |
| use_ntp | Use NTP-backed UTC time when true. |
Definition at line 42 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 54 of file ZonedClock.hpp.
|
inlineprivatenoexcept |
Definition at line 344 of file ZonedClock.hpp.
|
inlineprivatenoexcept |
Definition at line 348 of file ZonedClock.hpp.
|
inline |
Format current local time using the custom formatter grammar.
| fmt | Formatting pattern. |
Definition at line 319 of file ZonedClock.hpp.
Return a snapshot for a specific UTC instant in milliseconds.
| utc_ms | UTC timestamp in milliseconds. |
Definition at line 275 of file ZonedClock.hpp.
Return a snapshot for a specific UTC instant in seconds.
| utc_s | UTC timestamp in seconds. |
Definition at line 282 of file ZonedClock.hpp.
|
inlinenoexcept |
Return true when the instance stores a named zone.
Definition at line 136 of file ZonedClock.hpp.
|
inlinestaticprivatenoexcept |
Definition at line 336 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current local timestamp in milliseconds.
Definition at line 256 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current local timestamp in seconds.
Definition at line 250 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current local timestamp in microseconds.
Definition at line 262 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current time snapshot with resolved fixed offset.
Definition at line 268 of file ZonedClock.hpp.
|
inlinenoexcept |
Return true when the global NTP service is active for this clock.
Definition at line 151 of file ZonedClock.hpp.
Return effective UTC offset in seconds for a specific UTC instant.
| utc_ms | UTC timestamp in milliseconds. |
Definition at line 167 of file ZonedClock.hpp.
|
inlinenoexcept |
Return effective UTC offset in seconds for the current UTC instant.
Definition at line 160 of file ZonedClock.hpp.
|
inline |
Return effective numeric UTC offset as +HH:MM or -HH:MM.
Definition at line 302 of file ZonedClock.hpp.
|
inlinestaticprivate |
Definition at line 340 of file ZonedClock.hpp.
|
inlinenoexcept |
Resolve a local timestamp in this clock's zone.
| local_ms | Local civil timestamp in milliseconds. |
Definition at line 192 of file ZonedClock.hpp.
|
inlinenoexcept |
Set preferred UTC source.
| use_ntp | Use NTP-backed UTC time when true. |
Definition at line 131 of file ZonedClock.hpp.
|
inlinenoexcept |
Set the stored named zone.
| zone | Supported named zone. UNKNOWN resets the instance to fixed UTC offset +00:00. |
Definition at line 79 of file ZonedClock.hpp.
|
inline |
Return current local time formatted as ISO8601 with offset.
Definition at line 307 of file ZonedClock.hpp.
|
inline |
Return current UTC time formatted as ISO8601 with Z.
Definition at line 312 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 219 of file ZonedClock.hpp.
|
inlinestaticprivate |
Definition at line 324 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 68 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 176 of file ZonedClock.hpp.
|
inlinenoexcept |
Set the stored fixed UTC offset.
| utc_offset | Fixed UTC offset in seconds. |
Definition at line 95 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 109 of file ZonedClock.hpp.
|
inlinenoexcept |
Return the preferred UTC source flag.
Definition at line 146 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current UTC time in milliseconds.
Definition at line 240 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current UTC time in seconds.
Definition at line 235 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current UTC time in microseconds.
Definition at line 245 of file ZonedClock.hpp.
|
inlinenoexcept |
Return stored named zone or UNKNOWN for fixed-offset mode.
Definition at line 141 of file ZonedClock.hpp.
|
inline |
Return human-readable zone label.
UTC+/-HH:MM for fixed offsets. Definition at line 294 of file ZonedClock.hpp.
|
inline |
Return short name of the stored named zone.
Definition at line 288 of file ZonedClock.hpp.
|
private |
Definition at line 363 of file ZonedClock.hpp.
|
private |
Definition at line 362 of file ZonedClock.hpp.
|
private |
Definition at line 364 of file ZonedClock.hpp.
|
private |
Definition at line 361 of file ZonedClock.hpp.