7#ifndef __TIME_SHIELD_TIME_FORMATTING_MQH__
8#define __TIME_SHIELD_TIME_FORMATTING_MQH__
18#property copyright "Copyright 2025, NewYaroslav"
19#property link "https://github.com/NewYaroslav/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) {
295 if(StringLen(format_str)==0)
return result;
297 bool is_command=
false;
299 char last_char = (char)format_str[0];
300 if(last_char!=
'%') result+=CharToString(last_char);
301 for(
int i=0;i<StringLen(format_str);++i) {
302 char current_char = (char)format_str[i];
304 if(current_char==
'%') {
306 if(repeat_count==2) {
313 result += CharToString(current_char);
316 last_char=current_char;
320 if(last_char==current_char) {
349 return StringFormat(
"%lld-%02d-%02dT%02d:%02d:%02d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec);
357 return StringFormat(
"%lld-%02d-%02dT%02d:%02d:%02d.%03d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec, dt.
ms);
365 return StringFormat(
"%lld-%02d-%02d", dt.
year, dt.
mon, dt.
day);
373 return StringFormat(
"%02d:%02d:%02d", dt.
hour, dt.
min, dt.
sec);
381 return StringFormat(
"%02d:%02d:%02d.%03d", dt.
hour, dt.
min, dt.
sec, dt.
ms);
427 return StringFormat(
"%lld.%02d.%02d %02d:%02d:%02d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec);
435 return StringFormat(
"%lld.%02d.%02d", dt.
year, dt.
mon, dt.
day);
443 return StringFormat(
"%02d:%02d:%02d", dt.
hour, dt.
min, dt.
sec);
455 return StringFormat(
"%lld-%02d-%02d_%02d-%02d-%02d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec);
463 return StringFormat(
"%lld-%02d-%02d_%02d-%02d-%02d-%03d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec, dt.
ms);
471 return StringFormat(
"%lld-%02d-%02d %02d:%02d:%02d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec);
479 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 ts_t timestamp(year_t year, int month, int day)
Alias for to_timestamp.
const T to_time_zone(tz_t offset)
Converts an integer to a time zone structure.
T to_date_time_ms(ts_ms_t ts)
Converts a timestamp in milliseconds to a date-time structure with milliseconds.
constexpr ts_ms_t timestamp_ms(year_t year, int month, int day)
Alias for to_timestamp_ms.
TIME_SHIELD_CONSTEXPR ts_t ts(year_t year, int month, int day)
Alias for to_timestamp.
constexpr const T1 day_of_week(year_t year, int month, int day)
Alias for day_of_week_date.
TIME_SHIELD_CONSTEXPR const T hour24_to_12(T hour) noexcept
Converts a 24-hour format hour to a 12-hour format.
constexpr ts_ms_t ts_ms(year_t year, int month, int day)
Alias for to_timestamp_ms.
T1 to_date_time(T2 ts)
Converts a timestamp to a date-time structure.
const T day_of_year(ts_t ts=time_shield::ts())
Get the day of the year.
constexpr const T1 ms_to_sec(T2 ts_ms) noexcept
Converts a timestamp from milliseconds to seconds.
const std::string & to_str(Weekday value, FormatType format=UPPERCASE_NAME)
Converts a Weekday enum value to a string.
const TimeZoneStruct to_time_zone_struct(tz_t offset)
Converts an integer to a TimeZoneStruct.
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).