Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
time_formatting.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2#pragma once
3#ifndef _TIME_SHIELD_TIME_FORMATTING_HPP_INCLUDED
4#define _TIME_SHIELD_TIME_FORMATTING_HPP_INCLUDED
5
12
13#include "date_time_struct.hpp"
14#include "time_zone_struct.hpp"
15#include "time_conversions.hpp"
16
17namespace time_shield {
18
21
23 char last_char,
24 size_t repeat_count,
25 ts_t ts,
26 tz_t utc_offset,
27 const DateTimeStruct& dt,
28 std::string& result) {
29 switch (last_char) {
30 case 'a':
31 if (repeat_count > 1) break;
32 result += to_str(day_of_week(dt.year, dt.mon, dt.day), FormatType::SHORT_NAME);
33 break;
34 case 'A':
35 if (repeat_count > 1) break;
36 result += to_str(day_of_week(dt.year, dt.mon, dt.day), FormatType::FULL_NAME);
37 break;
38 case 'I':
39 if (repeat_count == 1) {
40 char buffer[4] = {0};
41 snprintf(buffer, sizeof(buffer), "%.2d", hour24_to_12(dt.hour));
42 result += std::string(buffer);
43 }
44 break;
45 case 'H':
46 if (repeat_count <= 2) {
47 char buffer[4] = {0};
48 snprintf(buffer, sizeof(buffer),"%.2d", dt.hour);
49 result += std::string(buffer);
50 }
51 break;
52 case 'h':
53 if (repeat_count == 2) {
54 char buffer[4] = {0};
55 snprintf(buffer, sizeof(buffer),"%.2d", dt.hour);
56 result += std::string(buffer);
57 break;
58 }
59 // %h: Equivalent to %b
60 case 'b':
61 if (repeat_count > 1) break;
62 result += to_str(static_cast<Month>(dt.mon), FormatType::SHORT_NAME);
63 break;
64 case 'B':
65 if (repeat_count > 1) break;
66 result += to_str(static_cast<Month>(dt.mon), FormatType::FULL_NAME);
67 break;
68 case 'c':
69 // Preferred date and time representation for the current locale.
70 // %a %b %e %H:%M:%S %Y
71 if (repeat_count <= 1){
72 char buffer[16];
73 result += to_str(day_of_week(dt.year, dt.mon, dt.day), FormatType::SHORT_NAME);
74 result += " ";
75 result += to_str(static_cast<Month>(dt.mon), FormatType::SHORT_NAME);
76 result += " ";
77 // added %e
78 std::fill(buffer, buffer + sizeof(buffer), '\0');
79 snprintf(buffer, sizeof(buffer),"%2d ", dt.day);
80 result += std::string(buffer);
81 // added %H:%M:%S
82 std::fill(buffer, buffer + sizeof(buffer), '\0');
83 snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2d ", dt.hour, dt.min, dt.sec);
84 result += std::string(buffer);
85 // added %Y
86 result += std::to_string(dt.year);
87 }
88 break;
89 case 'C':
90 if (repeat_count > 1) break;
91 result += std::to_string(dt.year/100);
92 break;
93 case 'd':
94 if (repeat_count < 2) {
95 char buffer[4] = {0};
96 snprintf(buffer, sizeof(buffer),"%.2d", dt.day);
97 result += std::string(buffer);
98 }
99 break;
100 case 'D':
101 if (repeat_count == 1) {
102 // %m/%d/%y
103 char buffer[16] = {0};
104 snprintf(buffer, sizeof(buffer), "%.2d/%.2d/%.2d", dt.mon, dt.day, (int)(dt.year % 100LL));
105 result += std::string(buffer);
106 } else
107 if (repeat_count == 2) {
108 char buffer[4] = {0};
109 snprintf(buffer, sizeof(buffer),"%.2d", dt.day);
110 result += std::string(buffer);
111 }
112 break;
113 case 'e':
114 if (repeat_count == 1) {
115 char buffer[4] = {0};
116 snprintf(buffer, sizeof(buffer),"%2d", dt.day);
117 result += std::string(buffer);
118 }
119 break;
120 case 'E':
121 // %E: Modifier for alternative ("era-based") format.
122 // https://help.hcltechsw.com/onedb/1.0.0.1/gug/ids_gug_086.html#ids_gug_086
123 break;
124 case 'F':
125 if (repeat_count == 1) {
126 // %Y-%m-%d ISO 8601 date format
127 char buffer[32] = {0};
128 if (dt.year <= 9999 || dt.year >= 0) {
129 snprintf(buffer, sizeof(buffer), "%.4d-%.2d-%.2d", (int)dt.year, dt.mon, dt.day);
130 } else
131 if (dt.year < 0) {
132 snprintf(buffer, sizeof(buffer), "-%lld-%.2d-%.2d", dt.year, dt.mon, dt.day);
133 } else {
134 snprintf(buffer, sizeof(buffer), "+%lld-%.2d-%.2d", dt.year, dt.mon, dt.day);
135 }
136 result += std::string(buffer);
137 }
138 case 'g':
139 // ISO 8601 week-based year without century (2-digit year).
140 break;
141 case 'G':
142 // ISO 8601 week-based year with century as a decimal number.
143 break;
144 case 'j':
145 if (repeat_count == 1) {
146 char buffer[4] = {0};
147 snprintf(buffer, sizeof(buffer), "%.3d", day_of_year(ts));
148 result += std::string(buffer);
149 }
150 break;
151 case 'k':
152 if (repeat_count == 1) {
153 char buffer[4] = {0};
154 snprintf(buffer, sizeof(buffer), "%2d", dt.hour);
155 result += std::string(buffer);
156 }
157 break;
158 case 'l':
159 if (repeat_count == 1) {
160 char buffer[4] = {0};
161 snprintf(buffer, sizeof(buffer), "%2d", hour24_to_12(dt.hour));
162 result += std::string(buffer);
163 }
164 break;
165 case 'm':
166 if (repeat_count == 1) {
167 char buffer[4] = {0};
168 snprintf(buffer, sizeof(buffer), "%.2d", dt.mon);
169 result += std::string(buffer);
170 } else
171 if (repeat_count == 2) {
172 char buffer[4] = {0};
173 snprintf(buffer, sizeof(buffer), "%.2d", dt.min);
174 result += std::string(buffer);
175 }
176 break;
177 case 'M':
178 if (repeat_count == 1) {
179 char buffer[4] = {0};
180 snprintf(buffer, sizeof(buffer), "%.2d", dt.min);
181 result += std::string(buffer);
182 } else
183 if (repeat_count == 2) {
184 char buffer[4] = {0};
185 snprintf(buffer, sizeof(buffer), "%.2d", dt.mon);
186 result += std::string(buffer);
187 } else
188 if (repeat_count == 3) {
189 result += to_str(static_cast<Month>(dt.mon), FormatType::UPPERCASE_NAME);
190 }
191 break;
192 case 'n':
193 result += "\n";
194 break;
195 case 'O':
196 // Modifier for using alternative numeric symbols.
197 break;
198 case 'p':
199 if (dt.hour < 12) result += "AM";
200 else result += "PM";
201 break;
202 case 'P':
203 if (dt.hour < 12) result += "am";
204 else result += "pm";
205 break;
206 case 'r':
207 if (repeat_count == 1) {
208 char buffer[16] = {0};
209 if (dt.hour < 12) snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2d AM", hour24_to_12(dt.hour), dt.min, dt.sec);
210 else snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2d PM", hour24_to_12(dt.hour), dt.min, dt.sec);
211 result += std::string(buffer);
212 break;
213 }
214 break;
215 case 'R':
216 // %H:%M
217 if (repeat_count == 1) {
218 char buffer[8] = {0};
219 snprintf(buffer, sizeof(buffer), "%.2d:%.2d", dt.hour, dt.min);
220 result += std::string(buffer);
221 }
222 break;
223 case 's':
224 if (repeat_count == 1) {
225 result += std::to_string(ts);
226 break;
227 }
228 if (repeat_count == 3) {
229 result += std::to_string(dt.ms);
230 break;
231 }
232 // to '%ss'
233 case 'S':
234 if (repeat_count <= 2) {
235 char buffer[4] = {0};
236 snprintf(buffer, sizeof(buffer), "%.2d", dt.sec);
237 result += std::string(buffer);
238 }
239 if (repeat_count == 3) {
240 result += std::to_string(dt.ms);
241 break;
242 }
243 break;
244 case 't':
245 if (repeat_count > 1) break;
246 result += "\t";
247 break;
248 case 'T':
249 // %H:%M:%S
250 if (repeat_count == 1) {
251 char buffer[16] = {0};
252 snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2d", dt.hour, dt.min, dt.sec);
253 result += std::string(buffer);
254 }
255 break;
256 case 'u':
257 if (repeat_count == 1) {
258 // Day of the week as a decimal number (1 to 7, Monday being 1).
259 int dw = day_of_week(dt.year, dt.mon, dt.day);
260 if (dw == 0) dw = 7;
261 result += std::to_string(dw);
262 }
263 break;
264 case 'U':
265 // Week number of the current year (00 to 53, starting with the first Sunday as week 01).
266 break;
267 case 'V':
268 // ISO 8601 week number of the current year (01 to 53, with specific rules).
269 break;
270 case 'w':
271 // Day of the week as a decimal number (0 to 6, Sunday being 0).
272 if (repeat_count == 1) {
273 result += std::to_string(day_of_week(dt.year, dt.mon, dt.day));
274 } else
275 if (repeat_count == 3) {
276 result += to_str(day_of_week(dt.year, dt.mon, dt.day), FormatType::SHORT_NAME);
277 }
278 break;
279 case 'W':
280 // Week number of the current year (00 to 53, starting with the first Monday as week 01).
281 if (repeat_count == 3) {
282 result += to_str(day_of_week(dt.year, dt.mon, dt.day), FormatType::UPPERCASE_NAME);
283 }
284 break;
285 case 'x':
286 // Preferred date representation for the current locale without the time.
287 break;
288 case 'X':
289 // Preferred time representation for the current locale without the date.
290 break;
291 case 'y':
292 if (repeat_count == 1) {
293 result += std::to_string(dt.year % 100);
294 }
295 break;
296 case 'Y':
297 if (repeat_count == 1) {
298 result += std::to_string(dt.year);
299 } else
300 if (repeat_count == 6) {
301 char buffer[32] = {0};
302 const int64_t mega_years = dt.year / 1000000;
303 const int64_t millennia = (dt.year - mega_years * 1000000) / 1000;
304 const int64_t centuries = dt.year - mega_years * 1000000 - millennia * 1000;
305 if (mega_years) {
306 if (millennia) {
307 snprintf(buffer, sizeof(buffer), "%lldM%lldK%.3lld", mega_years, std::abs(millennia), std::abs(centuries));
308 } else {
309 snprintf(buffer, sizeof(buffer), "%lldM%.3lld", mega_years, std::abs(centuries));
310 }
311 } else
312 if (millennia) {
313 snprintf(buffer, sizeof(buffer), "%lldK%.3lld", millennia, std::abs(centuries));
314 } else {
315 snprintf(buffer, sizeof(buffer), "%.4lld", dt.year);
316 }
317 result += std::string(buffer);
318 } else
319 if (repeat_count == 4) {
320 char buffer[8] = {0};
321 snprintf(buffer, sizeof(buffer), "%.4d", (int)(dt.year % 10000));
322 result += std::string(buffer);
323 } else
324 if (repeat_count == 2) {
325 char buffer[8] = {0};
326 snprintf(buffer, sizeof(buffer), "%.2d", (int)(dt.year % 100));
327 result += std::string(buffer);
328 }
329 break;
330 case 'z':
331 // +hhmm or -hhmm numeric timezone offset from UTC.
332 if (repeat_count == 1) {
333 TimeZoneStruct tz = to_time_zone_struct(utc_offset);
334 char buffer[16] = {0};
335 if (tz.is_positive) snprintf(buffer, sizeof(buffer), "+%.2d%.2d", tz.hour, tz.min);
336 else snprintf(buffer, sizeof(buffer), "-%.2d%.2d", tz.hour, tz.min);
337 result += std::string(buffer);
338 }
339 break;
340 case 'Z':
341 // Timezone name or abbreviation.
342
343 result += "UTC";
344 break;
345 case '+':
346 // Date and time in date(1) format (not supported in glibc2).
347 // Tue Jun 4 04:07:43 UTC 2024
348 break;
349 };
350 }
351
378 template<class T = ts_t>
379 const std::string to_string(
380 const std::string& format_str,
381 T timestamp,
382 tz_t utc_offset = 0) {
383 std::string result;
384 if (format_str.empty()) return result;
386
387 bool is_command = false;
388 size_t repeat_count = 0;
389 char last_char = format_str[0];
390 if (last_char != '%') result += last_char;
391 for (size_t i = 0; i < format_str.size(); ++i) {
392 const char& current_char = format_str[i];
393 if (!is_command) {
394 if (current_char == '%') {
395 ++repeat_count;
396 if (repeat_count == 2) {
397 result += current_char;
398 repeat_count = 0;
399 }
400 continue;
401 }
402 if (!repeat_count) {
403 result += current_char;
404 continue;
405 }
406 last_char = current_char;
407 is_command = true;
408 continue;
409 }
410 if (last_char == current_char) {
411 ++repeat_count;
412 continue;
413 }
414 process_format_impl(last_char, repeat_count, timestamp, utc_offset, dt, result);
415 repeat_count = 0;
416 is_command = false;
417 --i;
418 }
419 if (is_command) {
420 process_format_impl(last_char, repeat_count, timestamp, utc_offset, dt, result);
421 }
422 return result;
423 }
424
427 template<class T = ts_t>
428 inline const std::string to_str(
429 const std::string& format_str,
430 T timestamp,
431 tz_t utc_offset = 0) {
432 return to_string<T>(format_str, timestamp, utc_offset);
433 }
434
461 template<class T = ts_ms_t>
462 const std::string to_string_ms(
463 const std::string& format_str,
464 T timestamp,
465 tz_t utc_offset = 0) {
466 std::string result;
467 if (format_str.empty()) return result;
469
470 bool is_command = false;
471 size_t repeat_count = 0;
472 char last_char = format_str[0];
473 if (last_char != '%') result += last_char;
474 for (size_t i = 0; i < format_str.size(); ++i) {
475 const char& current_char = format_str[i];
476 if (!is_command) {
477 if (current_char == '%') {
478 ++repeat_count;
479 if (repeat_count == 2) {
480 result += current_char;
481 repeat_count = 0;
482 }
483 continue;
484 }
485 if (!repeat_count) {
486 result += current_char;
487 continue;
488 }
489 last_char = current_char;
490 is_command = true;
491 continue;
492 }
493 if (last_char == current_char) {
494 ++repeat_count;
495 continue;
496 }
497 process_format_impl(last_char, repeat_count, timestamp, utc_offset, dt, result);
498 repeat_count = 0;
499 is_command = false;
500 --i;
501 }
502 if (is_command) {
503 process_format_impl(last_char, repeat_count, timestamp, utc_offset, dt, result);
504 }
505 return result;
506 }
507
510 template<class T = ts_t>
511 inline const std::string to_str_ms(
512 const std::string& format_str,
513 T timestamp,
514 tz_t utc_offset = 0) {
515 return to_string_ms<T>(format_str, timestamp, utc_offset);
516 }
517
525 template<class T = ts_t>
526 inline const std::string to_iso8601(T ts) {
528 char buffer[32] = {0};
529 if TIME_SHIELD_IF_CONSTEXPR (std::is_floating_point<T>::value) {
530 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);
531 } else {
532 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2dT%.2d:%.2d:%.2d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec);
533 }
534 return std::string(buffer);
535 }
536
544 template<class T = ts_t>
545 inline const std::string to_iso8601_date(T ts) {
547 char buffer[32] = {0};
548 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2d", dt.year, dt.mon, dt.day);
549 return std::string(buffer);
550 }
551
559 template<class T = ts_t>
560 inline const std::string to_iso8601_time(T ts) {
562 char buffer[32] = {0};
563 if TIME_SHIELD_IF_CONSTEXPR (std::is_floating_point<T>::value) {
564 snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2d.%.3d", dt.hour, dt.min, dt.sec, dt.ms);
565 } else {
566 snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2d", dt.hour, dt.min, dt.sec);
567 }
568 return std::string(buffer);
569 }
570
578 template<class T = ts_t>
579 inline const std::string to_iso8601_time_utc(T ts) {
581 char buffer[32] = {0};
582 if TIME_SHIELD_IF_CONSTEXPR (std::is_floating_point<T>::value) {
583 snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2d.%.3dZ", dt.hour, dt.min, dt.sec, dt.ms);
584 } else {
585 snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2dZ", dt.hour, dt.min, dt.sec);
586 }
587 return std::string(buffer);
588 }
589
597 template<class T = ts_t>
598 inline const std::string to_iso8601_utc(T ts) {
600 char buffer[32] = {0};
601 if TIME_SHIELD_IF_CONSTEXPR (std::is_floating_point<T>::value) {
602 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);
603 } else {
604 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2dT%.2d:%.2d:%.2dZ", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec);
605 }
606 return std::string(buffer);
607 }
608
615 inline const std::string to_iso8601_utc_ms(ts_ms_t ts_ms) {
617 char buffer[32] = {0};
618 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);
619 return std::string(buffer);
620 }
621
628 inline const std::string to_iso8601_ms(ts_ms_t ts_ms) {
630 char buffer[32] = {0};
631 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);
632 return std::string(buffer);
633 }
634
643 template<class T = ts_t>
644 inline const std::string to_iso8601(T ts, tz_t utc_offset) {
645 TimeZoneStruct tz = to_time_zone(utc_offset);
647 char buffer[32] = {0};
648 if TIME_SHIELD_IF_CONSTEXPR (std::is_floating_point<T>::value) {
649 if (tz.is_positive) {
650 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);
651 } else {
652 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);
653 }
654 } else {
655 if (tz.is_positive) {
656 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);
657 } else {
658 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);
659 }
660 }
661 return std::string(buffer);
662 }
663
671 inline const std::string to_iso8601_ms(ts_ms_t ts_ms, tz_t utc_offset) {
672 TimeZoneStruct tz = to_time_zone(utc_offset);
674 char buffer[32] = {0};
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 return std::string(buffer);
681 }
682
689 inline const std::string to_mql5_date_time(ts_t ts) {
691 char buffer[32] = {0};
692 snprintf(buffer, sizeof(buffer), "%lld.%.2d.%.2d %.2d:%.2d:%.2d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec);
693 return std::string(buffer);
694 }
695
698 inline const std::string to_mql5_full(ts_t ts) {
699 return to_mql5_date_time(ts);
700 }
701
708 inline const std::string to_mql5_date(ts_t ts) {
710 char buffer[32] = {0};
711 snprintf(buffer, sizeof(buffer), "%lld.%.2d.%.2d", dt.year, dt.mon, dt.day);
712 return std::string(buffer);
713 }
714
721 inline const std::string to_mql5_time(ts_t ts) {
723 char buffer[32] = {0};
724 snprintf(buffer, sizeof(buffer), "%.2d:%.2d:%.2d", dt.hour, dt.min, dt.sec);
725 return std::string(buffer);
726 }
727
731 inline const std::string to_windows_filename(ts_t ts) {
733 char buffer[32] = {0};
734 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2d_%.2d-%.2d-%.2d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec);
735 return std::string(buffer);
736 }
737
741 inline const std::string to_windows_filename_ms(ts_ms_t ts) {
743 char buffer[32] = {0};
744 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);
745 return std::string(buffer);
746 }
747
751 std::string to_human_readable(ts_t ts) {
753 char buffer[32] = {0};
754 snprintf(buffer, sizeof(buffer), "%lld-%.2d-%.2d %.2d:%.2d:%.2d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec);
755 return std::string(buffer);
756 }
757
763 char buffer[32] = {0};
764 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);
765 return std::string(buffer);
766 }
767
769
770}; // namespace time_shield
771
772#endif // _TIME_SHIELD_TIME_FORMATTING_HPP_INCLUDED
Header for date and time structure and related functions.
TIME_SHIELD_CONSTEXPR ts_t timestamp(year_t year, int month, int day)
Alias for to_timestamp.
T to_date_time_ms(ts_ms_t ts)
Converts a timestamp in milliseconds to a date-time structure with milliseconds.
TIME_SHIELD_CONSTEXPR ts_t ts(year_t year, int month, int day)
Alias for to_timestamp.
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.
T day_of_year(ts_t ts=time_shield::ts())
Get the day of the year.
constexpr T1 day_of_week(year_t year, int month, int day)
Alias for day_of_week_date.
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 std::string & to_str(Weekday value, FormatType format=UPPERCASE_NAME)
Converts a Weekday enum value to a string.
Definition enums.hpp:70
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.
TimeZoneStruct to_time_zone_struct(tz_t offset)
Converts an integer to a TimeZoneStruct.
int64_t ts_t
Unix timestamp in seconds since 1970‑01‑01T00:00:00Z.
Definition types.hpp:46
int32_t tz_t
Time zone offset in minutes from UTC (e.g., +180 = UTC+3).
Definition types.hpp:58
int64_t ts_ms_t
Unix timestamp in milliseconds since epoch.
Definition types.hpp:47
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 file for time conversion functions.
Header for time zone structure and related functions.