Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
time_parser_demo.mq5
Go to the documentation of this file.
1//+------------------------------------------------------------------+
2//| time_parser_demo.mq5 |
3//| Time Shield - Parsing Examples |
4//| Copyright 2025, NewYaroslav |
5//| https://github.com/NewYaroslav/time-shield-cpp |
6//+------------------------------------------------------------------+
7#property script_show_inputs
8#property strict
9
10#include <TimeShield.mqh>
11
12void OnStart() {
13 time_shield::init();
14
15 string iso = "2024-11-25T14:30:00+01:00";
16
17 datetime ts;
18 if (time_shield::str_to_ts(iso, ts))
19 Print("ts: ", ts, " -> ", time_shield::to_iso8601(ts));
20 else
21 Print("Failed to parse: ", iso);
22
23 long ts_ms;
24 if (time_shield::str_to_ts_ms(iso, ts_ms))
25 Print("ts_ms: ", ts_ms);
26
27 double fts_val;
28 if (time_shield::str_to_fts(iso, fts_val))
29 Print("fts: ", DoubleToString(fts_val, 2));
30
31 time_shield::DateTimeStruct dt;
32 time_shield::TimeZoneStruct tz;
33 if (time_shield::parse_iso8601(iso, dt, tz)) {
34 string sign = tz.is_positive ? "+" : "-";
35 Print("dt: ", dt.year, "-", dt.mon, "-", dt.day, " ", dt.hour, ":", dt.min, ":", dt.sec, ".", dt.ms,
36 " TZ ", sign, tz.hour, ":", tz.min);
37 }
38
39 int mon = time_shield::get_month_number("March");
40 Print("Month number for March: ", mon);
41
42 int sod = time_shield::sec_of_day("15:30:10");
43 Print("sec_of_day('15:30:10'): ", sod);
44 Print("sec_of_day('8:20'): ", time_shield::sec_of_day("8:20"));
45
46 datetime direct = (datetime)time_shield::ts("2024-01-01T00:00:00Z");
47 Print("ts() shortcut: ", direct);
48}