|
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. | |
| 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 294 of file ZonedClock.hpp.
|
inlineprivatenoexcept |
Definition at line 298 of file ZonedClock.hpp.
|
inline |
Format current local time using the custom formatter grammar.
| fmt | Formatting pattern. |
Definition at line 269 of file ZonedClock.hpp.
Return a snapshot for a specific UTC instant in milliseconds.
| utc_ms | UTC timestamp in milliseconds. |
Definition at line 225 of file ZonedClock.hpp.
Return a snapshot for a specific UTC instant in seconds.
| utc_s | UTC timestamp in seconds. |
Definition at line 232 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 286 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current local timestamp in milliseconds.
Definition at line 206 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current local timestamp in seconds.
Definition at line 200 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current local timestamp in microseconds.
Definition at line 212 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current time snapshot with resolved fixed offset.
Definition at line 218 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 252 of file ZonedClock.hpp.
|
inlinestaticprivate |
Definition at line 290 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 257 of file ZonedClock.hpp.
|
inline |
Return current UTC time formatted as ISO8601 with Z.
Definition at line 262 of file ZonedClock.hpp.
|
inlinestaticprivate |
Definition at line 274 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 |
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 190 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current UTC time in seconds.
Definition at line 185 of file ZonedClock.hpp.
|
inlinenoexcept |
Return current UTC time in microseconds.
Definition at line 195 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 244 of file ZonedClock.hpp.
|
inline |
Return short name of the stored named zone.
Definition at line 238 of file ZonedClock.hpp.
|
private |
Definition at line 313 of file ZonedClock.hpp.
|
private |
Definition at line 312 of file ZonedClock.hpp.
|
private |
Definition at line 314 of file ZonedClock.hpp.
|
private |
Definition at line 311 of file ZonedClock.hpp.