|
Time Shield Library 2.0.0
C++ library for working with time
|
Represents a moment in time with optional fixed UTC offset. More...
#include <DateTime.hpp>
Public Member Functions | |
| DateTime () noexcept | |
| Default constructor sets epoch with zero offset. | |
| DateTimeStruct | to_date_time_struct_local () const |
| Convert to date-time structure using stored offset. | |
| DateTimeStruct | to_date_time_struct_utc () const |
| Convert to UTC date-time structure. | |
| std::string | to_iso8601 () const |
| Format to ISO8601 string with stored offset. | |
| std::string | to_iso8601_utc () const |
| Format to ISO8601 string in UTC. | |
| std::string | format (const std::string &fmt) const |
| Format using custom pattern. | |
| std::string | format (std::string_view fmt) const |
| Format using custom string_view pattern. | |
| std::string | format (const char *fmt) const |
| Format using C-string pattern. | |
| std::string | to_mql5_date_time () const |
| Format to MQL5 date-time string. | |
| ts_ms_t | unix_ms () const noexcept |
| Access UTC milliseconds. | |
| ts_t | unix_s () const noexcept |
| Access UTC seconds. | |
| tz_t | utc_offset () const noexcept |
| Access stored UTC offset. | |
| TimeZoneStruct | time_zone () const |
| Get timezone structure from offset. | |
| year_t | year () const |
| Local year component. | |
| int | month () const |
| Local month component. | |
| int | day () const |
| Local day component. | |
| int | hour () const |
| Local hour component. | |
| int | minute () const |
| Local minute component. | |
| int | second () const |
| Local second component. | |
| int | millisecond () const |
| Local millisecond component. | |
| DateStruct | date () const |
| Local date components. | |
| TimeStruct | time_of_day () const |
| Local time-of-day components. | |
| DateStruct | utc_date () const |
| UTC date components. | |
| TimeStruct | utc_time_of_day () const |
| UTC time-of-day components. | |
| year_t | utc_year () const |
| UTC year component. | |
| int | utc_month () const |
| UTC month component. | |
| int | utc_day () const |
| UTC day component. | |
| int | utc_hour () const |
| UTC hour component. | |
| int | utc_minute () const |
| UTC minute component. | |
| int | utc_second () const |
| UTC second component. | |
| int | utc_millisecond () const |
| UTC millisecond component. | |
| Weekday | weekday () const |
| Local weekday. | |
| int | iso_weekday () const |
| Local ISO weekday number (1..7). | |
| IsoWeekDateStruct | iso_week_date () const |
| Local ISO week date. | |
| Weekday | utc_weekday () const |
| UTC weekday. | |
| int | utc_iso_weekday () const |
| UTC ISO weekday number (1..7). | |
| IsoWeekDateStruct | utc_iso_week_date () const |
| UTC ISO week date. | |
| bool | is_workday () const noexcept |
| Check if local date is a workday. | |
| bool | is_weekend () const noexcept |
| Check if local date is a weekend. | |
| bool | utc_is_workday () const noexcept |
| Check if UTC date is a workday. | |
| bool | utc_is_weekend () const noexcept |
| Check if UTC date is a weekend. | |
| bool | operator== (const DateTime &other) const noexcept |
| Compare equality by UTC instant. | |
| bool | operator!= (const DateTime &other) const noexcept |
| Compare inequality by UTC instant. | |
| bool | operator< (const DateTime &other) const noexcept |
| Less-than comparison by UTC instant. | |
| bool | operator<= (const DateTime &other) const noexcept |
| Less-than-or-equal comparison by UTC instant. | |
| bool | operator> (const DateTime &other) const noexcept |
| Greater-than comparison by UTC instant. | |
| bool | operator>= (const DateTime &other) const noexcept |
| Greater-than-or-equal comparison by UTC instant. | |
| bool | same_local (const DateTime &other) const noexcept |
| Check if local representations match including offset. | |
| DateTime | add_ms (int64_t delta_ms) const noexcept |
| Add milliseconds to UTC instant. | |
| DateTime | add_seconds (int64_t seconds) const noexcept |
| Add seconds to UTC instant. | |
| DateTime | add_minutes (int64_t minutes) const noexcept |
| Add minutes to UTC instant. | |
| DateTime | add_hours (int64_t hours) const noexcept |
| Add hours to UTC instant. | |
| DateTime | add_days (int64_t days) const noexcept |
| Add days to UTC instant. | |
| int64_t | diff_ms (const DateTime &other) const noexcept |
| Difference in milliseconds to another DateTime. | |
| double | diff_seconds (const DateTime &other) const noexcept |
| Difference in seconds to another DateTime. | |
| DateTime | with_offset (tz_t new_offset) const noexcept |
| Return copy with new offset preserving instant. | |
| DateTime | to_utc () const noexcept |
| Return copy with zero offset. | |
| DateTime | start_of_day () const |
| Start of local day. | |
| DateTime | end_of_day () const |
| End of local day. | |
| DateTime | start_of_month () const |
| Start of local month. | |
| DateTime | end_of_month () const |
| End of local month. | |
| DateTime | start_of_year () const |
| Start of local year. | |
| DateTime | end_of_year () const |
| End of local year. | |
| DateTime | start_of_utc_day () const |
| Start of UTC day. | |
| DateTime | end_of_utc_day () const |
| End of UTC day. | |
| DateTime | start_of_utc_month () const |
| Start of UTC month. | |
| DateTime | end_of_utc_month () const |
| End of UTC month. | |
| DateTime | start_of_utc_year () const |
| Start of UTC year. | |
| DateTime | end_of_utc_year () const |
| End of UTC year. | |
| DateTime () | |
| Default constructor initializes epoch with zero offset. | |
| string | to_iso8601 () const |
| Format to ISO8601 string with stored offset. | |
| long | unix_ms () const |
| Access UTC milliseconds. | |
| int | utc_offset () const |
| Access stored UTC offset. | |
| DateTime | with_offset (const int new_offset) const |
| Return copy with new offset preserving instant. | |
| DateTime | to_utc () const |
| Return copy with zero offset. | |
Static Public Member Functions | |
| static DateTime | from_unix_ms (ts_ms_t utc_ms, tz_t offset=0) noexcept |
| Create instance from UTC milliseconds. | |
| static DateTime | from_unix_s (ts_t utc_s, tz_t offset=0) noexcept |
| Create instance from UTC seconds. | |
| static DateTime | now_utc (tz_t offset=0) noexcept |
| Construct instance for current UTC time. | |
| static DateTime | from_components (year_t year, int month, int day, int hour=0, int min=0, int sec=0, int ms=0, tz_t offset=0) |
| Build from calendar components interpreted in provided offset. | |
| static bool | try_from_components (year_t year, int month, int day, int hour, int min, int sec, int ms, tz_t offset, DateTime &out) noexcept |
| Try to build from calendar components interpreted in provided offset. | |
| static DateTime | from_date_time_struct (const DateTimeStruct &local_dt, tz_t offset=0) |
| Build from DateTimeStruct interpreted in provided offset. | |
| static bool | try_from_date_time_struct (const DateTimeStruct &local_dt, tz_t offset, DateTime &out) noexcept |
| Try to build from DateTimeStruct interpreted in provided offset. | |
| static DateTime | from_iso_week_date (const IsoWeekDateStruct &iso, int hour=0, int min=0, int sec=0, int ms=0, tz_t offset=0) |
| Build instance from ISO week date interpreted in provided offset. | |
| static bool | try_parse_iso8601 (const std::string &str, DateTime &out) noexcept |
| Try to parse ISO8601 string to DateTime. | |
| static bool | try_parse_iso8601 (std::string_view str, DateTime &out) noexcept |
| Try to parse ISO8601 string_view to DateTime. | |
| static bool | try_parse_iso8601 (const char *str, DateTime &out) noexcept |
| Try to parse ISO8601 C-string to DateTime. | |
| static DateTime | parse_iso8601 (const std::string &str) |
| Parse ISO8601 string, throws on failure. | |
| static DateTime | parse_iso8601 (std::string_view str) |
| Parse ISO8601 string_view, throws on failure. | |
| static DateTime | parse_iso8601 (const char *str) |
| Parse ISO8601 C-string, throws on failure. | |
| static bool | try_parse_iso_week_date (const std::string &str, IsoWeekDateStruct &iso) noexcept |
| Try to parse ISO week-date string. | |
| static bool | try_parse_iso_week_date (std::string_view str, IsoWeekDateStruct &iso) noexcept |
| Try to parse ISO week-date string_view. | |
| static bool | try_parse_iso_week_date (const char *str, IsoWeekDateStruct &iso) noexcept |
| Try to parse ISO week-date C-string. | |
| static DateTime | from_unix_ms (const long utc_ms, const int offset=0) |
| Create instance from UTC milliseconds. | |
| static DateTime | now_utc (const int offset=0) |
| Construct instance for current UTC time. | |
| static bool | try_from_components (const long year, const int month, const int day, const int hour, const int min, const int sec, const int ms, const int offset, DateTime &out) |
| Try to build from calendar components interpreted in provided offset. | |
| static bool | try_from_date_time_struct (const DateTimeStruct &local_dt, const int offset, DateTime &out) |
| Try to build from DateTimeStruct interpreted in provided offset. | |
| static bool | try_parse_iso8601 (const string str, DateTime &out) |
| Try to parse ISO8601 string to DateTime. | |
Private Member Functions | |
| DateTime (ts_ms_t utc_ms, tz_t offset) noexcept | |
| ts_ms_t | local_ms () const noexcept |
| DateTime (const long utc_ms, const int offset) | |
| long | local_ms () const |
Static Private Member Functions | |
| static bool | try_parse_iso8601_buffer (const char *data, std::size_t size, DateTime &out) noexcept |
| static DateTime | parse_iso8601_buffer (const char *data, std::size_t size) |
| static TIME_SHIELD_CONSTEXPR ts_ms_t | offset_to_ms (tz_t offset) noexcept |
| static long | offset_to_ms (const int offset) |
Private Attributes | |
| ts_ms_t | m_utc_ms |
| tz_t | m_offset |
| long | m_utc_ms |
| int | m_offset |
Represents a moment in time with optional fixed UTC offset.
Represents a UTC timestamp with an optional fixed offset.
Equality and ordering compare the UTC instant only and ignore the stored offset.
Definition at line 27 of file DateTime.mqh.
|
inlinenoexcept |
Default constructor sets epoch with zero offset.
Definition at line 29 of file DateTime.hpp.
Definition at line 685 of file DateTime.hpp.
|
inline |
Default constructor initializes epoch with zero offset.
Definition at line 30 of file DateTime.mqh.
|
inlineprivate |
Definition at line 140 of file DateTime.mqh.
|
inlinenoexcept |
Add days to UTC instant.
Definition at line 506 of file DateTime.hpp.
|
inlinenoexcept |
Add hours to UTC instant.
Definition at line 501 of file DateTime.hpp.
|
inlinenoexcept |
Add minutes to UTC instant.
Definition at line 496 of file DateTime.hpp.
|
inlinenoexcept |
Add milliseconds to UTC instant.
Definition at line 486 of file DateTime.hpp.
|
inlinenoexcept |
Add seconds to UTC instant.
Definition at line 491 of file DateTime.hpp.
|
inline |
Local date components.
Definition at line 327 of file DateTime.hpp.
|
inline |
Local day component.
Definition at line 302 of file DateTime.hpp.
|
inlinenoexcept |
Difference in milliseconds to another DateTime.
Definition at line 511 of file DateTime.hpp.
|
inlinenoexcept |
Difference in seconds to another DateTime.
Definition at line 516 of file DateTime.hpp.
|
inline |
End of local day.
Definition at line 538 of file DateTime.hpp.
|
inline |
End of local month.
Definition at line 559 of file DateTime.hpp.
|
inline |
End of UTC day.
Definition at line 601 of file DateTime.hpp.
|
inline |
End of UTC month.
Definition at line 622 of file DateTime.hpp.
|
inline |
End of UTC year.
Definition at line 644 of file DateTime.hpp.
|
inline |
End of local year.
Definition at line 581 of file DateTime.hpp.
|
inline |
Format using C-string pattern.
Definition at line 259 of file DateTime.hpp.
|
inline |
Format using custom pattern.
Definition at line 247 of file DateTime.hpp.
|
inline |
Format using custom string_view pattern.
Definition at line 253 of file DateTime.hpp.
|
inlinestatic |
Build from calendar components interpreted in provided offset.
Definition at line 57 of file DateTime.hpp.
|
inlinestatic |
Build from DateTimeStruct interpreted in provided offset.
Definition at line 104 of file DateTime.hpp.
|
inlinestatic |
Build instance from ISO week date interpreted in provided offset.
Definition at line 141 of file DateTime.hpp.
|
inlinestatic |
Create instance from UTC milliseconds.
| utc_ms | Timestamp in milliseconds since the Unix epoch (UTC). |
| offset | Fixed UTC offset in seconds. |
Definition at line 36 of file DateTime.mqh.
|
inlinestaticnoexcept |
Create instance from UTC milliseconds.
| utc_ms | Timestamp in milliseconds since Unix epoch (UTC). |
| offset | Fixed UTC offset in seconds. |
Definition at line 37 of file DateTime.hpp.
|
inlinestaticnoexcept |
Create instance from UTC seconds.
| utc_s | Timestamp in seconds since Unix epoch (UTC). |
| offset | Fixed UTC offset in seconds. |
Definition at line 45 of file DateTime.hpp.
|
inline |
Local hour component.
Definition at line 307 of file DateTime.hpp.
|
inlinenoexcept |
Check if local date is a weekend.
Definition at line 435 of file DateTime.hpp.
|
inlinenoexcept |
Check if local date is a workday.
Definition at line 430 of file DateTime.hpp.
|
inline |
Local ISO week date.
Definition at line 406 of file DateTime.hpp.
|
inline |
Local ISO weekday number (1..7).
Definition at line 400 of file DateTime.hpp.
|
inlineprivate |
Definition at line 144 of file DateTime.mqh.
|
inlineprivatenoexcept |
Definition at line 693 of file DateTime.hpp.
|
inline |
Local millisecond component.
Definition at line 322 of file DateTime.hpp.
|
inline |
Local minute component.
Definition at line 312 of file DateTime.hpp.
|
inline |
Local month component.
Definition at line 297 of file DateTime.hpp.
|
inlinestatic |
Construct instance for current UTC time.
| offset | Fixed UTC offset in seconds. |
Definition at line 44 of file DateTime.mqh.
Construct instance for current UTC time.
| offset | Fixed UTC offset in seconds. |
Definition at line 52 of file DateTime.hpp.
|
inlinestaticprivate |
Definition at line 142 of file DateTime.mqh.
|
inlinestaticprivatenoexcept |
Definition at line 689 of file DateTime.hpp.
|
inlinenoexcept |
Compare inequality by UTC instant.
Definition at line 456 of file DateTime.hpp.
|
inlinenoexcept |
Less-than comparison by UTC instant.
Definition at line 461 of file DateTime.hpp.
|
inlinenoexcept |
Less-than-or-equal comparison by UTC instant.
Definition at line 466 of file DateTime.hpp.
|
inlinenoexcept |
Compare equality by UTC instant.
Definition at line 451 of file DateTime.hpp.
|
inlinenoexcept |
Greater-than comparison by UTC instant.
Definition at line 471 of file DateTime.hpp.
|
inlinenoexcept |
Greater-than-or-equal comparison by UTC instant.
Definition at line 476 of file DateTime.hpp.
|
inlinestatic |
Parse ISO8601 C-string, throws on failure.
| str | Null-terminated ISO8601 string. |
Definition at line 200 of file DateTime.hpp.
|
inlinestatic |
Parse ISO8601 string, throws on failure.
| str | Input ISO8601 string. |
Definition at line 184 of file DateTime.hpp.
|
inlinestatic |
Parse ISO8601 string_view, throws on failure.
| str | Input ISO8601 view. |
Definition at line 192 of file DateTime.hpp.
|
inlinestaticprivate |
Definition at line 677 of file DateTime.hpp.
|
inlinenoexcept |
Check if local representations match including offset.
Definition at line 481 of file DateTime.hpp.
|
inline |
Local second component.
Definition at line 317 of file DateTime.hpp.
|
inline |
Start of local day.
Definition at line 531 of file DateTime.hpp.
|
inline |
Start of local month.
Definition at line 552 of file DateTime.hpp.
|
inline |
Start of UTC day.
Definition at line 595 of file DateTime.hpp.
|
inline |
Start of UTC month.
Definition at line 616 of file DateTime.hpp.
|
inline |
Start of UTC year.
Definition at line 638 of file DateTime.hpp.
|
inline |
Start of local year.
Definition at line 574 of file DateTime.hpp.
|
inline |
Local time-of-day components.
Definition at line 333 of file DateTime.hpp.
|
inline |
Get timezone structure from offset.
Definition at line 287 of file DateTime.hpp.
|
inline |
Convert to date-time structure using stored offset.
Definition at line 131 of file DateTime.hpp.
|
inline |
Convert to UTC date-time structure.
Definition at line 136 of file DateTime.hpp.
|
inline |
Format to ISO8601 string with stored offset.
Definition at line 237 of file DateTime.hpp.
|
inline |
Format to ISO8601 string with stored offset.
Definition at line 122 of file DateTime.mqh.
|
inline |
Format to ISO8601 string in UTC.
Definition at line 242 of file DateTime.hpp.
|
inline |
Format to MQL5 date-time string.
Definition at line 267 of file DateTime.hpp.
|
inline |
Return copy with zero offset.
Definition at line 137 of file DateTime.mqh.
|
inlinenoexcept |
Return copy with zero offset.
Definition at line 526 of file DateTime.hpp.
|
inlinestatic |
Try to build from calendar components interpreted in provided offset.
| year | Year component. |
| month | Month component. |
| day | Day component. |
| hour | Hour component. |
| min | Minute component. |
| sec | Second component. |
| ms | Millisecond component. |
| offset | Fixed UTC offset in seconds. |
| out | Output DateTime on success. |
Definition at line 60 of file DateTime.mqh.
|
inlinestaticnoexcept |
Try to build from calendar components interpreted in provided offset.
| year | Year component. |
| month | Month component. |
| day | Day component. |
| hour | Hour component. |
| min | Minute component. |
| sec | Second component. |
| ms | Millisecond component. |
| offset | Fixed UTC offset in seconds. |
| out | Output DateTime on success. |
Definition at line 82 of file DateTime.hpp.
|
inlinestatic |
Try to build from DateTimeStruct interpreted in provided offset.
| local_dt | Local date-time structure. |
| offset | Fixed UTC offset in seconds. |
| out | Output DateTime on success. |
Definition at line 88 of file DateTime.mqh.
|
inlinestaticnoexcept |
Try to build from DateTimeStruct interpreted in provided offset.
| local_dt | Local date-time structure. |
| offset | Fixed UTC offset in seconds. |
| out | Output DateTime on success. |
Definition at line 115 of file DateTime.hpp.
|
inlinestaticnoexcept |
Try to parse ISO8601 C-string to DateTime.
| str | Null-terminated ISO8601 string. |
| out | Output DateTime when parsing succeeds. |
Definition at line 174 of file DateTime.hpp.
|
inlinestaticnoexcept |
Try to parse ISO8601 string to DateTime.
| str | Input ISO8601 string. |
| out | Output DateTime when parsing succeeds. |
Definition at line 156 of file DateTime.hpp.
|
inlinestatic |
Try to parse ISO8601 string to DateTime.
| str | Input ISO8601 string. |
| out | Output DateTime when parsing succeeds. |
Definition at line 109 of file DateTime.mqh.
|
inlinestaticnoexcept |
Try to parse ISO8601 string_view to DateTime.
| str | Input ISO8601 string_view. |
| out | Output DateTime when parsing succeeds. |
Definition at line 165 of file DateTime.hpp.
|
inlinestaticprivatenoexcept |
Definition at line 659 of file DateTime.hpp.
|
inlinestaticnoexcept |
Try to parse ISO week-date C-string.
Parser accepts canonical and compatible mixed separator variants, uppercase or lowercase W, and Monday default when weekday is omitted.
Definition at line 229 of file DateTime.hpp.
|
inlinestaticnoexcept |
Try to parse ISO week-date string.
| str | Input ISO week-date string. |
| iso | Output ISO week-date structure. |
Parser accepts canonical and compatible mixed separator variants, uppercase or lowercase W, and Monday default when weekday is omitted.
Definition at line 213 of file DateTime.hpp.
|
inlinestaticnoexcept |
Try to parse ISO week-date string_view.
Parser accepts canonical and compatible mixed separator variants, uppercase or lowercase W, and Monday default when weekday is omitted.
Definition at line 221 of file DateTime.hpp.
|
inline |
Access UTC milliseconds.
Definition at line 125 of file DateTime.mqh.
|
inlinenoexcept |
Access UTC milliseconds.
Definition at line 272 of file DateTime.hpp.
|
inlinenoexcept |
Access UTC seconds.
Definition at line 277 of file DateTime.hpp.
|
inline |
UTC date components.
Definition at line 343 of file DateTime.hpp.
|
inline |
UTC day component.
Definition at line 369 of file DateTime.hpp.
|
inline |
UTC hour component.
Definition at line 374 of file DateTime.hpp.
|
inlinenoexcept |
Check if UTC date is a weekend.
Definition at line 446 of file DateTime.hpp.
|
inlinenoexcept |
Check if UTC date is a workday.
Definition at line 440 of file DateTime.hpp.
|
inline |
UTC ISO week date.
Definition at line 424 of file DateTime.hpp.
|
inline |
UTC ISO weekday number (1..7).
Definition at line 418 of file DateTime.hpp.
|
inline |
UTC millisecond component.
Definition at line 389 of file DateTime.hpp.
|
inline |
UTC minute component.
Definition at line 379 of file DateTime.hpp.
|
inline |
UTC month component.
Definition at line 364 of file DateTime.hpp.
|
inline |
Access stored UTC offset.
Definition at line 128 of file DateTime.mqh.
|
inlinenoexcept |
Access stored UTC offset.
Definition at line 282 of file DateTime.hpp.
|
inline |
UTC second component.
Definition at line 384 of file DateTime.hpp.
|
inline |
UTC time-of-day components.
Definition at line 349 of file DateTime.hpp.
|
inline |
UTC weekday.
Definition at line 412 of file DateTime.hpp.
|
inline |
UTC year component.
Definition at line 359 of file DateTime.hpp.
|
inline |
Local weekday.
Definition at line 394 of file DateTime.hpp.
|
inline |
Return copy with new offset preserving instant.
Definition at line 131 of file DateTime.mqh.
Return copy with new offset preserving instant.
Definition at line 521 of file DateTime.hpp.
|
inline |
Local year component.
Definition at line 292 of file DateTime.hpp.
|
private |
Definition at line 698 of file DateTime.hpp.
|
private |
Definition at line 147 of file DateTime.mqh.
|
private |
Definition at line 697 of file DateTime.hpp.
|
private |
Definition at line 146 of file DateTime.mqh.