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
21#include "constants.mqh"
22
23namespace time_shield {
24
27 struct TimeZoneStruct {
28 int hour;
29 int min;
30 bool is_positive;
31 };
32
41 int hour,
42 int min,
43 bool is_positive = true) {
44 TimeZoneStruct result;
45 result.hour = hour;
46 result.min = min;
47 result.is_positive = is_positive;
48 return result;
49 }
50
51 //----------------------------------------------------------------------
52
59 int abs_val = (int)MathAbs(offset);
60 int hour = abs_val / (int)SEC_PER_HOUR;
61 int min = abs_val % (int)SEC_PER_MIN;
62 bool is_positive = (offset >= 0);
63 return create_time_zone_struct(hour, min, is_positive);
64 }
65
68 TimeZoneStruct to_tz(int offset) {
69 return to_time_zone_struct(offset);
70 }
71
72 //----------------------------------------------------------------------
73
79 string time_zone_struct_to_string(const TimeZoneStruct &tz) {
80 string result = tz.is_positive ? "+" : "-";
81 if (tz.hour < 10)
82 result += "0";
83 result += IntegerToString(tz.hour);
84 result += ":";
85 if (tz.min < 10)
86 result += "0";
87 result += IntegerToString(tz.min);
88 return result;
89 }
90
96 string to_string(const TimeZoneStruct &tz) {
98 }
99
105 string to_str(const TimeZoneStruct &tz) {
107 }
108
109 //----------------------------------------------------------------------
110
117 int sign = tz.is_positive ? 1 : -1;
118 return sign * (tz.hour * (int)SEC_PER_HOUR + tz.min * (int)SEC_PER_MIN);
119 }
120
126 int tz_to_offset(const TimeZoneStruct &tz) {
128 }
129
135 int to_offset(const TimeZoneStruct &tz) {
137 }
138
139}; // namespace time_shield
140
141#endif // __TIME_SHIELD_TIME_ZONE_STRUCT_MQH__
Header file with time-related constants.
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 std::string & to_str(Weekday value, FormatType format=UPPERCASE_NAME)
Converts a Weekday enum value to a string.
Definition enums.hpp:69
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 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 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.
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.