Time Shield Library 2.0.0
C++ library for working with time
Loading...
Searching...
No Matches
time_formatting_showcase_example.cpp
Go to the documentation of this file.
1
3
5
6#include <iostream>
7
8int main() {
9 using namespace time_shield;
10
11 const ts_t utc_ts = to_timestamp(2024, 6, 21, 12, 34, 56);
12 const ts_ms_t utc_ms = ts_ms(2024, 6, 21, 12, 34, 56, 789);
13 const tz_t utc_offset = 2 * SEC_PER_HOUR + 30 * SEC_PER_MIN;
14
15 // ISO8601 helpers.
16 std::cout << "ISO8601 local default: " << to_iso8601(utc_ts) << '\n';
17 std::cout << "ISO8601 UTC: " << to_iso8601_utc(utc_ts) << '\n';
18 std::cout << "ISO8601 date: " << to_iso8601_date(utc_ts) << '\n';
19 std::cout << "ISO8601 time: " << to_iso8601_time(utc_ts) << '\n';
20 std::cout << "ISO8601 time UTC: " << to_iso8601_time_utc(utc_ts) << '\n';
21 std::cout << "ISO8601 with offset: " << to_iso8601(utc_ts, utc_offset) << '\n';
22 std::cout << "ISO8601 ms local: " << to_iso8601_ms(utc_ms) << '\n';
23 std::cout << "ISO8601 ms UTC: " << to_iso8601_utc_ms(utc_ms) << '\n';
24 std::cout << "ISO8601 ms with offset: " << to_iso8601_ms(utc_ms, utc_offset) << '\n';
25
26 // Custom formatting helpers.
27 std::cout << "Custom UTC format: "
28 << to_string("%Y-%m-%d %H:%M:%S", utc_ts) << '\n';
29 std::cout << "Custom local format: "
30 << to_string("%Y-%m-%d %H:%M:%S %z", utc_ts, utc_offset) << '\n';
31 std::cout << "Custom UTC format (ms): "
32 << to_string_ms("%Y-%m-%d %H:%M:%S.%sss", utc_ms) << '\n';
33 std::cout << "Custom local fmt (ms): "
34 << to_string_ms("%Y-%m-%d %H:%M:%S.%sss %z", utc_ms, utc_offset) << '\n';
35
36 // Specialized output helpers.
37 std::cout << "MQL5 date/time: " << to_mql5_date_time(utc_ts) << '\n';
38 std::cout << "Filename-safe string: " << to_windows_filename(utc_ts) << '\n';
39 std::cout << "Filename-safe ms: " << to_windows_filename_ms(utc_ms) << '\n';
40 std::cout << "Human readable: " << to_human_readable(utc_ts) << '\n';
41 std::cout << "Human readable (ms): " << to_human_readable_ms(utc_ms) << '\n';
42
43 return 0;
44}
int64_t ts_t
Unix timestamp in seconds since 1970‑01‑01T00:00:00Z.
Definition types.hpp:48
int32_t tz_t
Time zone offset in minutes from UTC (e.g., +180 = UTC+3).
Definition types.hpp:60
int64_t ts_ms_t
Unix timestamp in milliseconds since epoch.
Definition types.hpp:49
Main namespace for the Time Shield library.
Header file for time formatting utilities.