7#ifndef __TIME_SHIELD_TIME_CONVERSIONS_MQH__
8#define __TIME_SHIELD_TIME_CONVERSIONS_MQH__
19#property copyright "Copyright 2025, NewYaroslav"
20#property link "https://github.com/NewYaroslav/time-shield-cpp"
39 double frac =
ts - MathFloor(
ts);
47 double frac =
ts - MathFloor(
ts);
55 double frac =
ts - MathFloor(
ts);
187 if(hour == 0 || hour > 12)
return 12;
203 const long BIAS_292277022000 = 9223371890843040000;
204 const long BIAS_2000 = 946684800;
207 long secs = -((
ts - BIAS_2000) - BIAS_292277022000);
211 y -= n_400_years * 400;
215 y -= n_100_years * 100;
225 y = secs == 0 ? y : y - 1;
276 TimeToStruct((datetime)
ts, tmp);
297 TimeToStruct((datetime)
ts, dt);
323 tmp.year = (int)dt.
year;
329 return (
long)StructToTime(tmp);
336 return (
long)StructToTime(dt);
363 return (
long)StructToTime(dt);
368 long to_ts(
long year,
int mon,
int day,
int hour=0,
int min=0,
int sec=0) {
387 long to_ts_ms(
long year,
int mon,
int day,
int hour=0,
int min=0,
int sec=0,
int ms=0) {
393 long ts_ms(
long year,
int mon,
int day,
int hour=0,
int min=0,
int sec=0,
int ms=0) {
572 long r = 7000 + day + y + (y / 4) - (y / 100) + (y / 400) + (31 * m) /
MONTHS_PER_YEAR;
640 MqlDateTime dt; TimeToStruct((datetime)
ts, dt);
641 dt.mon = 1; dt.day = 1; dt.hour = 0; dt.min = 0; dt.sec = 0;
642 return (
long)StructToTime(dt);
649 MqlDateTime dt; TimeToStruct((datetime)
ts, dt);
650 dt.year++; dt.mon = 1; dt.day = 1; dt.hour = 0; dt.min = 0; dt.sec = 0;
651 return (
long)StructToTime(dt) - 1;
684 long year_remainder = year_diff % 4;
687 switch(year_remainder) {
688 case 0:
return year_start_ts;
690 case 2:
return year_start_ts + SEC_PER_YEAR_X2;
691 default:
return year_start_ts + SEC_PER_YEAR_V2;
693 return year_start_ts + SEC_PER_YEAR_V2;
743 const int JAN_AND_FEB_DAY_LEAP_YEAR = 60;
744 static const int TABLE_MONTH_OF_YEAR[] = {
746 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
747 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
748 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
749 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
750 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
751 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
752 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
753 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
754 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
755 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
756 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
757 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
761 return (
Month)TABLE_MONTH_OF_YEAR[dy - 1];
762 return (
Month)TABLE_MONTH_OF_YEAR[dy];
769 const int JAN_AND_FEB_DAY_LEAP_YEAR = 60;
770 static const int TABLE_DAY_OF_YEAR[] = {
772 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
773 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,
774 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
775 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
776 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
777 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
778 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
779 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
780 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
781 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
785 if(dy == JAN_AND_FEB_DAY_LEAP_YEAR)
return TABLE_DAY_OF_YEAR[dy - 1] + 1;
786 if(dy > JAN_AND_FEB_DAY_LEAP_YEAR)
return TABLE_DAY_OF_YEAR[dy - 1];
788 return TABLE_DAY_OF_YEAR[dy];
797 static const int num_days[13] = {0,31,30,31,30,31,30,31,31,30,31,30,31};
802 return num_days[month];
813 static const int num_days[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
818 return num_days[month];
1054 return ts - (
ts % p);
1062 return ts - (
ts % p) + p - 1;
Header file with time-related constants.
Header for date and time structure and related functions (MQL5).
Header file with enumerations for weekdays, months, and other time-related categories.
constexpr int64_t MIN_PER_HOUR
Minutes per hour.
constexpr int64_t DAYS_PER_WEEK
Days per week.
constexpr int64_t SEC_PER_YEAR
Seconds per year (365 days)
const int64_t MONTHS_PER_YEAR
Months per year.
constexpr int64_t DAYS_PER_YEAR
Days per year.
constexpr int64_t HOURS_PER_DAY
Hours per day.
constexpr int64_t SEC_PER_100_YEARS
Seconds per 100 years.
constexpr int64_t MAX_YEAR
Maximum representable year.
constexpr int64_t MS_PER_MIN
Milliseconds per minute.
constexpr int64_t SEC_PER_LEAP_YEAR
Seconds per leap year (366 days)
constexpr int64_t MIN_PER_DAY
Minutes per day.
constexpr int64_t DAYS_PER_LEAP_YEAR
Days per leap year.
constexpr int64_t SEC_PER_HOUR
Seconds per hour.
constexpr int64_t UNIX_EPOCH
Start year of UNIX time.
constexpr int64_t MS_PER_DAY
Milliseconds per day.
constexpr int64_t MS_PER_SEC
Milliseconds per second.
constexpr int64_t SEC_PER_400_YEARS
Seconds per 400 years.
constexpr int64_t SEC_PER_DAY
Seconds per day.
constexpr int64_t SEC_PER_MIN
Seconds per minute.
constexpr int64_t NS_PER_SEC
Nanoseconds per second.
constexpr int64_t MS_PER_HOUR
Milliseconds per hour.
constexpr int64_t US_PER_SEC
Microseconds per second.
constexpr int64_t SEC_PER_4_YEARS
Seconds per 4 years.
TIME_SHIELD_CONSTEXPR const T year_ms(ts_ms_t ts_ms=ts_ms())
Alias for get_year_ms function.
TIME_SHIELD_CONSTEXPR const T day_of_month(ts_t ts)
Get the day of the month.
constexpr const T unix_year(ts_t ts) noexcept
Alias for get_unix_year function.
constexpr const T unixday_ms(ts_ms_t t_ms=ts_ms()) noexcept
Alias for get_unix_day_ms function.
TIME_SHIELD_CONSTEXPR const ts_t to_ts(T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0)
Alias for to_timestamp function.
constexpr const T uday_to_ts(uday_t unix_day) noexcept
Alias for unix_day_to_timestamp function.
constexpr const ts_ms_t day_end_ms(ts_ms_t ts_ms=ts_ms()) noexcept
Alias for end_of_day_ms function.
TIME_SHIELD_CONSTEXPR const T to_year_ms(ts_ms_t ts_ms=ts_ms())
Alias for get_year_ms function.
constexpr const T start_of_next_day_from_unix_day_ms(uday_t unix_day) noexcept
Converts a UNIX day to a timestamp representing the start of the next day in milliseconds.
TIME_SHIELD_CONSTEXPR const ts_t ts(T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0)
Alias for to_timestamp function.
constexpr const ts_t hour_begin(ts_t ts=ts()) noexcept
Alias for start_of_hour function.
constexpr const ts_ms_t next_day_ms(ts_ms_t ts_ms, T days=1) noexcept
Calculate the timestamp for a specified number of days in the future (milliseconds).
constexpr const T unix_day(ts_t ts=ts()) noexcept
Alias for get_unix_day function.
const T to_time_zone(tz_t offset)
Converts an integer to a time zone structure.
constexpr const T1 day_of_week(T2 year, T3 month, T3 day)
Alias for day_of_week_date function.
constexpr const ts_t next_day(ts_t ts, T days=1) noexcept
Calculate the timestamp for a specified number of days in the future.
constexpr const ts_t day_start(ts_t ts=ts()) noexcept
Alias for start_of_day function.
constexpr const T next_day_unixday_ms(uday_t unix_day) noexcept
Alias for start_of_next_day_from_unix_day_ms function.
constexpr const T next_day_unixday(uday_t unix_day) noexcept
Alias for start_of_next_day_from_unix_day function.
constexpr const T end_of_day_from_unix_day_ms(uday_t unix_day) noexcept
Converts a UNIX day to a timestamp representing the end of the day in milliseconds.
constexpr const T unixday_to_ts_ms(uday_t unix_day) noexcept
Alias for unix_day_to_timestamp_ms function.
constexpr const ts_t hour_begin_sec(ts_ms_t ts_ms=ts_ms()) noexcept
Alias for start_of_hour_sec function.
TIME_SHIELD_CONSTEXPR const ts_t last_sunday_of_month(ts_t ts=ts())
Get the timestamp of the last Sunday of the current month.
constexpr T1 min_to_sec(T2 ts) noexcept
Converts a timestamp from minutes to seconds.
constexpr const T get_unix_day_ms(ts_ms_t t_ms=ts_ms()) noexcept
Get UNIX day from milliseconds timestamp.
constexpr const ts_t end_of_day_sec(ts_ms_t ts_ms=ts_ms()) noexcept
Get the timestamp at the end of the day in seconds.
constexpr const ts_t start_of_week(ts_t ts=ts())
Get the timestamp of the beginning of the week.
TIME_SHIELD_CONSTEXPR const ts_t year_begin_date(T year)
Alias for start_of_year_date function.
constexpr const ts_t start_of_day_sec(ts_ms_t ts_ms=ts_ms()) noexcept
Get the start of the day timestamp in seconds.
constexpr const ts_t start_of_saturday(ts_t ts=ts())
Get the timestamp of the start of Saturday.
long eod_from_unix_day(long uday)
Alias for end_of_day_from_unix_day.
constexpr const T day_of_week_ms(const ts_ms_t &ts_ms)
Alias for get_weekday_from_ts_ms function.
constexpr const T next_day_unix_day_ms(uday_t unix_day) noexcept
Alias for start_of_next_day_from_unix_day_ms function.
TIME_SHIELD_CONSTEXPR const ts_t start_of_year_date(T year)
Get the timestamp of the start of the year.
constexpr const ts_ms_t hour_begin_ms(ts_ms_t ts_ms=ts_ms()) noexcept
Alias for start_of_hour_ms function.
constexpr T1 hour_to_ms(T2 ts) noexcept
Converts a timestamp from hours to milliseconds.
constexpr const ts_t finish_of_min(ts_t ts=ts()) noexcept
Alias for end_of_min function.
constexpr const ts_ms_t start_of_day_ms(ts_ms_t ts_ms=ts_ms()) noexcept
Get the start of the day timestamp in milliseconds.
constexpr const ts_t end_of_day(const ts_t &ts=ts()) noexcept
Get the timestamp at the end of the day.
constexpr const T min_of_hour(ts_t ts=ts()) noexcept
Get minute of hour. This function returns a value between 0 to 59.
constexpr const ts_t end_of_min(ts_t ts=ts()) noexcept
Get the timestamp of the end of the minute.
constexpr const T get_unix_day(ts_t ts=ts()) noexcept
Get UNIX day.
constexpr const T next_day_from_unix_day(uday_t unix_day) noexcept
Alias for start_of_next_day_from_unix_day function.
constexpr double sec_to_fhour(T ts) noexcept
Converts a timestamp from seconds to floating-point hours.
constexpr const T1 num_days_in_month(T2 year, T3 month) noexcept
Get the number of days in a month.
constexpr T1 ms_to_hour(T2 ts) noexcept
Converts a timestamp from milliseconds to hours.
constexpr const ts_t week_begin(ts_t ts=ts())
Alias for start_of_week function.
constexpr const T unix_day_to_ts(uday_t unix_day) noexcept
Alias for unix_day_to_timestamp function.
constexpr const ts_t previous_day_start(ts_t ts=ts(), T days=1) noexcept
Alias for start_of_prev_day function.
constexpr const T get_unixday(ts_t ts=ts()) noexcept
Alias for get_unix_day function.
constexpr const ts_t next_day_start(ts_t ts, T days=1) noexcept
Alias for start_of_next_day function.
constexpr const ts_t start_of_day(ts_t ts=ts()) noexcept
Get the start of the day timestamp.
constexpr T1 hour_to_sec(T2 ts) noexcept
Converts a timestamp from hours to seconds.
constexpr const T uday_ms(ts_ms_t t_ms=ts_ms()) noexcept
Alias for get_unix_day_ms function.
constexpr const T ms_of_ts(ts_ms_t ts) noexcept
Get the millisecond part of the timestamp.
constexpr const ts_t finish_of_week(ts_t ts=ts())
Alias for end_of_week function.
constexpr const ts_t start_of_prev_day(ts_t ts=ts(), T days=1) noexcept
Get timestamp of the start of the previous day.
TIME_SHIELD_CONSTEXPR const ts_ms_t start_of_year_date_ms(T year)
Get the timestamp in milliseconds of the start of the year.
constexpr const T get_days_difference(ts_t start, ts_t stop) noexcept
Get the number of days between two timestamps.
constexpr double sec_to_fmin(T ts) noexcept
Converts a timestamp from seconds to floating-point minutes.
TIME_SHIELD_CONSTEXPR const ts_ms_t year_start_date_ms(T year)
Alias for start_of_year_date_ms function.
TIME_SHIELD_CONSTEXPR const T month_of_year(ts_t ts) noexcept
Get the month of the year.
constexpr const ts_t finish_of_hour_sec(ts_ms_t ts_ms=ts_ms()) noexcept
Alias for end_of_hour_sec function.
constexpr const ts_t end_of_hour(ts_t ts=ts()) noexcept
Get the timestamp at the end of the hour. This function sets the minute and second to 59.
constexpr const T end_of_day_from_unix_day(uday_t unix_day) noexcept
Converts a UNIX day to a timestamp representing the end of the day in seconds.
TIME_SHIELD_CONSTEXPR const T1 last_sunday_month_day(T2 year, T3 month)
Get the day of the last Sunday of the given month and year.
constexpr const T unixday_to_ts(uday_t unix_day) noexcept
Alias for unix_day_to_timestamp function.
TIME_SHIELD_CONSTEXPR const T to_year(ts_t ts=ts())
Alias for get_year function.
constexpr const T get_unix_year(ts_t ts) noexcept
Converts a UNIX timestamp to a year.
long eod_from_unix_day_ms(long uday)
Alias for end_of_day_from_unix_day_ms.
constexpr const T unix_min(ts_t ts=ts())
Alias for get_unix_min function.
constexpr const T days_in_year_ts(ts_t ts=ts())
Alias for num_days_in_year_ts function.
TIME_SHIELD_CONSTEXPR const ts_t month_begin(ts_t ts=ts())
Alias for start_of_month function.
constexpr const T to_unix_year(ts_t ts) noexcept
Alias for get_unix_year function.
TIME_SHIELD_CONSTEXPR const ts_t year_start_ms(ts_t ts_ms=ts_ms())
Alias for start_of_year_ms function.
constexpr const T get_weekday_from_ts(ts_t ts) noexcept
Get the weekday from a timestamp.
constexpr fts_t hour_to_fsec(T hr) noexcept
Converts a timestamp from hours to floating-point seconds.
constexpr const ts_t start_of_period(T p, ts_t ts=ts())
Get the timestamp of the start of the period.
TIME_SHIELD_CONSTEXPR const ts_t to_timestamp(T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0)
Converts a date and time to a timestamp.
constexpr const T unix_day_ms(ts_ms_t t_ms=ts_ms()) noexcept
Alias for get_unix_day_ms function.
constexpr const T uday(ts_t ts=ts()) noexcept
Alias for get_unix_day function.
constexpr fts_t min_to_fsec(T min) noexcept
Converts a timestamp from minutes to floating-point seconds.
TIME_SHIELD_CONSTEXPR const ts_ms_t year_begin_date_ms(T year)
Alias for start_of_year_date_ms function.
TIME_SHIELD_CONSTEXPR const T hour24_to_12(T hour) noexcept
Converts a 24-hour format hour to a 12-hour format.
constexpr const T num_days_in_year_ts(ts_t ts=ts())
Get the number of days in the current year.
TIME_SHIELD_CONSTEXPR const ts_t year_start_date(T year)
Alias for start_of_year_date function.
constexpr const T1 days_in_year(T2 year) noexcept
Alias for num_days_in_year function.
constexpr const T unix_day_to_ts_ms(uday_t unix_day) noexcept
Alias for unix_day_to_timestamp_ms function.
TIME_SHIELD_CONSTEXPR const fts_t to_ftimestamp(T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0, T3 ms=0)
Converts a date and time to a floating-point timestamp.
constexpr const T start_of_day_from_unix_day_ms(uday_t unix_day) noexcept
Alias for unix_day_to_timestamp_ms function.
TIME_SHIELD_CONSTEXPR const ts_t start_of_month(ts_t ts=ts())
Get the timestamp at the start of the current month.
constexpr const ts_t saturday_begin(ts_t ts=ts())
Alias for start_of_saturday function.
constexpr const T unix_day_to_timestamp(uday_t unix_day) noexcept
Converts a UNIX day to a timestamp in seconds.
constexpr const ts_t start_of_next_day(ts_t ts, T days=1) noexcept
Get the timestamp of the start of the day after a specified number of days.
constexpr const ts_t end_of_period(T p, ts_t ts=ts())
Get the timestamp of the end of the period.
constexpr const T get_weekday_from_ts_ms(ts_ms_t ts_ms)
Get the weekday from a timestamp in milliseconds.
constexpr const T umin(ts_t ts=ts())
Alias for get_unix_min function.
constexpr const T unix_day_to_timestamp_ms(uday_t unix_day) noexcept
Converts a UNIX day to a timestamp in milliseconds.
TIME_SHIELD_CONSTEXPR const T1 final_sunday_month_day(T2 year, T3 month)
Alias for last_sunday_month_day function.
constexpr const ts_ms_t finish_of_hour_ms(ts_ms_t ts_ms=ts_ms()) noexcept
Alias for end_of_hour_ms function.
constexpr const ts_ms_t start_of_next_day_ms(ts_ms_t ts_ms, T days=1) noexcept
Get the timestamp of the start of the day after a specified number of days.
constexpr T1 min_to_ms(T2 ts) noexcept
Converts a timestamp from minutes to milliseconds.
constexpr const T sec_of_day(ts_t ts=ts()) noexcept
Get the second of the day.
constexpr const ts_ms_t end_of_hour_ms(ts_ms_t ts_ms=ts_ms()) noexcept
Get the timestamp at the end of the hour.
constexpr T1 ms_to_min(T2 ts) noexcept
Converts a timestamp from milliseconds to minutes.
TIME_SHIELD_CONSTEXPR const T1 num_days_in_month_ts(ts_t ts=ts()) noexcept
Get the number of days in the month of the given timestamp.
constexpr const ts_t end_of_hour_sec(ts_ms_t ts_ms=ts_ms()) noexcept
Get the timestamp at the end of the hour.
TIME_SHIELD_CONSTEXPR const ts_ms_t ts_ms(T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0, T2 ms=0)
Alias for to_timestamp_ms function.
TIME_SHIELD_CONSTEXPR const T get_year_ms(ts_ms_t ts_ms=ts_ms())
Get the year from the timestamp in milliseconds.
TIME_SHIELD_CONSTEXPR const ts_ms_t year_end_ms(ts_ms_t ts_ms=ts_ms())
Alias for end_of_year_ms function.
constexpr T1 sec_to_min(T2 ts) noexcept
Converts a timestamp from seconds to minutes.
constexpr const ts_ms_t start_of_hour_ms(ts_ms_t ts_ms=ts_ms()) noexcept
Get the timestamp at the start of the hour. This function sets the minute and second to zero.
constexpr const ts_t finish_of_hour(ts_t ts=ts()) noexcept
Alias for end_of_hour function.
TIME_SHIELD_CONSTEXPR const ts_ms_t to_ts_ms(T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0, T2 ms=0)
Alias for to_timestamp_ms function.
constexpr const T next_day_unix_day(uday_t unix_day) noexcept
Alias for start_of_next_day_from_unix_day function.
TIME_SHIELD_CONSTEXPR const ts_ms_t end_of_year_ms(ts_ms_t ts_ms=ts_ms())
Get the timestamp in milliseconds of the end of the year.
TIME_SHIELD_CONSTEXPR const ts_t year_start(ts_t ts=ts())
Alias for start_of_year function.
constexpr T1 sec_to_hour(T2 ts) noexcept
Converts a timestamp from seconds to hours.
constexpr const T start_of_next_day_from_unix_day(uday_t unix_day) noexcept
Converts a UNIX day to a timestamp representing the start of the next day in seconds.
TIME_SHIELD_CONSTEXPR const ts_t final_sunday_of_month(ts_t ts=ts())
Alias for last_sunday_of_month function.
TIME_SHIELD_CONSTEXPR const T get_year(ts_t ts=ts())
Get the year from the timestamp.
constexpr const T1 num_days_in_year(T2 year) noexcept
Get the number of days in a given year.
constexpr const ts_t day_end_sec(ts_ms_t ts_ms=ts_ms()) noexcept
Alias for end_of_day_sec function.
TIME_SHIELD_CONSTEXPR ts_t end_of_year(ts_t ts=ts())
Get the end-of-year timestamp.
constexpr const T unixday(ts_t ts=ts()) noexcept
Alias for get_unix_day function.
int min_in_hour(long ts)
Alias for min_of_hour.
constexpr T1 sec_to_ms(T2 ts) noexcept
Converts a timestamp from seconds to milliseconds.
constexpr const ts_t day_start_sec(ts_ms_t ts_ms=ts_ms()) noexcept
Alias for start_of_day_sec function.
TIME_SHIELD_CONSTEXPR const ts_ms_t start_of_year_ms(ts_ms_t ts_ms=ts_ms()) noexcept
Get the start of the year timestamp in milliseconds.
constexpr const ts_t start_of_hour_sec(ts_ms_t ts_ms=ts_ms()) noexcept
Get the timestamp at the start of the hour.
constexpr const ts_t day_end(const ts_t &ts=ts()) noexcept
Alias for end_of_day function.
TIME_SHIELD_CONSTEXPR const T year(ts_t ts=ts())
Alias for get_year function.
constexpr const T to_unix_min(ts_t ts=ts())
Alias for get_unix_min function.
constexpr const T get_unix_min(ts_t ts=ts())
Get UNIX minute.
constexpr const T start_of_day_from_unix_day(uday_t unix_day) noexcept
Alias for unix_day_to_timestamp function.
TIME_SHIELD_CONSTEXPR const ts_t last_day_of_month(ts_t ts=ts())
Alias for end_of_month function.
constexpr const T days(ts_t start, ts_t stop) noexcept
Alias for get_days_difference function.
MqlDateTime to_mql_dt(long ts)
Alias for to_date_time_mql.
TimeZoneStruct to_tz_struct(int offset)
Alias for to_time_zone.
TIME_SHIELD_CONSTEXPR const ts_t start_of_year(ts_t ts) noexcept
Get the start of the year timestamp.
constexpr const ts_ms_t day_start_ms(ts_ms_t ts_ms=ts_ms()) noexcept
Alias for start_of_day_ms function.
constexpr const ts_t start_of_min(ts_t ts=ts()) noexcept
Get the timestamp of the beginning of the minute.
TIME_SHIELD_CONSTEXPR const T h24_to_h12(T hour) noexcept
Alias for hour24_to_12 function.
constexpr const T uday_to_ts_ms(uday_t unix_day) noexcept
Alias for unix_day_to_timestamp_ms function.
constexpr const T sec_of_day_ms(ts_ms_t ts_ms) noexcept
Get the second of the day from milliseconds timestamp.
const TimeZoneStruct to_time_zone_struct(tz_t offset)
Converts an integer to a TimeZoneStruct.
constexpr const T1 get_weekday(T2 year, T3 month, T3 day)
Alias for day_of_week_date function.
constexpr const T1 days_in_month(T2 year, T3 month) noexcept
Alias for num_days_in_month function.
constexpr const ts_t start_of_hour(ts_t ts=ts()) noexcept
Get the timestamp at the start of the hour.
TIME_SHIELD_CONSTEXPR const 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 and time to a timestamp in milliseconds.
constexpr const ts_t end_of_week(ts_t ts=ts())
Get the timestamp of the end of the week.
TIME_SHIELD_CONSTEXPR const ts_t year_begin_ms(ts_t ts_ms=ts_ms())
Alias for start_of_year_ms function.
TIME_SHIELD_CONSTEXPR const ts_t year_begin(ts_t ts=ts())
Alias for start_of_year function.
constexpr const T get_days(ts_t start, ts_t stop) noexcept
Alias for get_days_difference function.
constexpr const ts_ms_t end_of_day_ms(ts_ms_t ts_ms=ts_ms()) noexcept
Get the timestamp at the end of the day in milliseconds.
constexpr const T get_unixday_ms(ts_ms_t t_ms=ts_ms()) noexcept
Alias for get_unix_day_ms function.
constexpr const T min_of_day(ts_t ts=ts()) noexcept
Get minute of day. This function returns a value between 0 to 1439 (minute of day).
constexpr const ts_t min_begin(ts_t ts=ts()) noexcept
Alias for start_of_min function.
constexpr const fts_t ms_to_fsec(T ts_ms) noexcept
Converts a timestamp from milliseconds to floating-point seconds.
constexpr const T1 ms_to_sec(T2 ts_ms) noexcept
Converts a timestamp from milliseconds to seconds.
constexpr const T hour_of_day(ts_t ts=ts()) noexcept
Get the hour of the day.
const T day_of_year(ts_t ts=ts())
Get the day of the year.
constexpr const T1 day_of_week_date(T2 year, T3 month, T3 day)
Get the day of the week.
MqlDateTime to_date_time_mql(long ts)
Convert a timestamp to the standard MqlDateTime structure.
constexpr const T hour_in_day(ts_t ts=ts()) noexcept
Alias for hour_of_day function.
constexpr const ts_ms_t next_day_start_ms(ts_ms_t ts_ms, T days=1) noexcept
Alias for start_of_next_day_ms function.
TIME_SHIELD_CONSTEXPR const ts_t end_of_month(ts_t ts=ts())
Get the last timestamp of the current month.
Month
Enumeration of the months of the year.
TIME_SHIELD_CONSTEXPR const fts_t dt_to_ftimestamp(const T &date_time)
Converts a date-time structure to a floating-point timestamp.
T to_date_time_ms(ts_ms_t ts)
Converts a timestamp in milliseconds to a date-time structure with milliseconds.
constexpr const T1 get_weekday_from_date(const T2 &date)
Get the day of the week from a date structure.
TIME_SHIELD_CONSTEXPR const ts_t dt_to_timestamp(const T &date_time)
Converts a date-time structure to a timestamp.
T to_dt_ms(ts_ms_t ts)
Alias for to_date_time_ms function.
constexpr const T1 day_of_week_dt(const T2 &date)
Alias for get_weekday_from_date function that accepts a date structure.
T1 to_date_time(T2 ts)
Converts a timestamp to a date-time structure.
TIME_SHIELD_CONSTEXPR const ts_t dt_to_timestamp_ms(const T &date_time)
Converts a date-time structure to a timestamp in milliseconds.
T1 to_dt(T2 ts)
Alias for to_date_time function.
const T us_of_sec() noexcept
Get the microsecond part of the current second.
const T ns_of_sec() noexcept
Get the nanosecond part of the current second.
const ts_ms_t ts_ms() noexcept
Get the current UTC timestamp in milliseconds.
const T ms_of_sec() noexcept
Get the millisecond part of the current second.
constexpr const bool is_leap_year_date(T year) noexcept
Checks if the given year is a leap year.
TIME_SHIELD_CONSTEXPR const bool is_leap_year(ts_t ts)
Alias for is_leap_year_ts function.
TIME_SHIELD_CONSTEXPR const bool is_leap_year_ts(ts_t ts)
Checks if the given year is a leap year.
Main namespace for the Time Shield library.
Structure to represent date and time.
int ms
Millisecond component of time (0-999)
int hour
Hour component of time (0-23)
int64_t year
Year component of the date.
int day
Day component of the date (1-31).
int min
Minute component of time (0-59)
int mon
Month component of the date (1-12).
int sec
Second component of time (0-59)
Structure to represent time zone information.
Header for time zone structure and related functions (MQL5).
Header with validation functions for dates, times, and timestamps.