7#ifndef TIME_SHIELD_MQL5_HEADER_TIME_FORMATTING_MQH_INCLUDED
8#define TIME_SHIELD_MQL5_HEADER_TIME_FORMATTING_MQH_INCLUDED
18#property copyright "Copyright 2025, NewYaroslav"
19#property link "https://github.com/LimiNode/time-shield-cpp"
38 string s = IntegerToString(value);
39 while(StringLen(s) < width)
101 result += StringFormat(
"%2d ", dt.
day);
102 result += StringFormat(
"%02d:%02d:%02d ", dt.
hour, dt.
min, dt.
sec);
103 result += IntegerToString(dt.
year);
108 result += IntegerToString(dt.
year/100);
116 result += StringFormat(
"%02d/%02d/%02d", dt.
mon, dt.
day, (
int)(dt.
year%100));
117 else if(repeat_count==2)
122 result += StringFormat(
"%2d", dt.
day);
126 result += StringFormat(
"%lld-%02d-%02d", dt.
year, dt.
mon, dt.
day);
134 result += StringFormat(
"%2d", dt.
hour);
143 else if(repeat_count==2)
149 else if(repeat_count==2)
151 else if(repeat_count==3)
158 result += dt.
hour<12?
"AM":
"PM";
161 result += dt.
hour<12?
"am":
"pm";
169 result += StringFormat(
"%02d:%02d", dt.
hour, dt.
min);
173 result += IntegerToString(
ts);
174 else if(repeat_count==3)
175 result += IntegerToString(dt.
ms);
181 result += IntegerToString(dt.
ms);
189 result += StringFormat(
"%02d:%02d:%02d", dt.
hour, dt.
min, dt.
sec);
192 if(repeat_count==1) {
195 result += IntegerToString(dw);
201 else if(repeat_count==3)
210 result += IntegerToString(dt.
year%100);
214 result += IntegerToString(dt.
year);
217 if(repeat_count==1) {
240 if(StringLen(format_str)==0)
return result;
242 bool is_command=
false;
244 char last_char = (char)format_str[0];
245 if(last_char!=
'%') result+=CharToString(last_char);
246 for(
int i=0;i<StringLen(format_str);++i) {
247 char current_char = (char)format_str[i];
249 if(current_char==
'%') {
251 if(repeat_count==2) {
258 result += CharToString(current_char);
261 last_char=current_char;
265 if(last_char==current_char) {
297 if(StringLen(format_str)==0)
return result;
299 bool is_command=
false;
301 char last_char = (char)format_str[0];
302 if(last_char!=
'%') result+=CharToString(last_char);
303 for(
int i=0;i<StringLen(format_str);++i) {
304 char current_char = (char)format_str[i];
306 if(current_char==
'%') {
308 if(repeat_count==2) {
315 result += CharToString(current_char);
318 last_char=current_char;
322 if(last_char==current_char) {
353 return StringFormat(
"%lld-%02d-%02dT%02d:%02d:%02d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec);
361 return StringFormat(
"%lld-%02d-%02dT%02d:%02d:%02d.%03d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec, dt.
ms);
369 return StringFormat(
"%lld-%02d-%02d", dt.
year, dt.
mon, dt.
day);
377 return StringFormat(
"%02d:%02d:%02d", dt.
hour, dt.
min, dt.
sec);
385 return StringFormat(
"%02d:%02d:%02d.%03d", dt.
hour, dt.
min, dt.
sec, dt.
ms);
431 return StringFormat(
"%lld.%02d.%02d %02d:%02d:%02d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec);
439 return StringFormat(
"%lld.%02d.%02d", dt.
year, dt.
mon, dt.
day);
447 return StringFormat(
"%02d:%02d:%02d", dt.
hour, dt.
min, dt.
sec);
459 return StringFormat(
"%lld-%02d-%02d_%02d-%02d-%02d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec);
467 return StringFormat(
"%lld-%02d-%02d_%02d-%02d-%02d-%03d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec, dt.
ms);
475 return StringFormat(
"%lld-%02d-%02d %02d:%02d:%02d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec);
483 return StringFormat(
"%lld-%02d-%02d %02d:%02d:%02d.%03d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec, dt.
ms);
Header for date and time structure and related functions (MQL5).
Header file with enumerations for weekdays, months, and other time-related categories.
@ UPPERCASE_NAME
Uppercase short name.
TIME_SHIELD_CONSTEXPR T1 ms_to_sec(T2 ts_ms) noexcept
Converts a timestamp from milliseconds to seconds.
TIME_SHIELD_CONSTEXPR T hour24_to_12(T hour) noexcept
Converts a 24-hour format hour to a 12-hour format.
T to_time_zone(tz_t offset)
Converts an integer to a time zone structure.
TIME_SHIELD_CONSTEXPR T1 day_of_week(year_t year, int month, int day)
Alias for day_of_week_date.
const std::string & to_str(Weekday value, FormatType format=UPPERCASE_NAME)
Converts a Weekday enum value to a string.
TimeZoneStruct to_time_zone_struct(tz_t offset)
Converts an integer to a TimeZoneStruct.
T to_date_time_ms(ts_ms_t ts)
Converts a timestamp in milliseconds to a date-time structure with milliseconds.
T day_of_year(ts_t ts=time_shield::ts())
Get the day of the year.
T1 to_date_time(T2 ts)
Converts a timestamp to a date-time structure.
ts_t ts() noexcept
Get the current UTC timestamp in seconds.
ts_t timestamp() noexcept
Get the current UTC timestamp in seconds.
ts_ms_t ts_ms() noexcept
Get the current UTC timestamp in milliseconds.
ts_ms_t timestamp_ms() noexcept
Get the current UTC timestamp in milliseconds.
Main namespace for the Time Shield library.
Structure to represent date and time.
int ms
Millisecond component of time (0-999)
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 min
Minute component of time (0-59)
int mon
Month component of the date (1-12).
int sec
Second component of time (0-59)
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.
Header with helper functions for converting between different time representations in MQL5.
Header for time zone structure and related functions (MQL5).