15 const std::string iso8601 =
"2024-11-25T14:30:00-05:30";
19 std::cout <<
"ISO fields: "
20 << iso_dt.
year <<
'-' << iso_dt.
mon <<
'-' << iso_dt.
day <<
' '
21 << iso_dt.
hour <<
':' << iso_dt.
min <<
':' << iso_dt.
sec <<
' '
28 std::cout <<
"UTC seconds: " << utc_ts <<
'\n';
34 std::cout <<
"UTC milliseconds: " << utc_ms <<
'\n';
39 if (
str_to_fts(
"2024-11-25T20:00:00.250Z", utc_fts)) {
40 std::cout <<
"UTC floating seconds: " << utc_fts <<
'\n';
45 const std::string custom =
to_string(
"%Y-%m-%d %H:%M:%S %z", utc_ts, utc_offset);
46 std::cout <<
"Custom formatted: " << custom <<
'\n';
50 std::cout <<
"Reparsed seconds: " << reparsed_ts <<
'\n';
53 const std::string custom_ms =
to_string_ms(
"%Y-%m-%d %H:%M:%S.%sss %z", utc_ms, utc_offset);
54 std::cout <<
"Custom formatted with ms: " << custom_ms <<
'\n';
58 std::cout <<
"Parsed custom milliseconds: " << reparsed_ms <<
'\n';
64 std::cout <<
"ISO week mixed form: "
65 << iso_week.
year <<
"-W" << iso_week.
week <<
'-' << iso_week.
weekday <<
'\n';
70 std::cout <<
"ISO week lowercase/default weekday: "
71 << iso_week.
year <<
"-W" << iso_week.
week <<
'-' << iso_week.
weekday <<
'\n';
76 const std::string iso_week_custom =
to_string(
"%G-%V-%u", iso_week_ts);
77 std::cout <<
"ISO week custom formatted: " << iso_week_custom <<
'\n';
81 if (
try_parse_format(iso_week_custom,
"%G-%V-%u", iso_week_dt, iso_week_tz)) {
82 std::cout <<
"ISO week reparsed calendar date: "
83 << iso_week_dt.
year <<
'-' << iso_week_dt.
mon <<
'-' << iso_week_dt.
day <<
'\n';
87 std::cout <<
"ISO week without weekday resolves to: "
88 << iso_week_dt.
year <<
'-' << iso_week_dt.
mon <<
'-' << iso_week_dt.
day <<
'\n';
93 std::cout <<
"Format mismatch: " << (mismatch ?
"unexpected success" :
"false") <<
'\n';
97 "2025-12-16 2025-51-2",
101 std::cout <<
"Mixed Gregorian/ISO-week tokens: "
102 << (conflicting_tokens ?
"unexpected success" :
"false") <<
'\n';
Value-type wrapper for timestamps with fixed UTC offset.
static bool try_parse_iso_week_date(const std::string &str, IsoWeekDateStruct &iso) noexcept
Try to parse ISO week-date string.
constexpr int64_t SEC_PER_HOUR
Seconds per hour.
constexpr int64_t SEC_PER_MIN
Seconds per minute.
bool parse_iso_week_date(const char *input, std::size_t length, IsoWeekDateStruct &iso_date) noexcept
Parse ISO week date string buffer.
bool parse_iso8601(const char *input, std::size_t length, DateTimeStruct &dt, TimeZoneStruct &tz) noexcept
Parse ISO8601 character buffer into DateTimeStruct and TimeZoneStruct.
bool str_to_ts_ms(const std::string &str, ts_ms_t &ts)
Convert an ISO8601 string to a millisecond timestamp (ts_ms_t).
bool try_parse_format(const char *data, std::size_t length, const char *format, std::size_t format_length, DateTimeStruct &out_dt, TimeZoneStruct &out_tz) noexcept
Parse input using formatter-compatible custom pattern.
bool try_parse_format_ts_ms(const char *data, std::size_t length, const char *format, std::size_t format_length, ts_ms_t &out_ts) noexcept
Parse input using formatter-compatible custom pattern and convert to UTC milliseconds.
bool try_parse_format_ts(const char *data, std::size_t length, const char *format, std::size_t format_length, ts_t &out_ts) noexcept
Parse input using formatter-compatible custom pattern and convert to UTC seconds.
bool str_to_ts(const std::string &str, ts_t &ts)
Convert an ISO8601 string to a timestamp (ts_t).
bool str_to_fts(const std::string &str, fts_t &ts)
Convert an ISO8601 string to a floating-point timestamp (fts_t).
TIME_SHIELD_CONSTEXPR ts_t to_timestamp(T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0)
Converts a date and time to a timestamp.
int64_t ts_t
Unix timestamp in seconds since 1970‑01‑01T00:00:00Z.
int32_t tz_t
Time zone offset in minutes from UTC (e.g., +180 = UTC+3).
int64_t ts_ms_t
Unix timestamp in milliseconds since epoch.
double fts_t
Floating-point timestamp (fractional seconds since epoch).
Main namespace for the Time Shield library.
Structure to represent date and time.
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 an ISO week date.
int64_t year
ISO week-numbering year component.
int32_t week
ISO week number component (1-52/53).
int32_t weekday
ISO weekday component (1=Monday .. 7=Sunday).
Structure to represent time zone information.
Header file with functions for parsing dates and times in ISO8601 format and converting them to vario...