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)
102 result += StringFormat(
"%2d ", dt.
day);
103 result += StringFormat(
"%02d:%02d:%02d ", dt.
hour, dt.
min, dt.
sec);
104 result += IntegerToString(dt.
year);
109 result += IntegerToString(dt.
year/100);
117 result += StringFormat(
"%02d/%02d/%02d", dt.
mon, dt.
day, (
int)(dt.
year%100));
118 else if(repeat_count==2)
123 result += StringFormat(
"%2d", dt.
day);
127 result += StringFormat(
"%lld-%02d-%02d", dt.
year, dt.
mon, dt.
day);
135 result += StringFormat(
"%2d", dt.
hour);
144 else if(repeat_count==2)
150 else if(repeat_count==2)
152 else if(repeat_count==3)
159 result += dt.
hour<12?
"AM":
"PM";
162 result += dt.
hour<12?
"am":
"pm";
170 result += StringFormat(
"%02d:%02d", dt.
hour, dt.
min);
174 result += IntegerToString(
ts);
175 else if(repeat_count==3)
176 result += IntegerToString(dt.
ms);
182 result += IntegerToString(dt.
ms);
190 result += StringFormat(
"%02d:%02d:%02d", dt.
hour, dt.
min, dt.
sec);
193 if(repeat_count==1) {
196 result += IntegerToString(dw);
202 else if(repeat_count==3)
211 result += IntegerToString(dt.
year%100);
215 result += IntegerToString(dt.
year);
218 if(repeat_count==1) {
241 if(StringLen(format_str)==0)
return result;
243 bool is_command=
false;
245 char last_char = StringGetChar(format_str,0);
246 if(last_char!=
'%') result+=CharToString(last_char);
247 for(
int i=0;i<StringLen(format_str);++i) {
248 char current_char = StringGetChar(format_str,i);
250 if(current_char==
'%') {
252 if(repeat_count==2) {
259 result += CharToString(current_char);
262 last_char=current_char;
266 if(last_char==current_char) {
296 if(StringLen(format_str)==0)
return result;
298 bool is_command=
false;
300 char last_char = StringGetChar(format_str,0);
301 if(last_char!=
'%') result+=CharToString(last_char);
302 for(
int i=0;i<StringLen(format_str);++i) {
303 char current_char = StringGetChar(format_str,i);
305 if(current_char==
'%') {
307 if(repeat_count==2) {
314 result += CharToString(current_char);
317 last_char=current_char;
321 if(last_char==current_char) {
350 return StringFormat(
"%lld-%02d-%02dT%02d:%02d:%02d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec);
358 return StringFormat(
"%lld-%02d-%02dT%02d:%02d:%02d.%03d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec, dt.
ms);
366 return StringFormat(
"%lld-%02d-%02d", dt.
year, dt.
mon, dt.
day);
374 return StringFormat(
"%02d:%02d:%02d", dt.
hour, dt.
min, dt.
sec);
382 return StringFormat(
"%02d:%02d:%02d.%03d", dt.
hour, dt.
min, dt.
sec, dt.
ms);
428 return StringFormat(
"%lld.%02d.%02d %02d:%02d:%02d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec);
436 return StringFormat(
"%lld.%02d.%02d", dt.
year, dt.
mon, dt.
day);
444 return StringFormat(
"%02d:%02d:%02d", dt.
hour, dt.
min, dt.
sec);
456 return StringFormat(
"%lld-%02d-%02d_%02d-%02d-%02d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec);
464 return StringFormat(
"%lld-%02d-%02d_%02d-%02d-%02d-%03d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec, dt.
ms);
472 return StringFormat(
"%lld-%02d-%02d %02d:%02d:%02d", dt.
year, dt.
mon, dt.
day, dt.
hour, dt.
min, dt.
sec);
480 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.
TIME_SHIELD_CONSTEXPR const ts_t timestamp(T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0)
Alias for to_timestamp function.
TIME_SHIELD_CONSTEXPR const ts_t ts(T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0)
Alias for to_timestamp function.
const T to_time_zone(tz_t offset)
Converts an integer to a time zone structure.
constexpr const T1 day_of_week(T2 year, T3 month, T3 day)
Alias for day_of_week_date function.
TIME_SHIELD_CONSTEXPR const T hour24_to_12(T hour) noexcept
Converts a 24-hour format hour to a 12-hour format.
TIME_SHIELD_CONSTEXPR const ts_ms_t timestamp_ms(T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0, T2 ms=0)
Alias for to_timestamp_ms function.
TIME_SHIELD_CONSTEXPR const ts_ms_t ts_ms(T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0, T2 ms=0)
Alias for to_timestamp_ms function.
const TimeZoneStruct to_time_zone_struct(tz_t offset)
Converts an integer to a TimeZoneStruct.
constexpr const T1 ms_to_sec(T2 ts_ms) noexcept
Converts a timestamp from milliseconds to seconds.
const T day_of_year(ts_t ts=ts())
Get the day of the year.
const std::string & to_str(Weekday value, FormatType format=UPPERCASE_NAME)
Converts a Weekday enum value to a string.
Month
Enumeration of the months of the year.
@ UPPERCASE_NAME
Uppercase short name.
T to_date_time_ms(ts_ms_t ts)
Converts a timestamp in milliseconds to a date-time structure with milliseconds.
T1 to_date_time(T2 ts)
Converts a timestamp to a date-time structure.
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).