|
Time Shield Library
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 37 of file DateTime.hpp.
|
inlinenoexcept |
Default constructor sets epoch with zero offset.
Definition at line 40 of file DateTime.hpp.
Definition at line 696 of file DateTime.hpp.
|
inline |
Default constructor initializes epoch with zero offset.
Definition at line 30 of file DateTime.mqh.
|
inlineprivate |
Definition at line 132 of file DateTime.mqh.
|
inlinenoexcept |
Add days to UTC instant.
Definition at line 517 of file DateTime.hpp.
|
inlinenoexcept |
Add hours to UTC instant.
Definition at line 512 of file DateTime.hpp.
|
inlinenoexcept |
Add minutes to UTC instant.
Definition at line 507 of file DateTime.hpp.
|
inlinenoexcept |
Add milliseconds to UTC instant.
Definition at line 497 of file DateTime.hpp.
|
inlinenoexcept |
Add seconds to UTC instant.
Definition at line 502 of file DateTime.hpp.
|
inline |
Local date components.
Definition at line 338 of file DateTime.hpp.
|
inline |
Local day component.
Definition at line 313 of file DateTime.hpp.
|
inlinenoexcept |
Difference in milliseconds to another DateTime.
Definition at line 522 of file DateTime.hpp.
|
inlinenoexcept |
Difference in seconds to another DateTime.
Definition at line 527 of file DateTime.hpp.
|
inline |
End of local day.
Definition at line 549 of file DateTime.hpp.
|
inline |
End of local month.
Definition at line 570 of file DateTime.hpp.
|
inline |
End of UTC day.
Definition at line 612 of file DateTime.hpp.
|
inline |
End of UTC month.
Definition at line 633 of file DateTime.hpp.
|
inline |
End of UTC year.
Definition at line 655 of file DateTime.hpp.
|
inline |
End of local year.
Definition at line 592 of file DateTime.hpp.
|
inline |
Format using C-string pattern.
Definition at line 270 of file DateTime.hpp.
|
inline |
Format using custom pattern.
Definition at line 258 of file DateTime.hpp.
|
inline |
Format using custom string_view pattern.
Definition at line 264 of file DateTime.hpp.
|
inlinestatic |
Build from calendar components interpreted in provided offset.
Definition at line 68 of file DateTime.hpp.
|
inlinestatic |
Build from DateTimeStruct interpreted in provided offset.
Definition at line 115 of file DateTime.hpp.
|
inlinestatic |
Build instance from ISO week date interpreted in provided offset.
Definition at line 152 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 48 of file DateTime.hpp.
Create instance from UTC seconds.
| utc_s | Timestamp in seconds since Unix epoch (UTC). |
| offset | Fixed UTC offset in seconds. |
Definition at line 56 of file DateTime.hpp.
|
inline |
Local hour component.
Definition at line 318 of file DateTime.hpp.
|
inlinenoexcept |
Check if local date is a weekend.
Definition at line 446 of file DateTime.hpp.
|
inlinenoexcept |
Check if local date is a workday.
Definition at line 441 of file DateTime.hpp.
|
inline |
Local ISO week date.
Definition at line 417 of file DateTime.hpp.
|
inline |
Local ISO weekday number (1..7).
Definition at line 411 of file DateTime.hpp.
|
inlineprivate |
Definition at line 136 of file DateTime.mqh.
|
inlineprivatenoexcept |
Definition at line 704 of file DateTime.hpp.
|
inline |
Local millisecond component.
Definition at line 333 of file DateTime.hpp.
|
inline |
Local minute component.
Definition at line 323 of file DateTime.hpp.
|
inline |
Local month component.
Definition at line 308 of file DateTime.hpp.
|
inlinestatic |
Construct instance for current UTC time.
| offset | Fixed UTC offset in seconds. |
Definition at line 43 of file DateTime.mqh.
Construct instance for current UTC time.
| offset | Fixed UTC offset in seconds. |
Definition at line 63 of file DateTime.hpp.
|
inlinestaticprivate |
Definition at line 134 of file DateTime.mqh.
|
inlinestaticprivatenoexcept |
Definition at line 700 of file DateTime.hpp.
|
inlinenoexcept |
Compare inequality by UTC instant.
Definition at line 467 of file DateTime.hpp.
|
inlinenoexcept |
Less-than comparison by UTC instant.
Definition at line 472 of file DateTime.hpp.
|
inlinenoexcept |
Less-than-or-equal comparison by UTC instant.
Definition at line 477 of file DateTime.hpp.
|
inlinenoexcept |
Compare equality by UTC instant.
Definition at line 462 of file DateTime.hpp.
|
inlinenoexcept |
Greater-than comparison by UTC instant.
Definition at line 482 of file DateTime.hpp.
|
inlinenoexcept |
Greater-than-or-equal comparison by UTC instant.
Definition at line 487 of file DateTime.hpp.
|
inlinestatic |
Parse ISO8601 C-string, throws on failure.
| str | Null-terminated ISO8601 string. |
Definition at line 211 of file DateTime.hpp.
|
inlinestatic |
Parse ISO8601 string, throws on failure.
| str | Input ISO8601 string. |
Definition at line 195 of file DateTime.hpp.
|
inlinestatic |
Parse ISO8601 string_view, throws on failure.
| str | Input ISO8601 view. |
Definition at line 203 of file DateTime.hpp.
|
inlinestaticprivate |
Definition at line 688 of file DateTime.hpp.
|
inlinenoexcept |
Check if local representations match including offset.
Definition at line 492 of file DateTime.hpp.
|
inline |
Local second component.
Definition at line 328 of file DateTime.hpp.
|
inline |
Start of local day.
Definition at line 542 of file DateTime.hpp.
|
inline |
Start of local month.
Definition at line 563 of file DateTime.hpp.
|
inline |
Start of UTC day.
Definition at line 606 of file DateTime.hpp.
|
inline |
Start of UTC month.
Definition at line 627 of file DateTime.hpp.
|
inline |
Start of UTC year.
Definition at line 649 of file DateTime.hpp.
|
inline |
Start of local year.
Definition at line 585 of file DateTime.hpp.
|
inline |
Local time-of-day components.
Definition at line 344 of file DateTime.hpp.
|
inline |
Get timezone structure from offset.
Definition at line 298 of file DateTime.hpp.
|
inline |
Convert to date-time structure using stored offset.
Definition at line 142 of file DateTime.hpp.
|
inline |
Convert to UTC date-time structure.
Definition at line 147 of file DateTime.hpp.
|
inline |
Format to ISO8601 string with stored offset.
Definition at line 248 of file DateTime.hpp.
|
inline |
Format to ISO8601 string with stored offset.
Definition at line 117 of file DateTime.mqh.
|
inline |
Format to ISO8601 string in UTC.
Definition at line 253 of file DateTime.hpp.
|
inline |
Format to MQL5 date-time string.
Definition at line 278 of file DateTime.hpp.
|
inline |
Return copy with zero offset.
Definition at line 129 of file DateTime.mqh.
|
inlinenoexcept |
Return copy with zero offset.
Definition at line 537 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 58 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 93 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 85 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 126 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 185 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 167 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 105 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 176 of file DateTime.hpp.
|
inlinestaticprivatenoexcept |
Definition at line 670 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 240 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 224 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 232 of file DateTime.hpp.
|
inline |
Access UTC milliseconds.
Definition at line 120 of file DateTime.mqh.
|
inlinenoexcept |
Access UTC milliseconds.
Definition at line 283 of file DateTime.hpp.
|
inlinenoexcept |
Access UTC seconds.
Definition at line 288 of file DateTime.hpp.
|
inline |
UTC date components.
Definition at line 354 of file DateTime.hpp.
|
inline |
UTC day component.
Definition at line 380 of file DateTime.hpp.
|
inline |
UTC hour component.
Definition at line 385 of file DateTime.hpp.
|
inlinenoexcept |
Check if UTC date is a weekend.
Definition at line 457 of file DateTime.hpp.
|
inlinenoexcept |
Check if UTC date is a workday.
Definition at line 451 of file DateTime.hpp.
|
inline |
UTC ISO week date.
Definition at line 435 of file DateTime.hpp.
|
inline |
UTC ISO weekday number (1..7).
Definition at line 429 of file DateTime.hpp.
|
inline |
UTC millisecond component.
Definition at line 400 of file DateTime.hpp.
|
inline |
UTC minute component.
Definition at line 390 of file DateTime.hpp.
|
inline |
UTC month component.
Definition at line 375 of file DateTime.hpp.
|
inline |
Access stored UTC offset.
Definition at line 123 of file DateTime.mqh.
|
inlinenoexcept |
Access stored UTC offset.
Definition at line 293 of file DateTime.hpp.
|
inline |
UTC second component.
Definition at line 395 of file DateTime.hpp.
|
inline |
UTC time-of-day components.
Definition at line 360 of file DateTime.hpp.
|
inline |
UTC weekday.
Definition at line 423 of file DateTime.hpp.
|
inline |
UTC year component.
Definition at line 370 of file DateTime.hpp.
|
inline |
Local weekday.
Definition at line 405 of file DateTime.hpp.
|
inline |
Return copy with new offset preserving instant.
Definition at line 126 of file DateTime.mqh.
Return copy with new offset preserving instant.
Definition at line 532 of file DateTime.hpp.
|
inline |
Local year component.
Definition at line 303 of file DateTime.hpp.
|
private |
Definition at line 709 of file DateTime.hpp.
|
private |
Definition at line 139 of file DateTime.mqh.
|
private |
Definition at line 708 of file DateTime.hpp.
|
private |
Definition at line 138 of file DateTime.mqh.