|
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. | |
| Weekday | weekday () const |
| Local weekday. | |
| int | iso_weekday () const |
| Local ISO weekday number (1..7). | |
| IsoWeekDateStruct | iso_week_date () const |
| Local 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 | 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 () | |
| 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 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 36 of file DateTime.hpp.
|
inlinenoexcept |
Default constructor sets epoch with zero offset.
Definition at line 39 of file DateTime.hpp.
Definition at line 560 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 448 of file DateTime.hpp.
|
inlinenoexcept |
Add hours to UTC instant.
Definition at line 443 of file DateTime.hpp.
|
inlinenoexcept |
Add minutes to UTC instant.
Definition at line 438 of file DateTime.hpp.
|
inlinenoexcept |
Add milliseconds to UTC instant.
Definition at line 428 of file DateTime.hpp.
|
inlinenoexcept |
Add seconds to UTC instant.
Definition at line 433 of file DateTime.hpp.
|
inline |
Local date components.
Definition at line 333 of file DateTime.hpp.
|
inline |
Local day component.
Definition at line 308 of file DateTime.hpp.
|
inlinenoexcept |
Difference in milliseconds to another DateTime.
Definition at line 453 of file DateTime.hpp.
|
inlinenoexcept |
Difference in seconds to another DateTime.
Definition at line 458 of file DateTime.hpp.
|
inline |
End of local day.
Definition at line 480 of file DateTime.hpp.
|
inline |
End of local month.
Definition at line 501 of file DateTime.hpp.
|
inline |
End of local year.
Definition at line 523 of file DateTime.hpp.
|
inline |
Format using C-string pattern.
Definition at line 265 of file DateTime.hpp.
|
inline |
Format using custom pattern.
Definition at line 253 of file DateTime.hpp.
|
inline |
Format using custom string_view pattern.
Definition at line 259 of file DateTime.hpp.
|
inlinestatic |
Build from calendar components interpreted in provided offset.
Definition at line 67 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 153 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 47 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 55 of file DateTime.hpp.
|
inline |
Local hour component.
Definition at line 313 of file DateTime.hpp.
|
inlinenoexcept |
Check if local date is a weekend.
Definition at line 388 of file DateTime.hpp.
|
inlinenoexcept |
Check if local date is a workday.
Definition at line 383 of file DateTime.hpp.
|
inline |
Local ISO week date.
Definition at line 377 of file DateTime.hpp.
|
inline |
Local ISO weekday number (1..7).
Definition at line 371 of file DateTime.hpp.
|
inlineprivate |
Definition at line 136 of file DateTime.mqh.
|
inlineprivatenoexcept |
Definition at line 568 of file DateTime.hpp.
|
inline |
Local millisecond component.
Definition at line 328 of file DateTime.hpp.
|
inline |
Local minute component.
Definition at line 318 of file DateTime.hpp.
|
inline |
Local month component.
Definition at line 303 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 62 of file DateTime.hpp.
|
inlinestaticprivate |
Definition at line 134 of file DateTime.mqh.
|
inlinestaticconstexprprivatenoexcept |
Definition at line 564 of file DateTime.hpp.
|
inlinenoexcept |
Compare inequality by UTC instant.
Definition at line 398 of file DateTime.hpp.
|
inlinenoexcept |
Less-than comparison by UTC instant.
Definition at line 403 of file DateTime.hpp.
|
inlinenoexcept |
Less-than-or-equal comparison by UTC instant.
Definition at line 408 of file DateTime.hpp.
|
inlinenoexcept |
Compare equality by UTC instant.
Definition at line 393 of file DateTime.hpp.
|
inlinenoexcept |
Greater-than comparison by UTC instant.
Definition at line 413 of file DateTime.hpp.
|
inlinenoexcept |
Greater-than-or-equal comparison by UTC instant.
Definition at line 418 of file DateTime.hpp.
|
inlinestatic |
Parse ISO8601 C-string, throws on failure.
| str | Null-terminated ISO8601 string. |
Definition at line 212 of file DateTime.hpp.
|
inlinestatic |
Parse ISO8601 string, throws on failure.
| str | Input ISO8601 string. |
Definition at line 196 of file DateTime.hpp.
|
inlinestatic |
Parse ISO8601 string_view, throws on failure.
| str | Input ISO8601 view. |
Definition at line 204 of file DateTime.hpp.
|
inlinestaticprivate |
Definition at line 552 of file DateTime.hpp.
|
inlinenoexcept |
Check if local representations match including offset.
Definition at line 423 of file DateTime.hpp.
|
inline |
Local second component.
Definition at line 323 of file DateTime.hpp.
|
inline |
Start of local day.
Definition at line 473 of file DateTime.hpp.
|
inline |
Start of local month.
Definition at line 494 of file DateTime.hpp.
|
inline |
Start of local year.
Definition at line 516 of file DateTime.hpp.
|
inline |
Local time-of-day components.
Definition at line 339 of file DateTime.hpp.
|
inline |
Get timezone structure from offset.
Definition at line 293 of file DateTime.hpp.
|
inline |
Convert to date-time structure using stored offset.
Definition at line 143 of file DateTime.hpp.
|
inline |
Convert to UTC date-time structure.
Definition at line 148 of file DateTime.hpp.
|
inline |
Format to ISO8601 string with stored offset.
Definition at line 243 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 248 of file DateTime.hpp.
|
inline |
Format to MQL5 date-time string.
Definition at line 273 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 468 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 92 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 186 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 168 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 177 of file DateTime.hpp.
|
inlinestaticprivatenoexcept |
Definition at line 537 of file DateTime.hpp.
|
inlinestaticnoexcept |
Try to parse ISO week-date C-string.
Definition at line 235 of file DateTime.hpp.
|
inlinestaticnoexcept |
Try to parse ISO week-date string.
| str | Input ISO week-date string. |
| iso | Output ISO week-date structure. |
Definition at line 223 of file DateTime.hpp.
|
inlinestaticnoexcept |
Try to parse ISO week-date string_view.
Definition at line 229 of file DateTime.hpp.
|
inline |
Access UTC milliseconds.
Definition at line 120 of file DateTime.mqh.
|
inlinenoexcept |
Access UTC milliseconds.
Definition at line 278 of file DateTime.hpp.
|
inlinenoexcept |
Access UTC seconds.
Definition at line 283 of file DateTime.hpp.
|
inline |
UTC date components.
Definition at line 349 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 288 of file DateTime.hpp.
|
inline |
UTC time-of-day components.
Definition at line 355 of file DateTime.hpp.
|
inline |
Local weekday.
Definition at line 365 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 463 of file DateTime.hpp.
|
inline |
Local year component.
Definition at line 298 of file DateTime.hpp.
|
private |
Definition at line 573 of file DateTime.hpp.
|
private |
Definition at line 139 of file DateTime.mqh.
|
private |
Definition at line 572 of file DateTime.hpp.
|
private |
Definition at line 138 of file DateTime.mqh.