Skip to content

Commit 035e381

Browse files
authored
feat(mql5): add enums.mqh with time-related enums and helpers
1 parent d9cfa9b commit 035e381

File tree

1 file changed

+207
-0
lines changed

1 file changed

+207
-0
lines changed

MQL5/Include/time_shield/enums.mqh

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
//+------------------------------------------------------------------+
2+
//| enums.mqh |
3+
//| Time Shield - MQL5 Enumerations |
4+
//| Copyright 2025, NewYaroslav |
5+
//| https://github.com/NewYaroslav/time-shield-cpp |
6+
//+------------------------------------------------------------------+
7+
#ifndef __TIME_SHIELD_ENUMS_MQH__
8+
#define __TIME_SHIELD_ENUMS_MQH__
9+
10+
/// \file enums.mqh
11+
/// \ingroup mql5
12+
/// \brief Header file with enumerations for weekdays, months, and other time-related categories.
13+
///
14+
/// This file contains enum definitions for representing various time-related concepts.
15+
16+
#property copyright "Copyright 2025, NewYaroslav"
17+
#property link "https://github.com/NewYaroslav/time-shield-cpp"
18+
#property strict
19+
20+
namespace time_shield {
21+
22+
/// \defgroup time_enums Time Enumerations
23+
/// \brief Enumerations for time-related concepts.
24+
///
25+
/// This group contains various enums that represent time-related concepts such as
26+
/// weekdays, months, time zones, and formatting options.
27+
///
28+
/// ### Key Features:
29+
/// - Defines enumerations for consistent handling of weekdays, months, and other time units.
30+
/// - Provides utility functions for converting enum values to string representations.
31+
///
32+
/// ### Example Usage:
33+
/// \code
34+
/// Weekday weekday = MON;
35+
/// Print(time_shield::to_str(weekday, FormatType::FULL_NAME)); // "Monday"
36+
/// \endcode
37+
/// \{
38+
39+
/// Enumeration of the format options for representing a weekday or month.
40+
enum FormatType {
41+
UPPERCASE_NAME = 0, ///< Uppercase short name
42+
SHORT_NAME, ///< Short name
43+
FULL_NAME, ///< Full name
44+
};
45+
46+
/// Enumeration of the days of the week.
47+
enum Weekday {
48+
SUN = 0, ///< Sunday
49+
MON, ///< Monday
50+
TUE, ///< Tuesday
51+
WED, ///< Wednesday
52+
THU, ///< Thursday
53+
FRI, ///< Friday
54+
SAT ///< Saturday
55+
};
56+
57+
/// \brief Converts a Weekday enum value to a string.
58+
///
59+
/// \param value The Weekday enum value to convert.
60+
/// \param format The format to use for the string representation (default is UPPERCASE_NAME).
61+
/// \return A string with the representation of the day.
62+
string to_str(Weekday value, FormatType format = UPPERCASE_NAME) {
63+
static const string uppercase_names[] = {
64+
"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"
65+
};
66+
static const string short_names[] = {
67+
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
68+
};
69+
static const string full_names[] = {
70+
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
71+
};
72+
switch(format) {
73+
default:
74+
case UPPERCASE_NAME:
75+
return uppercase_names[(int)value];
76+
case SHORT_NAME:
77+
return short_names[(int)value];
78+
case FULL_NAME:
79+
return full_names[(int)value];
80+
}
81+
return "";
82+
}
83+
84+
85+
/// Enumeration of the months of the year.
86+
enum Month {
87+
JAN = 1, ///< January
88+
FEB, ///< February
89+
MAR, ///< March
90+
APR, ///< April
91+
MAY, ///< May
92+
JUN, ///< June
93+
JUL, ///< July
94+
AUG, ///< August
95+
SEP, ///< September
96+
OCT, ///< October
97+
NOV, ///< November
98+
DEC ///< December
99+
};
100+
101+
/// \brief Converts a Month enum value to a string.
102+
///
103+
/// \param value The Month enum value to convert.
104+
/// \param format The format to use for the string representation (default is UPPERCASE_NAME).
105+
/// \return A string with the representation of the month.
106+
string to_str(Month value, FormatType format = UPPERCASE_NAME) {
107+
static const string uppercase_names[] = {
108+
"",
109+
"JAN", "FEB", "MAR", "APR", "MAY", "JUN",
110+
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
111+
};
112+
static const string short_names[] = {
113+
"",
114+
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
115+
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
116+
};
117+
static const string full_names[] = {
118+
"",
119+
"January", "February", "March", "April", "May", "June",
120+
"July", "August", "September", "October", "November", "December"
121+
};
122+
switch(format) {
123+
default:
124+
case UPPERCASE_NAME:
125+
return uppercase_names[(int)value];
126+
case SHORT_NAME:
127+
return short_names[(int)value];
128+
case FULL_NAME:
129+
return full_names[(int)value];
130+
}
131+
return "";
132+
}
133+
134+
135+
/// Enumeration of the time zones.
136+
enum TimeZone {
137+
GMT, ///< Greenwich Mean Time
138+
UTC, ///< Coordinated Universal Time
139+
EET, ///< Eastern European Time
140+
CET, ///< Central European Time
141+
WET, ///< Western European Time
142+
EEST, ///< Eastern European Summer Time
143+
CEST, ///< Central European Summer Time
144+
WEST, ///< Western European Summer Time
145+
UNKNOWN ///< Unknown Time Zone
146+
};
147+
148+
/// \brief Converts a TimeZone enum value to a string.
149+
///
150+
/// \param value The TimeZone enum value to convert.
151+
/// \param format The format to use for the string representation (default is UPPERCASE_NAME).
152+
/// \return A string with the representation of the time zone.
153+
string to_str(TimeZone value, FormatType format = UPPERCASE_NAME) {
154+
static const string uppercase_names[] = {
155+
"GMT", "UTC", "EET", "CET", "WET", "EEST", "CEST", "WEST", "UNKNOWN"
156+
};
157+
static const string short_names[] = {
158+
"GMT", "UTC", "EET", "CET", "WET", "EEST", "CEST", "WEST", "Unknown"
159+
};
160+
static const string full_names[] = {
161+
"Greenwich Mean Time", "Coordinated Universal Time", "Eastern European Time",
162+
"Central European Time", "Western European Time", "Eastern European Summer Time",
163+
"Central European Summer Time", "Western European Summer Time", "Unknown Time Zone"
164+
};
165+
switch(format) {
166+
default:
167+
case UPPERCASE_NAME:
168+
return uppercase_names[(int)value];
169+
case SHORT_NAME:
170+
return short_names[(int)value];
171+
case FULL_NAME:
172+
return full_names[(int)value];
173+
}
174+
return "";
175+
}
176+
177+
178+
/// Enumeration of the moon phases.
179+
enum MoonPhase {
180+
WAXING_CRESCENT, ///< Waxing Crescent Moon
181+
FIRST_QUARTER, ///< First Quarter Moon
182+
WAXING_GIBBOUS, ///< Waxing Gibbous Moon
183+
FULL_MOON, ///< Full Moon
184+
WANING_GIBBOUS, ///< Waning Gibbous Moon
185+
LAST_QUARTER, ///< Last Quarter Moon
186+
WANING_CRESCENT, ///< Waning Crescent Moon
187+
NEW_MOON ///< New Moon
188+
};
189+
190+
/// Enumeration of time format types.
191+
enum TimeFormatType {
192+
ISO8601_WITH_TZ, ///< ISO8601 format with time zone (e.g., "2024-06-06T12:30:45+03:00")
193+
ISO8601_NO_TZ, ///< ISO8601 format without time zone (e.g., "2024-06-06T12:30:45")
194+
MQL5_FULL, ///< MQL5 time format (e.g., "2024.06.06 12:30:45")
195+
MQL5_DATE_ONLY, ///< MQL5 date format (e.g., "2024.06.06")
196+
MQL5_TIME_ONLY, ///< MQL5 time format (e.g., "12:30:45")
197+
AMERICAN_MONTH_DAY, ///< American date format (e.g., "06/06/2024")
198+
EUROPEAN_MONTH_DAY, ///< European date format (e.g., "06.06.2024")
199+
AMERICAN_TIME, ///< American time format (e.g., "12:30 PM")
200+
EUROPEAN_TIME ///< European time format (e.g., "12:30")
201+
};
202+
203+
/// \}
204+
205+
}; // namespace time_shield
206+
207+
#endif // __TIME_SHIELD_ENUMS_MQH__

0 commit comments

Comments
 (0)