Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
time_formatting.hpp
Go to the documentation of this file.
1#pragma once
8#ifndef _TIME_SHIELD_TIME_FORMATTING_HPP_INCLUDED
9#define _TIME_SHIELD_TIME_FORMATTING_HPP_INCLUDED
10
11#include "date_time_struct.hpp"
12#include "time_zone_struct.hpp"
13#include "time_conversions.hpp"
14
15namespace time_shield {
16
47
49 char last_char,
50 size_t repeat_count,
51 ts_t ts,
52 tz_t utc_offset,
53 const DateTimeStruct& dt,
54 std::string& result) {
55 switch (last_char) {
56 case 'a':
57 if (repeat_count > 1) break;
58 result += to_str(day_of_week(dt.year, dt.mon, dt.day), FormatType::SHORT_NAME);
59 break;
60 case 'A':
61 if (repeat_count > 1) break;
62 result += to_str(day_of_week(dt.year, dt.mon, dt.day), FormatType::FULL_NAME);
63 break;
64 case 'I':
65 if (repeat_count == 1) {
66 char buffer[4] = {0};
67 snprintf(buffer, sizeof(buffer), "%.2d", hour24_to_12(dt.hour));
68 result += std::string(buffer);
69 }
70 break;
71 case 'H':
72 if (repeat_count <= 2) {
73 char buffer[4] = {0};
74 snprintf(buffer, sizeof(buffer),"%.2d", dt.hour);
75 result += std::string(buffer);
76 }
77 break;
78 case 'h':
79 if (repeat_count == 2) {
80 char buffer[4] = {0};
81 snprintf(buffer, sizeof(buffer),"%.2d", dt.hour);
82 result += std::string(buffer);
83 break;
84 }
85 // %h: Equivalent to %b
86 case 'b':
87 if (repeat_count > 1) break;
88 result += to_str(static_cast<Month>(dt.mon), FormatType::SHORT_NAME);
89 break;
90 case 'B':
91 if (repeat_count > 1) break;
92 result += to_str(static_cast<Month>(dt.mon), FormatType::FULL_NAME);
93 break;
94 case 'c':
95 // Preferred date and time representation for the current locale.
96 // %a %b %e %H:%M:%S %Y
97 if (repeat_count <= 1){
98 char buffer[16];
99 result += to_str(day_of_week(dt.year, dt.mon, dt.day), FormatType::SHORT_NAME);
100 result += " ";
101 result += to_str(static_cast<Month>(dt.mon), FormatType::SHORT_NAME);
102 result += " ";
103 // added %e
104 std::fill(buffer, buffer + sizeof(buffer), '\0');
105 snprintf(buffer, sizeof(buffer),"%2d ", dt.day);
106 result += std::string(buffer);
107 // added %H:%M:%S
108 std::fill(buffer, buffer + sizeof(buffer), '\0');
109 snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2d ", dt.hour, dt.min, dt.sec);
110 result += std::string(buffer);
111 // added %Y
112 result += std::to_string(dt.year);
113 }
114 break;
115 case 'C':
116 if (repeat_count > 1) break;
117 result += std::to_string(dt.year/100);
118 break;
119 case 'd':
120 if (repeat_count < 2) {
121 char buffer[4] = {0};
122 snprintf(buffer, sizeof(buffer),"%.2d", dt.day);
123 result += std::string(buffer);
124 }
125 break;
126 case 'D':
127 if (repeat_count == 1) {
128 // %m/%d/%y
129 char buffer[16] = {0};
130 snprintf(buffer, sizeof(buffer), "%.2d/%.2d/%.2d", dt.mon, dt.day, (int)(dt.year % 100LL));
131 result += std::string(buffer);
132 } else
133 if (repeat_count == 2) {
134 char buffer[4] = {0};
135 snprintf(buffer, sizeof(buffer),"%.2d", dt.day);
136 result += std::string(buffer);
137 }
138 break;
139 case 'e':
140 if (repeat_count == 1) {
141 char buffer[4] = {0};
142 snprintf(buffer, sizeof(buffer),"%2d", dt.day);
143 result += std::string(buffer);
144 }
145 break;
146 case 'E':
147 // %E: Modifier for alternative ("era-based") format.
148 // https://help.hcltechsw.com/onedb/1.0.0.1/gug/ids_gug_086.html#ids_gug_086
149 break;
150 case 'F':
151 if (repeat_count == 1) {
152 // %Y-%m-%d ISO 8601 date format
153 char buffer[32] = {0};
154 if (dt.year <= 9999 || dt.year >= 0) {
155 snprintf(buffer, sizeof(buffer), "%.4d-%.2d-%.2d", (int)dt.year, dt.mon, dt.day);
156 } else
157 if (dt.year < 0) {
158 snprintf(buffer, sizeof(buffer), "-%lld-%.2d-%.2d", dt.year, dt.mon, dt.day);
159 } else {
160 snprintf(buffer, sizeof(buffer), "+%lld-%.2d-%.2d", dt.year, dt.mon, dt.day);
161 }
162 result += std::string(buffer);
163 }
164 case 'g':
165 // ISO 8601 week-based year without century (2-digit year).
166 break;
167 case 'G':
168 // ISO 8601 week-based year with century as a decimal number.
169 break;
170 case 'j':
171 if (repeat_count == 1) {
172 char buffer[4] = {0};
173 snprintf(buffer, sizeof(buffer), "%.3d", day_of_year(ts));
174 result += std::string(buffer);
175 }
176 break;
177 case 'k':
178 if (repeat_count == 1) {
179 char buffer[4] = {0};
180 snprintf(buffer, sizeof(buffer), "%2d", dt.hour);
181 result += std::string(buffer);
182 }
183 break;
184 case 'l':
185 if (repeat_count == 1) {
186 char buffer[4] = {0};
187 snprintf(buffer, sizeof(buffer), "%2d", hour24_to_12(dt.hour));
188 result += std::string(buffer);
189 }
190 break;
191 case 'm':
192 if (repeat_count == 1) {
193 char buffer[4] = {0};
194 snprintf(buffer, sizeof(buffer), "%.2d", dt.mon);
195 result += std::string(buffer);
196 } else
197 if (repeat_count == 2) {
198 char buffer[4] = {0};
199 snprintf(buffer, sizeof(buffer), "%.2d", dt.min);
200 result += std::string(buffer);
201 }
202 break;
203 case 'M':
204 if (repeat_count == 1) {
205 char buffer[4] = {0};
206 snprintf(buffer, sizeof(buffer), "%.2d", dt.min);
207 result += std::string(buffer);
208 } else
209 if (repeat_count == 2) {
210 char buffer[4] = {0};
211 snprintf(buffer, sizeof(buffer), "%.2d", dt.mon);
212 result += std::string(buffer);
213 } else
214 if (repeat_count == 3) {
215 result += to_str(static_cast<Month>(dt.mon), FormatType::UPPERCASE_NAME);
216 }
217 break;
218 case 'n':
219 result += "\n";
220 break;
221 case 'O':
222 // Modifier for using alternative numeric symbols.
223 break;
224 case 'p':
225 if (dt.hour < 12) result += "AM";
226 else result += "PM";
227 break;
228 case 'P':
229 if (dt.hour < 12) result += "am";
230 else result += "pm";
231 break;
232 case 'r':
233 if (repeat_count == 1) {
234 char buffer[16] = {0};
235 if (dt.hour < 12) snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2d AM", hour24_to_12(dt.hour), dt.min, dt.sec);
236 else snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2d PM", hour24_to_12(dt.hour), dt.min, dt.sec);
237 result += std::string(buffer);
238 break;
239 }
240 break;
241 case 'R':
242 // %H:%M
243 if (repeat_count == 1) {
244 char buffer[8] = {0};
245 snprintf(buffer, sizeof(buffer), "%.2d:%.2d", dt.hour, dt.min);
246 result += std::string(buffer);
247 }
248 break;
249 case 's':
250 if (repeat_count == 1) {
251 result += std::to_string(ts);
252 break;
253 }
254 if (repeat_count == 3) {
255 result += std::to_string(dt.ms);
256 break;
257 }
258 // to '%ss'
259 case 'S':
260 if (repeat_count <= 2) {
261 char buffer[4] = {0};
262 snprintf(buffer, sizeof(buffer), "%.2d", dt.sec);
263 result += std::string(buffer);
264 }
265 if (repeat_count == 3) {
266 result += std::to_string(dt.ms);
267 break;
268 }
269 break;
270 case 't':
271 if (repeat_count > 1) break;
272 result += "\t";
273 break;
274 case 'T':
275 // %H:%M:%S
276 if (repeat_count == 1) {
277 char buffer[16] = {0};
278 snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2d", dt.hour, dt.min, dt.sec);
279 result += std::string(buffer);
280 }
281 break;
282 case 'u':
283 if (repeat_count == 1) {
284 // Day of the week as a decimal number (1 to 7, Monday being 1).
285 int dw = day_of_week(dt.year, dt.mon, dt.day);
286 if (dw == 0) dw = 7;
287 result += std::to_string(dw);
288 }
289 break;
290 case 'U':
291 // Week number of the current year (00 to 53, starting with the first Sunday as week 01).
292 break;
293 case 'V':
294 // ISO 8601 week number of the current year (01 to 53, with specific rules).
295 break;
296 case 'w':
297 // Day of the week as a decimal number (0 to 6, Sunday being 0).
298 if (repeat_count == 1) {
299 result += std::to_string(day_of_week(dt.year, dt.mon, dt.day));
300 } else
301 if (repeat_count == 3) {
302 result += to_str(day_of_week(dt.year, dt.mon, dt.day), FormatType::SHORT_NAME);
303 }
304 break;
305 case 'W':
306 // Week number of the current year (00 to 53, starting with the first Monday as week 01).
307 if (repeat_count == 3) {
309 }
310 break;
311 case 'x':
312 // Preferred date representation for the current locale without the time.
313 break;
314 case 'X':
315 // Preferred time representation for the current locale without the date.
316 break;
317 case 'y':
318 if (repeat_count == 1) {
319 result += std::to_string(dt.year % 100);
320 }
321 break;
322 case 'Y':
323 if (repeat_count == 1) {
324 result += std::to_string(dt.year);
325 } else
326 if (repeat_count == 6) {
327 char buffer[32] = {0};
328 const int64_t mega_years = dt.year / 1000000;
329 const int64_t millennia = (dt.year - mega_years * 1000000) / 1000;
330 const int64_t centuries = dt.year - mega_years * 1000000 - millennia * 1000;
331 if (mega_years) {
332 if (millennia) {
333 snprintf(buffer, sizeof(buffer), "%lldM%lldK%.3lld", mega_years, std::abs(millennia), std::abs(centuries));
334 } else {
335 snprintf(buffer, sizeof(buffer), "%lldM%.3lld", mega_years, std::abs(centuries));
336 }
337 } else
338 if (millennia) {
339 snprintf(buffer, sizeof(buffer), "%lldK%.3lld", millennia, std::abs(centuries));
340 } else {
341 snprintf(buffer, sizeof(buffer), "%.4lld", dt.year);
342 }
343 result += std::string(buffer);
344 } else
345 if (repeat_count == 4) {
346 char buffer[8] = {0};
347 snprintf(buffer, sizeof(buffer), "%.4d", (int)(dt.year % 10000));
348 result += std::string(buffer);
349 } else
350 if (repeat_count == 2) {
351 char buffer[8] = {0};
352 snprintf(buffer, sizeof(buffer), "%.2d", (int)(dt.year % 100));
353 result += std::string(buffer);
354 }
355 break;
356 case 'z':
357 // +hhmm or -hhmm numeric timezone offset from UTC.
358 if (repeat_count == 1) {
359 TimeZoneStruct tz = to_time_zone_struct(utc_offset);
360 char buffer[16] = {0};
361 if (tz.is_positive) snprintf(buffer, sizeof(buffer), "+%.2d%.2d", tz.hour, tz.min);
362 else snprintf(buffer, sizeof(buffer), "-%.2d%.2d", tz.hour, tz.min);
363 result += std::string(buffer);
364 }
365 break;
366 case 'Z':
367 // Timezone name or abbreviation.
368
369 result += "UTC";
370 break;
371 case '+':
372 // Date and time in date(1) format (not supported in glibc2).
373 // Tue Jun 4 04:07:43 UTC 2024
374 break;
375 };
376 }
377
404 template<class T = ts_t>
405 const std::string to_string(
406 const std::string& format_str,
407 T timestamp,
408 tz_t utc_offset = 0) {
409 std::string result;
410 if (format_str.empty()) return result;
412
413 bool is_command = false;
414 size_t repeat_count = 0;
415 char last_char = format_str[0];
416 if (last_char != '%') result += last_char;
417 for (size_t i = 0; i < format_str.size(); ++i) {
418 const char& current_char = format_str[i];
419 if (!is_command) {
420 if (current_char == '%') {
421 ++repeat_count;
422 if (repeat_count == 2) {
423 result += current_char;
424 repeat_count = 0;
425 }
426 continue;
427 }
428 if (!repeat_count) {
429 result += current_char;
430 continue;
431 }
432 last_char = current_char;
433 is_command = true;
434 continue;
435 }
436 if (last_char == current_char) {
437 ++repeat_count;
438 continue;
439 }
440 process_format_impl(last_char, repeat_count, timestamp, utc_offset, dt, result);
441 repeat_count = 0;
442 is_command = false;
443 --i;
444 }
445 if (is_command) {
446 process_format_impl(last_char, repeat_count, timestamp, utc_offset, dt, result);
447 }
448 return result;
449 }
450
453 template<class T = ts_t>
454 inline const std::string to_str(
455 const std::string& format_str,
456 T timestamp,
457 tz_t utc_offset = 0) {
458 return to_string<T>(format_str, timestamp, utc_offset);
459 }
460
487 template<class T = ts_ms_t>
488 const std::string to_string_ms(
489 const std::string& format_str,
490 T timestamp,
491 tz_t utc_offset = 0) {
492 std::string result;
493 if (format_str.empty()) return result;
495
496 bool is_command = false;
497 size_t repeat_count = 0;
498 char last_char = format_str[0];
499 if (last_char != '%') result += last_char;
500 for (size_t i = 0; i < format_str.size(); ++i) {
501 const char& current_char = format_str[i];
502 if (!is_command) {
503 if (current_char == '%') {
504 ++repeat_count;
505 if (repeat_count == 2) {
506 result += current_char;
507 repeat_count = 0;
508 }
509 continue;
510 }
511 if (!repeat_count) {
512 result += current_char;
513 continue;
514 }
515 last_char = current_char;
516 is_command = true;
517 continue;
518 }
519 if (last_char == current_char) {
520 ++repeat_count;
521 continue;
522 }
523 process_format_impl(last_char, repeat_count, timestamp, utc_offset, dt, result);
524 repeat_count = 0;
525 is_command = false;
526 --i;
527 }
528 if (is_command) {
529 process_format_impl(last_char, repeat_count, timestamp, utc_offset, dt, result);
530 }
531 return result;
532 }
533
536 template<class T = ts_t>
537 inline const std::string to_str_ms(
538 const std::string& format_str,
539 T timestamp,
540 tz_t utc_offset = 0) {
541 return to_string_ms<T>(format_str, timestamp, utc_offset);
542 }
543
551 template<class T = ts_t>
552 inline const std::string to_iso8601(T ts) {
554 char buffer[32] = {0};
555 if TIME_SHIELD_IF_CONSTEXPR (std::is_floating_point<T>::value) {
556 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2dT%.2d:%.2d:%.2d.%.3d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec, dt.ms);
557 } else {
558 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2dT%.2d:%.2d:%.2d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec);
559 }
560 return std::string(buffer);
561 }
562
570 template<class T = ts_t>
571 inline const std::string to_iso8601_date(T ts) {
573 char buffer[32] = {0};
574 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2d", dt.year, dt.mon, dt.day);
575 return std::string(buffer);
576 }
577
585 template<class T = ts_t>
586 inline const std::string to_iso8601_time(T ts) {
588 char buffer[32] = {0};
589 if TIME_SHIELD_IF_CONSTEXPR (std::is_floating_point<T>::value) {
590 snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2d.%.3d", dt.hour, dt.min, dt.sec, dt.ms);
591 } else {
592 snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2d", dt.hour, dt.min, dt.sec);
593 }
594 return std::string(buffer);
595 }
596
604 template<class T = ts_t>
605 inline const std::string to_iso8601_time_utc(T ts) {
607 char buffer[32] = {0};
608 if TIME_SHIELD_IF_CONSTEXPR (std::is_floating_point<T>::value) {
609 snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2d.%.3dZ", dt.hour, dt.min, dt.sec, dt.ms);
610 } else {
611 snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2dZ", dt.hour, dt.min, dt.sec);
612 }
613 return std::string(buffer);
614 }
615
623 template<class T = ts_t>
624 inline const std::string to_iso8601_utc(T ts) {
626 char buffer[32] = {0};
627 if TIME_SHIELD_IF_CONSTEXPR (std::is_floating_point<T>::value) {
628 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2dT%.2d:%.2d:%.2d.%.3dZ", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec, dt.ms);
629 } else {
630 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2dT%.2d:%.2d:%.2dZ", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec);
631 }
632 return std::string(buffer);
633 }
634
641 inline const std::string to_iso8601_utc_ms(ts_ms_t ts_ms) {
643 char buffer[32] = {0};
644 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2dT%.2d:%.2d:%.2d.%.3dZ", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec, dt.ms);
645 return std::string(buffer);
646 }
647
654 inline const std::string to_iso8601_ms(ts_ms_t ts_ms) {
656 char buffer[32] = {0};
657 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2dT%.2d:%.2d:%.2d.%.3d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec, dt.ms);
658 return std::string(buffer);
659 }
660
669 template<class T = ts_t>
670 inline const std::string to_iso8601(T ts, tz_t utc_offset) {
671 TimeZoneStruct tz = to_time_zone(utc_offset);
673 char buffer[32] = {0};
674 if TIME_SHIELD_IF_CONSTEXPR (std::is_floating_point<T>::value) {
675 if (tz.is_positive) {
676 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2dT%.2d:%.2d:%.2d.%.3d+%.2d:%.2d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec, dt.ms, tz.hour, tz.min);
677 } else {
678 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2dT%.2d:%.2d:%.2d.%.3d-%.2d:%.2d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec, dt.ms, tz.hour, tz.min);
679 }
680 } else {
681 if (tz.is_positive) {
682 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2dT%.2d:%.2d:%.2d+%.2d:%.2d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec, tz.hour, tz.min);
683 } else {
684 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2dT%.2d:%.2d:%.2d-%.2d:%.2d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec, tz.hour, tz.min);
685 }
686 }
687 return std::string(buffer);
688 }
689
697 inline const std::string to_iso8601_ms(ts_ms_t ts_ms, tz_t utc_offset) {
698 TimeZoneStruct tz = to_time_zone(utc_offset);
700 char buffer[32] = {0};
701 if (tz.is_positive) {
702 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2dT%.2d:%.2d:%.2d.%.3d+%.2d:%.2d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec, dt.ms, tz.hour, tz.min);
703 } else {
704 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2dT%.2d:%.2d:%.2d.%.3d-%.2d:%.2d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec, dt.ms, tz.hour, tz.min);
705 }
706 return std::string(buffer);
707 }
708
715 inline const std::string to_mql5_date_time(ts_t ts) {
717 char buffer[32] = {0};
718 snprintf(buffer, sizeof(buffer), "%lld.%.2d.%.2d %.2d:%.2d:%.2d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec);
719 return std::string(buffer);
720 }
721
724 inline const std::string to_mql5_full(ts_t ts) {
725 return to_mql5_date_time(ts);
726 }
727
734 inline const std::string to_mql5_date(ts_t ts) {
736 char buffer[32] = {0};
737 snprintf(buffer, sizeof(buffer), "%lld.%.2d.%.2d", dt.year, dt.mon, dt.day);
738 return std::string(buffer);
739 }
740
747 inline const std::string to_mql5_time(ts_t ts) {
749 char buffer[32] = {0};
750 snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2d", dt.hour, dt.min, dt.sec);
751 return std::string(buffer);
752 }
753
757 inline const std::string to_windows_filename(ts_t ts) {
759 char buffer[32] = {0};
760 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2d_%.2d-%.2d-%.2d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec);
761 return std::string(buffer);
762 }
763
767 inline const std::string to_windows_filename_ms(ts_ms_t ts) {
769 char buffer[32] = {0};
770 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2d_%.2d-%.2d-%.2d-%.3d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec, dt.ms);
771 return std::string(buffer);
772 }
773
777 std::string to_human_readable(ts_t ts) {
779 char buffer[32] = {0};
780 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2d %.2d:%.2d:%.2d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec);
781 return std::string(buffer);
782 }
783
789 char buffer[32] = {0};
790 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2d %.2d:%.2d:%.2d.%.3d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec, dt.ms);
791 return std::string(buffer);
792 }
793
795
796}; // namespace time_shield
797
798#endif // _TIME_SHIELD_TIME_FORMATTING_HPP_INCLUDED
Header for date and time structure and related functions.
const TimeZoneStruct 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.
const TimeZoneStruct to_time_zone_struct(tz_t offset)
Converts an integer to a TimeZoneStruct.
const T day_of_year(ts_t ts=ts())
Get the day of the year.
Month
Enumeration of the months of the year.
Definition enums.hpp:103
const std::string & to_str(Weekday value, FormatType format=UPPERCASE_NAME)
Converts a Weekday enum value to a string.
Definition enums.hpp:81
@ SHORT_NAME
Short name.
Definition enums.hpp:35
@ UPPERCASE_NAME
Uppercase short name.
Definition enums.hpp:34
@ FULL_NAME
Full name.
Definition enums.hpp:36
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 std::string to_iso8601_ms(ts_ms_t ts_ms)
Converts a timestamp in milliseconds to an ISO8601 string.
const std::string to_mql5_date_time(ts_t ts)
Converts a timestamp to a string in MQL5 date and time format.
const std::string to_iso8601_time(T ts)
Converts a timestamp to an ISO8601 time string.
void process_format_impl(char last_char, size_t repeat_count, ts_t ts, tz_t utc_offset, const DateTimeStruct &dt, std::string &result)
const std::string to_windows_filename(ts_t ts)
Converts a timestamp in seconds to a Windows-compatible filename format.
const std::string to_iso8601_date(T ts)
Converts a timestamp to an ISO8601 date string.
const std::string to_mql5_date(ts_t ts)
Converts a timestamp to a string in MQL5 date format.
const std::string to_mql5_full(ts_t ts)
Alias for to_mql5_date_time_str function.
const std::string to_mql5_time(ts_t ts)
Converts a timestamp to a string in MQL5 time format.
const std::string to_str_ms(const std::string &format_str, T timestamp, tz_t utc_offset=0)
Alias for to_string function.
std::string to_human_readable(ts_t ts)
Converts a timestamp in seconds to a human-readable format.
const std::string to_iso8601_utc_ms(ts_ms_t ts_ms)
Converts a timestamp in milliseconds to an ISO8601 string in UTC format.
const std::string to_iso8601(T ts)
Converts a timestamp to an ISO8601 string.
std::string to_human_readable_ms(ts_ms_t ts)
Converts a timestamp in milliseconds to a human-readable format.
const std::string to_iso8601_time_utc(T ts)
Converts a timestamp to an ISO8601 UTC time string.
const std::string to_string_ms(const std::string &format_str, T timestamp, tz_t utc_offset=0)
Convert timestamp in milliseconds to string with custom format.
const std::string to_windows_filename_ms(ts_ms_t ts)
Converts a timestamp in milliseconds to a Windows-compatible filename format.
const std::string to_iso8601_utc(T ts)
Converts a timestamp to an ISO8601 string in UTC format.
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.
int64_t ts_t
Type for representing timestamps in seconds.
Definition types.hpp:33
int tz_t
Type for representing time zone offsets in minutes.
Definition types.hpp:41
int64_t ts_ms_t
Type for representing timestamps in milliseconds.
Definition types.hpp:34
const ts_t timestamp() noexcept
Get the current UTC timestamp in seconds.
const ts_ms_t ts_ms() noexcept
Get the current UTC timestamp in milliseconds.
const ts_t ts() noexcept
Get the current UTC timestamp in seconds.
Main namespace for the Time Shield library.
Definition constants.hpp:12
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 file for time conversion functions.
Header for time zone structure and related functions.