Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
time_zone_conversions.mqh
Go to the documentation of this file.
1//+------------------------------------------------------------------+
2//| time_zone_conversions.mqh |
3//| Time Shield - MQL5 Time Zone Conversions |
4//| Copyright 2025, NewYaroslav |
5//| https://github.com/NewYaroslav/time-shield-cpp |
6//+------------------------------------------------------------------+
7#ifndef __TIME_SHIELD_TIME_ZONE_CONVERSIONS_MQH__
8#define __TIME_SHIELD_TIME_ZONE_CONVERSIONS_MQH__
9
13
14#property copyright "Copyright 2025, NewYaroslav"
15#property link "https://github.com/NewYaroslav/time-shield-cpp"
16#property strict
17
19
20namespace time_shield {
21
26 datetime cet_to_gmt(const datetime cet) {
28 int max_days = num_days_in_month(dt.year, dt.mon);
29 const int OLD_START_SUMMER_HOUR = 2;
30 const int OLD_STOP_SUMMER_HOUR = 3;
31 const int NEW_SUMMER_HOUR = 1;
32
33 if(dt.year < 2002) {
34 if(dt.mon > MAR && dt.mon < OCT)
35 return cet - SEC_PER_HOUR * 2;
36 else
37 if(dt.mon == MAR) {
38 for(int d = max_days; d >= dt.day; d--) {
39 if(day_of_week_date(dt.year, MAR, d) == SUN) {
40 if(d == dt.day) {
41 if(dt.hour >= OLD_START_SUMMER_HOUR)
42 return cet - SEC_PER_HOUR * 2;
43 return cet - SEC_PER_HOUR;
44 }
45 return cet - SEC_PER_HOUR;
46 }
47 }
48 return cet - SEC_PER_HOUR * 2;
49 } else
50 if(dt.mon == OCT) {
51 for(int d = max_days; d >= dt.day; d--) {
52 if(day_of_week_date(dt.year, OCT, d) == SUN) {
53 if(d == dt.day) {
54 if(dt.hour >= OLD_STOP_SUMMER_HOUR)
55 return cet - SEC_PER_HOUR;
56 return cet - SEC_PER_HOUR;
57 }
58 return cet - SEC_PER_HOUR * 2;
59 }
60 }
61 return cet - SEC_PER_HOUR;
62 }
63 return cet - SEC_PER_HOUR;
64 } else {
65 if(dt.mon > MAR && dt.mon < OCT)
66 return cet - SEC_PER_HOUR * 2;
67 else
68 if(dt.mon == MAR) {
69 for(int d = max_days; d >= dt.day; d--) {
70 if(day_of_week_date(dt.year, MAR, d) == SUN) {
71 if(d == dt.day) {
72 if(dt.hour >= (NEW_SUMMER_HOUR + 2))
73 return cet - SEC_PER_HOUR * 2;
74 return cet - SEC_PER_HOUR;
75 }
76 return cet - SEC_PER_HOUR;
77 }
78 }
79 return cet - SEC_PER_HOUR * 2;
80 } else
81 if(dt.mon == OCT) {
82 for(int d = max_days; d >= dt.day; d--) {
83 if(day_of_week_date(dt.year, OCT, d) == SUN) {
84 if(d == dt.day) {
85 if(dt.hour >= (NEW_SUMMER_HOUR + 1))
86 return cet - SEC_PER_HOUR;
87 return cet - SEC_PER_HOUR * 2;
88 }
89 return cet - SEC_PER_HOUR * 2;
90 }
91 }
92 return cet - SEC_PER_HOUR;
93 }
94 return cet - SEC_PER_HOUR;
95 }
96 return cet - SEC_PER_HOUR;
97 }
98
103 datetime eet_to_gmt(const datetime eet) {
104 return cet_to_gmt(eet - SEC_PER_HOUR);
105 }
106
107}; // namespace time_shield
108
109#endif // __TIME_SHIELD_TIME_ZONE_CONVERSIONS_MQH__
constexpr int64_t SEC_PER_HOUR
Seconds per hour.
Definition constants.hpp:69
constexpr const T1 num_days_in_month(T2 year, T3 month) noexcept
Get the number of days in a month.
const ts_t eet_to_gmt(ts_t eet)
Convert Eastern European Time to Greenwich Mean Time.
const ts_t cet_to_gmt(ts_t cet)
Convert Central European Time to Greenwich Mean Time.
constexpr const T1 day_of_week_date(T2 year, T3 month, T3 day)
Get the day of the week.
@ OCT
October.
Definition enums.hpp:114
@ MAR
March.
Definition enums.hpp:107
@ SUN
Sunday.
Definition enums.hpp:42
T1 to_date_time(T2 ts)
Converts a timestamp to a date-time structure.
Main namespace for the Time Shield library.
Structure to represent date and time.
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 mon
Month component of the date (1-12).
Header with helper functions for converting between different time representations in MQL5.