Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
time_conversions_demo.mq5
Go to the documentation of this file.
1//+------------------------------------------------------------------+
2//| time_conversions_demo.mq5 |
3//| Time Shield - Conversions 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 double sec = 123.456;
16 Print("ns_of_sec: ", time_shield::ns_of_sec(sec));
17 Print("us_of_sec: ", time_shield::us_of_sec(sec));
18 Print("ms_of_sec: ", time_shield::ms_of_sec(sec));
19
20 long ms = time_shield::sec_to_ms(sec);
21 Print("sec_to_ms: ", ms);
22 Print("ms_to_sec: ", time_shield::ms_to_sec(ms));
23 Print("ms_to_fsec: ", DoubleToString(time_shield::ms_to_fsec(ms), 3));
24
25 Print("min_to_sec(2.5): ", time_shield::min_to_sec(2.5));
26 Print("sec_to_min(150): ", time_shield::sec_to_min(150));
27
28 Print("hour_to_ms(1.5): ", time_shield::hour_to_ms(1.5));
29 Print("hour24_to_12(15): ", time_shield::hour24_to_12(15));
30
31 datetime ts = (datetime)time_shield::to_ts(2024, time_shield::JUN, 21, 14, 30, 0);
32 long ts_ms = time_shield::to_ts_ms(2024, time_shield::JUN, 21, 14, 30, 0, 250);
33
34 time_shield::DateTimeStruct dt = time_shield::to_dt_ms(ts_ms);
35 Print("to_dt_ms: ", dt.year, "-", dt.mon, "-", dt.day, " ", dt.hour, ":", dt.min, ":", dt.sec, ".", dt.ms);
36
37 Print("start_of_day: ", time_shield::start_of_day(ts));
38 Print("end_of_day_ms: ", time_shield::end_of_day_ms(ts_ms));
39 Print("next_day_ms: ", time_shield::next_day_ms(ts_ms));
40
41 Print("day_of_year: ", time_shield::day_of_year(ts));
42 Print("month_of_year: ", time_shield::month_of_year(ts));
43 Print("day_of_month: ", time_shield::day_of_month(ts));
44 Print("start_of_year_date(2024): ", time_shield::start_of_year_date(2024));
45 Print("day_of_week_date(2024, JUN, 21): ", time_shield::day_of_week_date(2024, time_shield::JUN, 21));
46}