Time Shield Library 2.0.0
C++ library for working with time
Loading...
Searching...
No Matches
time_parser.mqh
Go to the documentation of this file.
1//+------------------------------------------------------------------+
2//| time_parser.mqh |
3//| Time Shield - MQL5 Time Parser |
4//| Copyright 2025, NewYaroslav |
5//| https://github.com/LimiNode/time-shield-cpp |
6//+------------------------------------------------------------------+
7#ifndef TIME_SHIELD_MQL5_HEADER_TIME_PARSER_MQH_INCLUDED
8#define TIME_SHIELD_MQL5_HEADER_TIME_PARSER_MQH_INCLUDED
9
18
19#property copyright "Copyright 2025, NewYaroslav"
20#property link "https://github.com/LimiNode/time-shield-cpp"
21#property strict
22
23#include <time_shield/enums.mqh>
29
30namespace time_shield {
31
35
39 int get_month_number(string month) {
40 if(StringLen(month)==0)
41 return 0;
42 string month_copy = month;
43 string tmp = "";
44 StringConcatenate(tmp,
45 StringToUpper(StringSubstr(month_copy,0,1)),
46 StringToLower(StringSubstr(month_copy,1)));
47 month_copy = tmp;
48 static const string short_names[] = {"Jan","Feb","Mar","Apr","May","Jun",
49 "Jul","Aug","Sep","Oct","Nov","Dec"};
50 static const string full_names[] = {"January","February","March","April","May","June",
51 "July","August","September","October","November","December"};
52 for(int i=0;i<MONTHS_PER_YEAR;++i)
53 {
54 if(month_copy==short_names[i] || month_copy==full_names[i])
55 return i+1;
56 }
57 return 0;
58 }
59
62 int month_of_year(string month) { return get_month_number(month); }
63
64//------------------------------------------------------------------------------
65
70 bool try_get_month_number(string month, int &value) {
71 int res = get_month_number(month);
72 if(res==0)
73 return false;
74 value = res;
75 return true;
76 }
77
80 bool get_month_number(string month, int &value) { return try_get_month_number(month,value); }
81
84 bool month_of_year(string month, int &value) { return try_get_month_number(month,value); }
85
86//------------------------------------------------------------------------------
87
88 bool timeframe_is_ascii_space(const int ch) {
89 return ch==' ' || ch=='\t' || ch=='\n' || ch=='\r' || ch=='\f' || ch=='\v';
90 }
91
92 bool timeframe_is_ascii_digit(const int ch) {
93 return ch>='0' && ch<='9';
94 }
95
96 bool timeframe_is_ascii_alpha(const int ch) {
97 return (ch>='A' && ch<='Z') || (ch>='a' && ch<='z');
98 }
99
100 int timeframe_ascii_to_lower(const int ch) {
101 if(ch>='A' && ch<='Z')
102 return ch - 'A' + 'a';
103 return ch;
104 }
105
106 string timeframe_trim_ascii(string value) {
107 int begin = 0;
108 int end = StringLen(value);
109 while(begin < end && timeframe_is_ascii_space(StringGetCharacter(value, begin)))
110 ++begin;
111 while(end > begin && timeframe_is_ascii_space(StringGetCharacter(value, end - 1)))
112 --end;
113 return StringSubstr(value, begin, end - begin);
114 }
115
116 bool timeframe_ascii_iequals(string value, string literal) {
117 const int len = StringLen(value);
118 if(len != StringLen(literal))
119 return false;
120
121 for(int i = 0; i < len; ++i) {
122 if(timeframe_ascii_to_lower(StringGetCharacter(value, i))
123 != timeframe_ascii_to_lower(StringGetCharacter(literal, i)))
124 return false;
125 }
126
127 return true;
128 }
129
130 bool timeframe_try_parse_positive_long(string value, long &out) {
131 const string trimmed = timeframe_trim_ascii(value);
132 const int len = StringLen(trimmed);
133 const string k_max_long = "9223372036854775807";
134 out = 0;
135 if(len <= 0)
136 return false;
137
138 for(int i = 0; i < len; ++i) {
139 if(!timeframe_is_ascii_digit(StringGetCharacter(trimmed, i)))
140 return false;
141 }
142
143 if(len > StringLen(k_max_long))
144 return false;
145 if(len == StringLen(k_max_long) && StringCompare(trimmed, k_max_long) > 0)
146 return false;
147
148 for(int i = 0; i < len; ++i)
149 out = out * 10 + (long)(StringGetCharacter(trimmed, i) - '0');
150
151 return out > 0;
152 }
153
154 bool timeframe_try_multiply_positive_long(long lhs, long rhs, long &out) {
155 const long k_max_long = 9223372036854775807;
156 out = 0;
157 if(lhs <= 0 || rhs <= 0)
158 return false;
159 if(lhs > k_max_long / rhs)
160 return false;
161 out = lhs * rhs;
162 return true;
163 }
164
165 bool timeframe_try_get_unit_seconds_compact(string unit, long &unit_seconds) {
166 const string normalized = StringToLower(unit);
167 unit_seconds = 0;
168 if(normalized == "s") { unit_seconds = 1; return true; }
169 if(normalized == "m") { unit_seconds = SEC_PER_MIN; return true; }
170 if(normalized == "h") { unit_seconds = SEC_PER_HOUR; return true; }
171 if(normalized == "d") { unit_seconds = SEC_PER_DAY; return true; }
172 if(normalized == "w") { unit_seconds = 7 * SEC_PER_DAY; return true; }
173 if(normalized == "mn") { unit_seconds = 30 * SEC_PER_DAY; return true; }
174 if(normalized == "q") { unit_seconds = 90 * SEC_PER_DAY; return true; }
175 if(normalized == "y") { unit_seconds = SEC_PER_YEAR; return true; }
176 return false;
177 }
178
179 bool timeframe_try_get_unit_seconds_word(string unit, long &unit_seconds) {
180 const string normalized = StringToLower(unit);
181 unit_seconds = 0;
182 if(normalized == "sec" || normalized == "second" || normalized == "seconds") { unit_seconds = 1; return true; }
183 if(normalized == "min" || normalized == "minute" || normalized == "minutes") { unit_seconds = SEC_PER_MIN; return true; }
184 if(normalized == "hr" || normalized == "hour" || normalized == "hours") { unit_seconds = SEC_PER_HOUR; return true; }
185 if(normalized == "day" || normalized == "days") { unit_seconds = SEC_PER_DAY; return true; }
186 if(normalized == "week" || normalized == "weeks") { unit_seconds = 7 * SEC_PER_DAY; return true; }
187 if(normalized == "month" || normalized == "months") { unit_seconds = 30 * SEC_PER_DAY; return true; }
188 if(normalized == "quarter" || normalized == "quarters") { unit_seconds = 90 * SEC_PER_DAY; return true; }
189 if(normalized == "year" || normalized == "years") { unit_seconds = SEC_PER_YEAR; return true; }
190 return false;
191 }
192
193 bool timeframe_try_parse_seconds(string str, long &seconds) {
194 str = timeframe_trim_ascii(str);
195 seconds = 0;
196 const int len = StringLen(str);
197 if(len <= 0)
198 return false;
199
200 long multiplier = 1;
201 long unit_seconds = 0;
202 long result = 0;
203 const int first = StringGetCharacter(str, 0);
204
205 if(timeframe_is_ascii_digit(first)) {
206 int pos = 0;
207 while(pos < len && timeframe_is_ascii_digit(StringGetCharacter(str, pos)))
208 ++pos;
209
210 if(!timeframe_try_parse_positive_long(StringSubstr(str, 0, pos), multiplier))
211 return false;
212
213 while(pos < len && timeframe_is_ascii_space(StringGetCharacter(str, pos)))
214 ++pos;
215 if(pos >= len)
216 return false;
217
218 string unit = StringSubstr(str, pos);
219 for(int i = 0; i < StringLen(unit); ++i) {
220 if(!timeframe_is_ascii_alpha(StringGetCharacter(unit, i)))
221 return false;
222 }
223
224 if(!timeframe_try_get_unit_seconds_word(unit, unit_seconds))
225 return false;
226 if(!timeframe_try_multiply_positive_long(multiplier, unit_seconds, result))
227 return false;
228
229 seconds = result;
230 return true;
231 }
232
233 if(!timeframe_is_ascii_alpha(first))
234 return false;
235
236 int pos = 0;
237 while(pos < len && timeframe_is_ascii_alpha(StringGetCharacter(str, pos)))
238 ++pos;
239
240 string unit = StringSubstr(str, 0, pos);
241 if(pos == len) {
242 if(!timeframe_try_get_unit_seconds_word(unit, unit_seconds))
243 return false;
244 seconds = unit_seconds;
245 return true;
246 }
247
248 if(timeframe_is_ascii_space(StringGetCharacter(str, pos)))
249 return false;
250
251 for(int i = pos; i < len; ++i) {
252 if(!timeframe_is_ascii_digit(StringGetCharacter(str, i)))
253 return false;
254 }
255
256 if(!timeframe_try_get_unit_seconds_compact(unit, unit_seconds))
257 return false;
258 if(!timeframe_try_parse_positive_long(StringSubstr(str, pos), multiplier))
259 return false;
260 if(!timeframe_try_multiply_positive_long(multiplier, unit_seconds, result))
261 return false;
262
263 seconds = result;
264 return true;
265 }
266
273 bool parse_time_zone(string tz_str, TimeZoneStruct &tz)
274 {
275 if(StringLen(tz_str)==0 || tz_str=="Z")
276 {
277 tz.hour=0; tz.min=0; tz.is_positive=true; return true;
278 }
279 tz.is_positive = ((char)tz_str[0] =='+');
280 tz.hour = (int)StringToInteger(StringSubstr(tz_str,1,2));
281 tz.min = (int)StringToInteger(StringSubstr(tz_str,4,2));
282 return is_valid_time_zone(tz);
283 }
284
288 bool parse_tz(string tz_str, TimeZoneStruct &tz) { return parse_time_zone(tz_str, tz); }
289
290//------------------------------------------------------------------------------
291
297 bool parse_iso8601(string input_str, DateTimeStruct &dt, TimeZoneStruct &tz) {
299 tz = create_time_zone_struct(0,0);
300
301 string date_part=input_str;
302 string time_part="";
303 int posT=StringFind(input_str,"T");
304 if (posT<0) posT=StringFind(input_str," ");
305 if (posT>=0) {
306 date_part=StringSubstr(input_str,0,posT);
307 time_part=StringSubstr(input_str,posT+1);
308 }
309
310 string parts[];
311 int cnt = StringSplit(date_part,'-',parts);
312 if (cnt<3) {
313 cnt = StringSplit(date_part,'/',parts);
314 if (cnt<3) cnt = StringSplit(date_part,'.',parts);
315 }
316 if (cnt<3) return false;
317 dt.year=(long)StringToInteger(parts[0]);
318 dt.mon =(int)StringToInteger(parts[1]);
319 dt.day =(int)StringToInteger(parts[2]);
320
321 if(!is_valid_date(dt.year, dt.mon, dt.day))
322 return false;
323
324 if (StringLen(time_part)>0) {
325 string tz_str = "";
326 int zpos = StringFind(time_part,"Z");
327 int ppos = StringFind(time_part,"+");
328 int npos = StringFind(time_part,"-");
329 int tzpos = -1;
330 if (zpos >= 0){ tzpos=zpos; tz_str=StringSubstr(time_part,zpos); }
331 else if(ppos >= 0){ tzpos=ppos; tz_str=StringSubstr(time_part,ppos); }
332 else if(npos > 0){ tzpos=npos; tz_str=StringSubstr(time_part,npos); }
333 if (tzpos >= 0) time_part=StringSubstr(time_part,0,tzpos);
334
335 string tparts[];
336 int tcnt=StringSplit(time_part,':',tparts);
337 if (tcnt < 2)
338 return is_valid_date_time(dt);
339 dt.hour = (int)StringToInteger(tparts[0]);
340 dt.min = (int)StringToInteger(tparts[1]);
341 if (tcnt >= 3) {
342 string sec_part=tparts[2];
343 int dot = StringFind(sec_part, ".");
344 if (dot >= 0) {
345 dt.sec = (int)StringToInteger(StringSubstr(sec_part,0,dot));
346 dt.ms = (int)StringToInteger(StringSubstr(sec_part,dot+1));
347 } else {
348 dt.sec = (int)StringToInteger(sec_part);
349 }
350 }
351 if (StringLen(tz_str)>0) {
352 if (!parse_time_zone(tz_str,tz)) return false;
353 }
354 }
355 return is_valid_date_time(dt);
356 }
357
362 bool str_to_ts(string str, long &ts) {
364 if(!parse_iso8601(str, dt, tz)) return false;
365 ts = to_timestamp(dt) + to_offset(tz);
366 return true;
367 }
368
373 bool str_to_ts_ms(string str, long &ts) {
375 if(!parse_iso8601(str, dt, tz)) return false;
377 return true;
378 }
379
383 bool is_workday(string str) {
384 long ts = 0;
385 if(!str_to_ts(str, ts))
386 return false;
387 return is_workday(ts);
388 }
389
392 bool workday(string str) { return is_workday(str); }
393
397 bool is_workday_ms(string str) {
398 long ts = 0;
399 if(!str_to_ts_ms(str, ts))
400 return false;
401 return is_workday_ms(ts);
402 }
403
406 bool workday_ms(string str) { return is_workday_ms(str); }
407
411 bool is_first_workday_of_month(string str) {
412 long ts = 0;
413 if(!str_to_ts(str, ts))
414 return false;
416 }
417
422 long ts = 0;
423 if(!str_to_ts_ms(str, ts))
424 return false;
426 }
427
432 bool is_within_first_workdays_of_month(string str, int count) {
433 long ts = 0;
434 if(!str_to_ts(str, ts))
435 return false;
437 }
438
443 bool is_within_first_workdays_of_month_ms(string str, int count) {
444 long ts = 0;
445 if(!str_to_ts_ms(str, ts))
446 return false;
448 }
449
453 bool is_last_workday_of_month(string str) {
454 long ts = 0;
455 if(!str_to_ts(str, ts))
456 return false;
458 }
459
464 long ts = 0;
465 if(!str_to_ts_ms(str, ts))
466 return false;
468 }
469
474 bool is_within_last_workdays_of_month(string str, int count) {
475 long ts = 0;
476 if(!str_to_ts(str, ts))
477 return false;
479 }
480
485 bool is_within_last_workdays_of_month_ms(string str, int count) {
486 long ts = 0;
487 if(!str_to_ts_ms(str, ts))
488 return false;
490 }
491
496 long ts = 0;
497 if(!str_to_ts(str, ts))
498 return ERROR_TIMESTAMP;
500 }
501
506 long ts = 0;
507 if(!str_to_ts_ms(str, ts))
508 return ERROR_TIMESTAMP;
510 }
511
515 long end_of_first_workday_month(string str) {
516 long ts = 0;
517 if(!str_to_ts(str, ts))
518 return ERROR_TIMESTAMP;
520 }
521
526 long ts = 0;
527 if(!str_to_ts_ms(str, ts))
528 return ERROR_TIMESTAMP;
530 }
531
536 long ts = 0;
537 if(!str_to_ts(str, ts))
538 return ERROR_TIMESTAMP;
540 }
541
546 long ts = 0;
547 if(!str_to_ts_ms(str, ts))
548 return ERROR_TIMESTAMP;
550 }
551
555 long end_of_last_workday_month(string str) {
556 long ts = 0;
557 if(!str_to_ts(str, ts))
558 return ERROR_TIMESTAMP;
560 }
561
566 long ts = 0;
567 if(!str_to_ts_ms(str, ts))
568 return ERROR_TIMESTAMP;
570 }
571
576 bool str_to_fts(string str, double &ts) {
578 if(!parse_iso8601(str, dt, tz)) return false;
579 ts = to_ftimestamp(dt) + (double)to_offset(tz);
580 return true;
581 }
582
587 long ts(string str) {
588 long v=0;
589 str_to_ts(str,v);
590 return v;
591 }
592
597 long ts_ms(string str) {
598 long v=0;
599 str_to_ts_ms(str,v);
600 return v;
601 }
602
607 double fts(string str) {
608 double v=0.0;
609 str_to_fts(str,v);
610 return v;
611 }
612
613 //--------------------------------------------------------------------------
614
619 bool str_to_timeframe_sec(string str, long &seconds) {
620 return timeframe_try_parse_seconds(str, seconds);
621 }
622
627 bool str_to_timeframe_ms(string str, long &milliseconds) {
628 long seconds = 0;
629 if(!timeframe_try_parse_seconds(str, seconds)) {
630 milliseconds = 0;
631 return false;
632 }
633
634 if(!timeframe_try_multiply_positive_long(seconds, MS_PER_SEC, milliseconds)) {
635 milliseconds = 0;
636 return false;
637 }
638
639 return true;
640 }
641
646 long timeframe_sec(string str) {
647 long value = 0;
648 str_to_timeframe_sec(str, value);
649 return value;
650 }
651
656 long timeframe_ms(string str) {
657 long value = 0;
658 str_to_timeframe_ms(str, value);
659 return value;
660 }
661
662 //--------------------------------------------------------------------------
663
672 int sec_of_day(string str) {
673 string result[];
674 const int k = StringSplit(str, ':', result);
675
676 if (k < 1 || k > 3)
677 return (int)SEC_PER_DAY;
678
679 int h = 0, m = 0, s = 0;
680
681 h = (int)StringToInteger(result[0]);
682 if (k > 1) m = (int)StringToInteger(result[1]);
683 if (k > 2) s = (int)StringToInteger(result[2]);
684
685 if (!is_valid_time(h, m, s)) return (int)SEC_PER_DAY;
686
687 return sec_of_day(h, m, s);
688 }
689
691
692}; // namespace time_shield
693
694#endif // TIME_SHIELD_MQL5_HEADER_TIME_PARSER_MQH_INCLUDED
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 ERROR_TIMESTAMP
Error timestamp value.
constexpr int64_t SEC_PER_YEAR
Seconds per year (365 days)
const int64_t MONTHS_PER_YEAR
Months per year.
constexpr int64_t SEC_PER_HOUR
Seconds per hour.
constexpr int64_t MS_PER_SEC
Milliseconds per second.
Definition constants.hpp:77
constexpr int64_t SEC_PER_DAY
Seconds per day.
constexpr int64_t SEC_PER_MIN
Seconds per minute.
TIME_SHIELD_CONSTEXPR ts_ms_t end_of_last_workday_month_ms(year_t year, int month) noexcept
Returns end-of-day millisecond timestamp for the last workday of month.
TIME_SHIELD_CONSTEXPR bool is_first_workday_of_month_ms(ts_ms_t ts_ms) noexcept
Checks whether millisecond timestamp is the first workday of the month.
TIME_SHIELD_CONSTEXPR ts_t end_of_first_workday_month(year_t year, int month) noexcept
Returns end-of-day timestamp for the first workday of month.
TIME_SHIELD_CONSTEXPR bool is_within_last_workdays_of_month_ms(ts_ms_t ts_ms, int count) noexcept
Checks if millisecond timestamp falls within the last N workdays of the month.
TIME_SHIELD_CONSTEXPR bool is_within_first_workdays_of_month(year_t year, int month, int day, int count) noexcept
Checks if date falls within the first N workdays of the month.
TIME_SHIELD_CONSTEXPR bool workday(ts_t ts) noexcept
Alias for is_workday(ts_t).
TIME_SHIELD_CONSTEXPR ts_ms_t start_of_first_workday_month_ms(year_t year, int month) noexcept
Returns start-of-day millisecond timestamp for the first workday of month.
TIME_SHIELD_CONSTEXPR bool is_within_first_workdays_of_month_ms(ts_ms_t ts_ms, int count) noexcept
Checks if millisecond timestamp falls within the first N workdays of the month.
TIME_SHIELD_CONSTEXPR bool is_last_workday_of_month(year_t year, int month, int day) noexcept
Checks whether date is the last workday of the month.
TIME_SHIELD_CONSTEXPR bool is_first_workday_of_month(year_t year, int month, int day) noexcept
Checks whether date is the first workday of the month.
TIME_SHIELD_CONSTEXPR ts_t end_of_last_workday_month(year_t year, int month) noexcept
Returns end-of-day timestamp for the last workday of month.
TIME_SHIELD_CONSTEXPR bool is_last_workday_of_month_ms(ts_ms_t ts_ms) noexcept
Checks whether millisecond timestamp is the last workday of the month.
TIME_SHIELD_CONSTEXPR bool is_within_last_workdays_of_month(year_t year, int month, int day, int count) noexcept
Checks if date falls within the last N workdays of the month.
TIME_SHIELD_CONSTEXPR ts_ms_t start_of_last_workday_month_ms(year_t year, int month) noexcept
Returns start-of-day millisecond timestamp for the last workday of month.
TIME_SHIELD_CONSTEXPR bool workday_ms(ts_ms_t ts_ms) noexcept
Alias for is_workday(ts_ms_t).
TIME_SHIELD_CONSTEXPR ts_t start_of_last_workday_month(year_t year, int month) noexcept
Returns start-of-day timestamp for the last workday of month.
TIME_SHIELD_CONSTEXPR T1 sec_to_ms(T2 ts) noexcept
Converts a timestamp from seconds to milliseconds.
TIME_SHIELD_CONSTEXPR ts_ms_t end_of_first_workday_month_ms(year_t year, int month) noexcept
Returns end-of-day millisecond timestamp for the first workday of month.
TIME_SHIELD_CONSTEXPR ts_t start_of_first_workday_month(year_t year, int month) noexcept
Returns start-of-day timestamp for the first workday of month.
bool timeframe_try_multiply_positive_long(long lhs, long rhs, long &out)
bool timeframe_is_ascii_alpha(const int ch)
bool parse_iso8601(const char *input, std::size_t length, DateTimeStruct &dt, TimeZoneStruct &tz) noexcept
Parse ISO8601 character buffer into DateTimeStruct and TimeZoneStruct.
bool timeframe_try_parse_positive_long(string value, long &out)
bool str_to_ts_ms(const std::string &str, ts_ms_t &ts)
Convert an ISO8601 string to a millisecond timestamp (ts_ms_t).
bool timeframe_try_parse_seconds(string str, long &seconds)
int timeframe_ascii_to_lower(const int ch)
bool parse_time_zone(const char *data, std::size_t length, TimeZoneStruct &tz) noexcept
Parse timezone character buffer into TimeZoneStruct.
bool timeframe_try_get_unit_seconds_compact(string unit, long &unit_seconds)
bool try_get_month_number(const std::string &month, T &value)
Try get the month number by name, with output parameter.
bool str_to_timeframe_ms(const std::string &str, ts_ms_t &milliseconds) noexcept
Parse timeframe string into fixed milliseconds.
bool timeframe_is_ascii_space(const int ch)
bool timeframe_ascii_iequals(string value, string literal)
bool str_to_timeframe_sec(const std::string &str, ts_t &seconds) noexcept
Parse timeframe string into fixed seconds.
bool timeframe_try_get_unit_seconds_word(string unit, long &unit_seconds)
string timeframe_trim_ascii(string value)
bool parse_tz(const std::string &tz_str, TimeZoneStruct &tz) noexcept
Alias for parse_time_zone.
bool timeframe_is_ascii_digit(const int ch)
T get_month_number(const std::string &month)
Get the month number by name (throwing).
bool str_to_ts(const std::string &str, ts_t &ts)
Convert an ISO8601 string to a timestamp (ts_t).
bool str_to_fts(const std::string &str, fts_t &ts)
Convert an ISO8601 string to a floating-point timestamp (fts_t).
ts_t timeframe_sec(const std::string &str) noexcept
Convert timeframe string to fixed seconds.
ts_ms_t timeframe_ms(const std::string &str) noexcept
Convert timeframe string to fixed milliseconds.
TIME_SHIELD_CONSTEXPR tz_t to_offset(const TimeZoneStruct &tz) noexcept
Alias for time_zone_struct_to_offset.
TIME_SHIELD_CONSTEXPR T month_of_year(ts_t ts) noexcept
Get the month of the year.
TIME_SHIELD_CONSTEXPR 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.
TIME_SHIELD_CONSTEXPR 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.
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.
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_t ts() noexcept
Get the current UTC timestamp in seconds.
ts_ms_t ts_ms() noexcept
Get the current UTC timestamp in milliseconds.
fts_t fts() noexcept
Get the current UTC timestamp in floating-point seconds.
TIME_SHIELD_CONSTEXPR bool is_valid_time_zone(T hour, T min) noexcept
Check if the time zone is valid.
TIME_SHIELD_CONSTEXPR bool is_valid_date(T1 year, T2 month, T2 day) noexcept
Checks the correctness of the specified date.
TIME_SHIELD_CONSTEXPR bool is_valid_time(T1 hour, T1 min, T1 sec, T2 ms=0) noexcept
Checks the correctness of the specified time.
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.
TIME_SHIELD_CONSTEXPR bool is_workday(ts_t ts) noexcept
Check if a given timestamp corresponds to a workday (Monday to Friday).
TIME_SHIELD_CONSTEXPR bool is_workday_ms(ts_ms_t ts_ms) noexcept
Check if a given timestamp in milliseconds corresponds to a workday (Monday to Friday).
Main namespace for the Time Shield library.
TIME_SHIELD_CONSTEXPR T sec_of_day(ts_t ts=time_shield::ts()) noexcept
Get the second of the day.
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.
int hour
Hour component of time (0-23)
int min
Minute component of time (0-59)
bool is_positive
True if the time zone offset is positive, false if negative.
Header with helper functions for converting between different time representations in MQL5.
Header for time zone structure and related functions (MQL5).
Header with validation functions for dates, times, and timestamps.