Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
time_zone_struct.mqh
Go to the documentation of this file.
1//+------------------------------------------------------------------+
2//| time_zone_struct.mqh |
3//| Time Shield - MQL5 Time Zone Structure |
4//| Copyright 2025, NewYaroslav |
5//| https://github.com/NewYaroslav/time-shield-cpp |
6//+------------------------------------------------------------------+
7#ifndef __TIME_SHIELD_TIME_ZONE_STRUCT_MQH__
8#define __TIME_SHIELD_TIME_ZONE_STRUCT_MQH__
9
16
17#property copyright "Copyright 2025, NewYaroslav"
18#property link "https://github.com/NewYaroslav/time-shield-cpp"
19#property strict
20
21namespace time_shield {
22
25 struct TimeZoneStruct {
26 int hour;
27 int min;
28 bool is_positive;
29 };
30
37 TimeZoneStruct create_time_zone_struct(
38 const int hour,
39 const int min,
40 const bool is_positive = true) {
41 TimeZoneStruct result;
42 result.hour = hour;
43 result.min = min;
44 result.is_positive = is_positive;
45 return result;
46 }
47
48 //----------------------------------------------------------------------
49
55 TimeZoneStruct to_time_zone_struct(const int offset) {
56 int abs_val = (int)MathAbs(offset);
57 int hour = abs_val / SEC_PER_HOUR;
58 int min = abs_val % SEC_PER_MIN;
59 bool is_positive = (offset >= 0);
60 return create_time_zone_struct(hour, min, is_positive);
61 }
62
67 TimeZoneStruct to_tz(const int offset) {
68 return to_time_zone_struct(offset);
69 }
70
71 //----------------------------------------------------------------------
72
78 string time_zone_struct_to_string(const TimeZoneStruct &tz) {
79 string result = tz.is_positive ? "+" : "-";
80 if (tz.hour < 10)
81 result += "0";
82 result += IntegerToString(tz.hour);
83 result += ":";
84 if (tz.min < 10)
85 result += "0";
86 result += IntegerToString(tz.min);
87 return result;
88 }
89
94 string to_string(const TimeZoneStruct &tz) {
96 }
97
102 string to_str(const TimeZoneStruct &tz) {
104 }
105
106 //----------------------------------------------------------------------
107
113 int time_zone_struct_to_offset(const TimeZoneStruct &tz) {
114 int sign = tz.is_positive ? 1 : -1;
115 return sign * (tz.hour * SEC_PER_HOUR + tz.min * SEC_PER_MIN);
116 }
117
121 int tz_to_offset(const TimeZoneStruct &tz) {
123 }
124
128 int to_offset(const TimeZoneStruct &tz) {
130 }
131
132}; // namespace time_shield
133
134#endif // __TIME_SHIELD_TIME_ZONE_STRUCT_MQH__
constexpr int64_t SEC_PER_HOUR
Seconds per hour.
Definition constants.hpp:69
constexpr int64_t SEC_PER_MIN
Seconds per minute.
Definition constants.hpp:62
const tz_t time_zone_struct_to_offset(const TimeZoneStruct &tz)
Converts a TimeZoneStruct to a single integer representation.
const tz_t tz_to_offset(const TimeZoneStruct &tz)
Alias for time_zone_struct_to_offset function.
const TimeZoneStruct to_tz(tz_t offset)
Alias for to_time_zone_struct function.
const tz_t to_offset(const TimeZoneStruct &tz)
Alias for time_zone_struct_to_offset function.
const TimeZoneStruct to_time_zone_struct(tz_t offset)
Converts an integer to a TimeZoneStruct.
const std::string & to_str(Weekday value, FormatType format=UPPERCASE_NAME)
Converts a Weekday enum value to a string.
Definition enums.hpp:82
const std::string to_string(const std::string &format_str, T timestamp, tz_t utc_offset=0)
Convert timestamp to string with custom format.
const std::string time_zone_struct_to_string(const TimeZoneStruct &tz)
Converts a TimeZoneStruct to a string representation.
const TimeZoneStruct create_time_zone_struct(int hour, int min, bool is_positive=true)
Creates a TimeZoneStruct instance.
Main namespace for the Time Shield library.
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.