7#ifndef __TIME_SHIELD_DATE_TIME_MQH__
8#define __TIME_SHIELD_DATE_TIME_MQH__
14#property copyright "Copyright 2025, NewYaroslav"
15#property link "https://github.com/NewYaroslav/time-shield-cpp"
Represents a moment in time with optional fixed UTC offset.
int day() const
Local day component.
DateTime()
Default constructor initializes epoch with zero offset.
static long offset_to_ms(const int offset)
int utc_offset() const
Access stored UTC 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.
string to_iso8601() const
Format to ISO8601 string with stored offset.
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.
DateTime with_offset(tz_t new_offset) const noexcept
Return copy with new offset preserving instant.
int hour() const
Local hour component.
static DateTime parse_iso8601(const std::string &str)
Parse ISO8601 string, throws on failure.
static DateTime now_utc(const int offset=0)
Construct instance for current UTC time.
DateTime() noexcept
Default constructor sets epoch with zero offset.
int month() const
Local month component.
long unix_ms() const
Access UTC milliseconds.
static DateTime from_unix_ms(const long utc_ms, const int offset=0)
Create instance from UTC milliseconds.
year_t year() const
Local year component.
ts_ms_t local_ms() const noexcept
DateTime with_offset(const int new_offset) const
Return copy with new offset preserving instant.
static constexpr ts_ms_t offset_to_ms(tz_t offset) noexcept
static bool try_parse_iso8601(const string str, DateTime &out)
Try to parse ISO8601 string to DateTime.
DateTime to_utc() const
Return copy with zero offset.
DateTime(const long utc_ms, const int offset)
constexpr int64_t MS_PER_SEC
Milliseconds per second.
TIME_SHIELD_CONSTEXPR tz_t time_zone_struct_to_offset(const TimeZoneStruct &tz) noexcept
Convert a TimeZoneStruct to a numeric UTC offset (seconds).
TimeZoneStruct to_time_zone_struct(tz_t offset)
Converts an integer to a TimeZoneStruct.
TIME_SHIELD_CONSTEXPR bool is_valid_time_zone_offset(const T &time_zone) noexcept
Check if the time zone is valid.
const DateTimeStruct create_date_time_struct(int64_t year, int mon=1, int day=1, int hour=0, int min=0, int sec=0, int ms=0)
Creates a DateTimeStruct instance.
TIME_SHIELD_CONSTEXPR ts_t dt_to_timestamp_ms(const T &date_time)
Converts a date-time structure to a timestamp in milliseconds.
TimeZoneStruct create_time_zone_struct(int hour, int min, bool is_positive=true)
Creates a TimeZoneStruct instance.
TIME_SHIELD_CONSTEXPR ts_ms_t to_timestamp_ms(T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0, T2 ms=0)
Converts a date-time structure to a timestamp in milliseconds.
ts_ms_t ts_ms() noexcept
Get the current UTC timestamp in milliseconds.
TIME_SHIELD_CONSTEXPR bool is_valid_date_time(T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0, T3 ms=0) noexcept
Checks the correctness of a date and time.
Main namespace for the Time Shield library.
Structure to represent date and time.
Structure to represent time zone information.
Header with helper functions for converting between different time representations in MQL5.
Header with functions for parsing ISO8601 strings and converting them to timestamps.
Header for time zone structure and related functions (MQL5).
Header with validation functions for dates, times, and timestamps.