Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
time_conversions.mqh
Go to the documentation of this file.
1//+------------------------------------------------------------------+
2//| time_conversions.mqh |
3//| Time Shield - MQL5 Time Conversions |
4//| Copyright 2025, NewYaroslav |
5//| https://github.com/NewYaroslav/time-shield-cpp |
6//+------------------------------------------------------------------+
7#ifndef __TIME_SHIELD_TIME_CONVERSIONS_MQH__
8#define __TIME_SHIELD_TIME_CONVERSIONS_MQH__
9
18
19#property copyright "Copyright 2025, NewYaroslav"
20#property link "https://github.com/NewYaroslav/time-shield-cpp"
21#property strict
22
25#include <time_shield/enums.mqh>
28
29namespace time_shield {
30
34
38 int ns_of_sec(double ts) {
39 double frac = ts - MathFloor(ts);
40 return (int)MathRound(frac * NS_PER_SEC);
41 }
42
46 int us_of_sec(double ts) {
47 double frac = ts - MathFloor(ts);
48 return (int)MathRound(frac * US_PER_SEC);
49 }
50
54 int ms_of_sec(double ts) {
55 double frac = ts - MathFloor(ts);
56 return (int)MathRound(frac * MS_PER_SEC);
57 }
58
62 int ms_of_ts(long ts_ms) {
63 return (int)(ts_ms % MS_PER_SEC);
64 }
65
66 //----------------------------------------------------------------------
67 // Seconds <-> Milliseconds
68 //----------------------------------------------------------------------
69
73 long sec_to_ms(double sec) {
74 return (long)MathRound(sec * MS_PER_SEC);
75 }
76
80 long ms_to_sec(long ms) {
81 return ms / MS_PER_SEC;
82 }
83
87 double ms_to_fsec(long ms) {
88 return (double)ms / (double)MS_PER_SEC;
89 }
90
91 //----------------------------------------------------------------------
92 // Minutes <-> Milliseconds / Seconds
93 //----------------------------------------------------------------------
94
98 long min_to_ms(double min) {
99 return (long)MathRound(min * MS_PER_MIN);
100 }
101
105 int ms_to_min(long ms) {
106 return (int)(ms / MS_PER_MIN);
107 }
108
112 long min_to_sec(double min) {
113 return (long)MathRound(min * SEC_PER_MIN);
114 }
115
119 int sec_to_min(long sec) {
120 return (int)(sec / SEC_PER_MIN);
121 }
122
126 double min_to_fsec(double min) {
127 return min * SEC_PER_MIN;
128 }
129
133 double sec_to_fmin(long sec) {
134 return (double)sec / (double)SEC_PER_MIN;
135 }
136
137 //----------------------------------------------------------------------
138 // Hours <-> Milliseconds / Seconds
139 //----------------------------------------------------------------------
140
144 long hour_to_ms(double hr) {
145 return (long)MathRound(hr * MS_PER_HOUR);
146 }
147
151 int ms_to_hour(long ms) {
152 return (int)(ms / MS_PER_HOUR);
153 }
154
158 long hour_to_sec(double hr) {
159 return (long)MathRound(hr * SEC_PER_HOUR);
160 }
161
165 int sec_to_hour(long sec) {
166 return (int)(sec / SEC_PER_HOUR);
167 }
168
172 double hour_to_fsec(double hr) {
173 return hr * SEC_PER_HOUR;
174 }
175
179double sec_to_fhour(long sec) {
180 return (double)sec / (double)SEC_PER_HOUR;
181 }
182
186 int hour24_to_12(int hour) {
187 if(hour == 0 || hour > 12) return 12;
188 return hour;
189 }
190
193 int h24_to_h12(int hour) { return hour24_to_12(hour); }
194
195 //----------------------------------------------------------------------
196 // Timestamp <-> Year
197 //----------------------------------------------------------------------
198
202 long get_unix_year(long ts) {
203 const long BIAS_292277022000 = 9223371890843040000;
204 const long BIAS_2000 = 946684800;
205
206 long y = MAX_YEAR;
207 long secs = -((ts - BIAS_2000) - BIAS_292277022000);
208
209 long n_400_years = secs / SEC_PER_400_YEARS;
210 secs -= n_400_years * SEC_PER_400_YEARS;
211 y -= n_400_years * 400;
212
213 long n_100_years = secs / SEC_PER_100_YEARS;
214 secs -= n_100_years * SEC_PER_100_YEARS;
215 y -= n_100_years * 100;
216
217 long n_4_years = secs / SEC_PER_4_YEARS;
218 secs -= n_4_years * SEC_PER_4_YEARS;
219 y -= n_4_years * 4;
220
221 long n_1_years = secs / SEC_PER_YEAR;
222 secs -= n_1_years * SEC_PER_YEAR;
223 y -= n_1_years;
224
225 y = secs == 0 ? y : y - 1;
226 return y - UNIX_EPOCH;
227 }
228
231 long unix_year(long ts) { return get_unix_year(ts); }
232
235 long to_unix_year(long ts) { return get_unix_year(ts); }
236
240 long get_year(long ts) {
241 return get_unix_year(ts) + UNIX_EPOCH;
242 }
243
246 long year(long ts) { return get_year(ts); }
247
250 long to_year(long ts) { return get_year(ts); }
251
255 long get_year_ms(long ts_ms) {
256 return get_year(ms_to_sec(ts_ms));
257 }
258
261 long year_ms(long ts_ms) { return get_year_ms(ts_ms); }
262
265 long to_year_ms(long ts_ms) { return get_year_ms(ts_ms); }
266
267 //----------------------------------------------------------------------
268 // DateTime conversions
269 //----------------------------------------------------------------------
270
275 MqlDateTime tmp;
276 TimeToStruct((datetime)ts, tmp);
278 dt.year = tmp.year;
279 dt.mon = tmp.mon;
280 dt.day = tmp.day;
281 dt.hour = tmp.hour;
282 dt.min = tmp.min;
283 dt.sec = tmp.sec;
284 dt.ms = 0;
285 return dt;
286 }
287
291
295 MqlDateTime to_date_time_mql(long ts) {
296 MqlDateTime dt;
297 TimeToStruct((datetime)ts, dt);
298 return dt;
299 }
300
303 MqlDateTime to_mql_dt(long ts) { return to_date_time_mql(ts); }
304
310 dt.ms = ms_of_ts(ts_ms);
311 return dt;
312 }
313
317
322 MqlDateTime tmp;
323 tmp.year = (int)dt.year;
324 tmp.mon = dt.mon;
325 tmp.day = dt.day;
326 tmp.hour = dt.hour;
327 tmp.min = dt.min;
328 tmp.sec = dt.sec;
329 return (long)StructToTime(tmp);
330 }
331
335 long dt_to_timestamp(const MqlDateTime &dt) {
336 return (long)StructToTime(dt);
337 }
338
341 long to_timestamp(const DateTimeStruct &dt) { return dt_to_timestamp(dt); }
342
345 long to_timestamp(const MqlDateTime &dt) { return dt_to_timestamp(dt); }
346
355 long to_timestamp(long year, int mon, int day, int hour=0, int min=0, int sec=0) {
356 MqlDateTime dt;
357 dt.year = (int)year;
358 dt.mon = mon;
359 dt.day = day;
360 dt.hour = hour;
361 dt.min = min;
362 dt.sec = sec;
363 return (long)StructToTime(dt);
364 }
365
368 long to_ts(long year, int mon, int day, int hour=0, int min=0, int sec=0) {
369 return to_timestamp(year, mon, day, hour, min, sec);
370 }
371
381 long to_timestamp_ms(long year, int mon, int day, int hour=0, int min=0, int sec=0, int ms=0) {
382 return sec_to_ms(to_timestamp(year, mon, day, hour, min, sec)) + ms;
383 }
384
387 long to_ts_ms(long year, int mon, int day, int hour=0, int min=0, int sec=0, int ms=0) {
388 return to_timestamp_ms(year, mon, day, hour, min, sec, ms);
389 }
390
393 long ts_ms(long year, int mon, int day, int hour=0, int min=0, int sec=0, int ms=0) {
394 return to_timestamp_ms(year, mon, day, hour, min, sec, ms);
395 }
396
401 return sec_to_ms(dt_to_timestamp(dt)) + dt.ms;
402 }
403
407 long dt_to_timestamp_ms(const MqlDateTime &dt) {
408 return sec_to_ms(dt_to_timestamp(dt));
409 }
410
413 long to_timestamp_ms(const DateTimeStruct &dt) { return dt_to_timestamp_ms(dt); }
414
417 long to_timestamp_ms(const MqlDateTime &dt) { return dt_to_timestamp_ms(dt); }
418
423 return (double)dt_to_timestamp(dt) + (double)dt.ms / (double)MS_PER_SEC;
424 }
425
429 double dt_to_ftimestamp(const MqlDateTime &dt) {
430 return (double)dt_to_timestamp(dt);
431 }
432
435 double to_ftimestamp(const DateTimeStruct &dt) { return dt_to_ftimestamp(dt); }
436
439 double to_ftimestamp(const MqlDateTime &dt) { return dt_to_ftimestamp(dt); }
440
441 //----------------------------------------------------------------------
442 // Start/End of intervals
443 //----------------------------------------------------------------------
444
448 long start_of_day(long ts) {
449 return ts - (ts % SEC_PER_DAY);
450 }
451
454 long day_start(long ts) { return start_of_day(ts); }
455
460 long start_of_prev_day(long ts, int days=1) {
461 return start_of_day(ts) - days * SEC_PER_DAY;
462 }
463
466 long previous_day_start(long ts, int days=1) { return start_of_prev_day(ts, days); }
467
473 }
474
478
483 return ts_ms - (ts_ms % MS_PER_DAY);
484 }
485
488 long day_start_ms(long ts_ms) { return start_of_day_ms(ts_ms); }
489
494 long start_of_next_day(long ts, int days=1) {
495 return start_of_day(ts) + days * SEC_PER_DAY;
496 }
497
500 long next_day_start(long ts, int days=1) { return start_of_next_day(ts, days); }
501
506 long start_of_next_day_ms(long ts_ms, int days=1) {
508 }
509
513
518 long next_day(long ts, int days=1) {
519 return ts + days * SEC_PER_DAY;
520 }
521
526 long next_day_ms(long ts_ms, int days=1) {
527 return ts_ms + days * MS_PER_DAY;
528 }
529
533 long end_of_day(long ts) {
534 return ts - (ts % SEC_PER_DAY) + SEC_PER_DAY - 1;
535 }
536
539 long day_end(long ts) { return end_of_day(ts); }
540
545 return end_of_day(ms_to_sec(ts_ms));
546 }
547
550 long day_end_sec(long ts_ms) { return end_of_day_sec(ts_ms); }
551
555 long end_of_day_ms(long ts_ms) {
556 return ts_ms - (ts_ms % MS_PER_DAY) + MS_PER_DAY - 1;
557 }
558
561 long day_end_ms(long ts_ms) { return end_of_day_ms(ts_ms); }
562
568 int day_of_week_date(long year, int month, int day) {
569 long a = (14 - month) / MONTHS_PER_YEAR;
570 long y = year - a;
571 long m = month + MONTHS_PER_YEAR * a - 2;
572 long r = 7000 + day + y + (y / 4) - (y / 100) + (y / 400) + (31 * m) / MONTHS_PER_YEAR;
573 return (int)(r % DAYS_PER_WEEK);
574 }
575
578 int get_weekday(long year, int month, int day) { return day_of_week_date(year, month, day); }
579
582 int day_of_week(long year, int month, int day) { return day_of_week_date(year, month, day); }
583
588 return day_of_week_date(dt.year, dt.mon, dt.day);
589 }
590
594 int get_weekday_from_date(const MqlDateTime &dt) {
595 return day_of_week_date(dt.year, dt.mon, dt.day);
596 }
597
601
604 int day_of_week(const DateTimeStruct &dt) { return get_weekday_from_date(dt); }
605
608 int day_of_week_dt(const MqlDateTime &dt) { return get_weekday_from_date(dt); }
609
612 int day_of_week(const MqlDateTime &dt) { return get_weekday_from_date(dt); }
613
618 return (int)((ts / SEC_PER_DAY + THU) % DAYS_PER_WEEK);
619 }
620
623 int day_of_week(long ts) { return get_weekday_from_ts(ts); }
624
631
635
639 long start_of_year(long ts) {
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);
643 }
644
648 long end_of_year(long ts) {
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;
652 }
653
656 long year_start(long ts) { return start_of_year(ts); }
657
660 long year_begin(long ts) { return start_of_year(ts); }
661
667 }
668
672
676
681 if(year < 2100) {
682 long year_diff = year >= UNIX_EPOCH ? year - UNIX_EPOCH : UNIX_EPOCH - year;
683 long year_start_ts = (year_diff / 4) * SEC_PER_4_YEARS;
684 long year_remainder = year_diff % 4;
685 long SEC_PER_YEAR_X2 = 2 * SEC_PER_YEAR;
686 long SEC_PER_YEAR_V2 = SEC_PER_YEAR_X2 + SEC_PER_LEAP_YEAR;
687 switch(year_remainder) {
688 case 0: return year_start_ts;
689 case 1: return year_start_ts + SEC_PER_YEAR;
690 case 2: return year_start_ts + SEC_PER_YEAR_X2;
691 default: return year_start_ts + SEC_PER_YEAR_V2;
692 }
693 return year_start_ts + SEC_PER_YEAR_V2;
694 }
695 return to_timestamp(year, 1, 1);
696 }
697
701
705
712
716
720
726 }
727
730 long year_end_ms(long ts_ms) { return end_of_year_ms(ts_ms); }
731
735 int day_of_year(long ts) {
736 return (int)((ts - start_of_year(ts)) / SEC_PER_DAY) + 1;
737 }
738
743 const int JAN_AND_FEB_DAY_LEAP_YEAR = 60;
744 static const int TABLE_MONTH_OF_YEAR[] = {
745 0,
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,
758 };
759 int dy = day_of_year(ts);
760 if(is_leap_year(ts) && dy >= JAN_AND_FEB_DAY_LEAP_YEAR)
761 return (Month)TABLE_MONTH_OF_YEAR[dy - 1];
762 return (Month)TABLE_MONTH_OF_YEAR[dy];
763 }
764
768 int day_of_month(long ts) {
769 const int JAN_AND_FEB_DAY_LEAP_YEAR = 60;
770 static const int TABLE_DAY_OF_YEAR[] = {
771 0,
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,
782 };
783 int dy = day_of_year(ts);
784 if(is_leap_year(ts)) {
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];
787 }
788 return TABLE_DAY_OF_YEAR[dy];
789 }
790
795 int num_days_in_month(long year, int month) {
796 if(month > MONTHS_PER_YEAR || month < 0) return 0;
797 static const int num_days[13] = {0,31,30,31,30,31,30,31,31,30,31,30,31};
798 if(month == FEB) {
799 if(is_leap_year_date(year)) return 29;
800 return 28;
801 }
802 return num_days[month];
803 }
804
807 int days_in_month(long year, int month) { return num_days_in_month(year, month); }
808
813 static const int num_days[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
814 int month = month_of_year(ts);
815 if(month == FEB) {
816 return is_leap_year(ts) ? 29 : 28;
817 }
818 return num_days[month];
819 }
820
824
828
834 return DAYS_PER_YEAR;
835 }
836
839 int days_in_year(long year) { return num_days_in_year(year); }
840
846 return DAYS_PER_YEAR;
847 }
848
852
856 long start_of_month(long ts) {
857 return start_of_day(ts) - (day_of_month(ts) - 1) * SEC_PER_DAY;
858 }
859
862 long month_begin(long ts) { return start_of_month(ts); }
863
867 long end_of_month(long ts) {
869 }
870
873 long last_day_of_month(long ts) { return end_of_month(ts); }
874
880 }
881
885
890 int last_sunday_month_day(long year, int month) {
891 int days = num_days_in_month(year, month);
892 return days - day_of_week_date(year, month, days);
893 }
894
897 int final_sunday_month_day(long year, int month) { return last_sunday_month_day(year, month); }
898
902 long start_of_hour(long ts) {
903 return ts - (ts % SEC_PER_HOUR);
904 }
905
908 long hour_begin(long ts) { return start_of_hour(ts); }
909
915 }
916
920
925 return ts_ms - (ts_ms % MS_PER_HOUR);
926 }
927
931
935 long end_of_hour(long ts) {
936 return ts - (ts % SEC_PER_HOUR) + SEC_PER_HOUR - 1;
937 }
938
941 long finish_of_hour(long ts) { return end_of_hour(ts); }
942
947 return end_of_hour(ms_to_sec(ts_ms));
948 }
949
953
958 return ts_ms - (ts_ms % MS_PER_HOUR) + MS_PER_HOUR - 1;
959 }
960
964
968 int hour_of_day(long ts) {
969 return (int)((ts / SEC_PER_HOUR) % HOURS_PER_DAY);
970 }
971
974 int hour_in_day(long ts) { return hour_of_day(ts); }
975
979 long start_of_week(long ts) {
981 }
982
985 long week_begin(long ts) { return start_of_week(ts); }
986
990 long end_of_week(long ts) {
992 }
993
996 long finish_of_week(long ts) { return end_of_week(ts); }
997
1002 return start_of_day(ts) + (SAT - day_of_week(ts)) * SEC_PER_DAY;
1003 }
1004
1007 long saturday_begin(long ts) { return start_of_saturday(ts); }
1008
1012 long start_of_min(long ts) {
1013 return ts - (ts % SEC_PER_MIN);
1014 }
1015
1018 long min_begin(long ts) { return start_of_min(ts); }
1019
1023 long end_of_min(long ts) {
1024 return ts - (ts % SEC_PER_MIN) + SEC_PER_MIN - 1;
1025 }
1026
1029 long finish_of_min(long ts) { return end_of_min(ts); }
1030
1034 int min_of_day(long ts) {
1035 return (int)((ts / SEC_PER_MIN) % MIN_PER_DAY);
1036 }
1037
1041 int min_of_hour(long ts) {
1042 return (int)((ts / SEC_PER_MIN) % MIN_PER_HOUR);
1043 }
1044
1047 int min_in_hour(long ts) { return min_of_hour(ts); }
1048
1053 long start_of_period(int p, long ts) {
1054 return ts - (ts % p);
1055 }
1056
1061 long end_of_period(int p, long ts) {
1062 return ts - (ts % p) + p - 1;
1063 }
1064
1065 //----------------------------------------------------------------------
1066 // UNIX day and minute helpers
1067 //----------------------------------------------------------------------
1068
1072 long get_unix_day(long ts) {
1073 return ts / SEC_PER_DAY;
1074 }
1075
1078 long unix_day(long ts) { return get_unix_day(ts); }
1079
1082 long get_unixday(long ts) { return get_unix_day(ts); }
1083
1086 long unixday(long ts) { return get_unix_day(ts); }
1087
1090 long uday(long ts) { return get_unix_day(ts); }
1091
1096 int get_days_difference(long start, long stop) {
1097 return (int)((stop - start) / SEC_PER_DAY);
1098 }
1099
1102 int get_days(long start, long stop) { return get_days_difference(start, stop); }
1103
1106 int days(long start, long stop) { return get_days_difference(start, stop); }
1107
1112 return get_unix_day(ms_to_sec(ts_ms));
1113 }
1114
1117 long unix_day_ms(long ts_ms) { return get_unix_day_ms(ts_ms); }
1118
1122
1125 long unixday_ms(long ts_ms) { return get_unix_day_ms(ts_ms); }
1126
1129 long uday_ms(long ts_ms) { return get_unix_day_ms(ts_ms); }
1130
1135 return uday * SEC_PER_DAY;
1136 }
1137
1141
1145
1149
1153
1158 return uday * MS_PER_DAY;
1159 }
1160
1164
1168
1172
1176
1181 return uday * SEC_PER_DAY + SEC_PER_DAY - 1;
1182 }
1183
1188 return uday * MS_PER_DAY + MS_PER_DAY - 1;
1189 }
1190
1194
1198
1205
1212
1216
1220
1224
1228
1232
1236 long get_unix_min(long ts) {
1237 return ts / SEC_PER_MIN;
1238 }
1239
1242 long unix_min(long ts) { return get_unix_min(ts); }
1243
1246 long to_unix_min(long ts) { return get_unix_min(ts); }
1247
1250 long umin(long ts) { return get_unix_min(ts); }
1251
1255 int sec_of_day(long ts) {
1256 return (int)(ts % SEC_PER_DAY);
1257 }
1258
1263 return sec_of_day(ms_to_sec(ts_ms));
1264 }
1265
1271 int sec_of_day(int hour, int min, int sec) {
1272 return hour * SEC_PER_HOUR + min * SEC_PER_MIN + sec;
1273 }
1274
1279 return to_time_zone_struct(offset);
1280 }
1281
1284 TimeZoneStruct to_tz_struct(int offset) { return to_time_zone(offset); }
1285
1287
1288}; // namespace time_shield
1289
1290#endif // __TIME_SHIELD_TIME_CONVERSIONS_MQH__
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.
Definition constants.hpp:87
constexpr int64_t DAYS_PER_WEEK
Days per week.
constexpr int64_t SEC_PER_YEAR
Seconds per year (365 days)
Definition constants.hpp:77
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.
Definition constants.hpp:82
constexpr int64_t MAX_YEAR
Maximum representable year.
constexpr int64_t MS_PER_MIN
Milliseconds per minute.
Definition constants.hpp:45
constexpr int64_t SEC_PER_LEAP_YEAR
Seconds per leap year (366 days)
Definition constants.hpp:79
constexpr int64_t MIN_PER_DAY
Minutes per day.
Definition constants.hpp:88
constexpr int64_t DAYS_PER_LEAP_YEAR
Days per leap year.
constexpr int64_t SEC_PER_HOUR
Seconds per hour.
Definition constants.hpp:69
constexpr int64_t UNIX_EPOCH
Start year of UNIX time.
constexpr int64_t MS_PER_DAY
Milliseconds per day.
Definition constants.hpp:59
constexpr int64_t MS_PER_SEC
Milliseconds per second.
Definition constants.hpp:39
constexpr int64_t SEC_PER_400_YEARS
Seconds per 400 years.
Definition constants.hpp:83
constexpr int64_t SEC_PER_DAY
Seconds per day.
Definition constants.hpp:76
constexpr int64_t SEC_PER_MIN
Seconds per minute.
Definition constants.hpp:62
constexpr int64_t NS_PER_SEC
Nanoseconds per second.
Definition constants.hpp:35
constexpr int64_t MS_PER_HOUR
Milliseconds per hour.
Definition constants.hpp:52
constexpr int64_t US_PER_SEC
Microseconds per second.
Definition constants.hpp:38
constexpr int64_t SEC_PER_4_YEARS
Seconds per 4 years.
Definition constants.hpp:80
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.
Definition enums.hpp:104
@ FEB
February.
Definition enums.hpp:106
@ SAT
Saturday.
Definition enums.hpp:48
@ THU
Thursday.
Definition enums.hpp:46
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.