15 const std::string iso =
"2024-11-25T14:30:00-05:30";
20 std::cout <<
"Parsed date/time: "
21 << dt.
year <<
'-' << dt.
mon <<
'-' << dt.
day <<
' '
24 std::cout <<
'.' << dt.
ms;
26 << tz.
hour <<
':' << tz.
min <<
'\n';
28 std::cerr <<
"Failed to parse: " << iso <<
'\n';
33 std::cout <<
"ts: " << s_ts <<
'\n';
37 std::cout <<
"ts_ms: " << ms_ts <<
'\n';
41 std::cout <<
"fts: " << f_ts <<
'\n';
43 std::cout <<
"Using helpers ts(): " <<
ts(iso) <<
'\n';
44 std::cout <<
"Using helpers ts_ms(): " <<
ts_ms(iso) <<
'\n';
45 std::cout <<
"Using helpers fts(): " <<
fts(iso) <<
'\n';
48 std::cout <<
"Month number for March: " <<
static_cast<int>(mon) <<
'\n';
52 std::cout <<
"sec_of_day(\"15:30:10\"): " << sod <<
'\n';
53 std::cout <<
"sec_of_day(\"8:20\"): " <<
sec_of_day(
"8:20") <<
'\n';
55 std::cout <<
"Press Enter to exit..." << std::endl;
61 std::cout <<
"time_parser.hpp requires Windows for now_realtime_us()" << std::endl;
constexpr T sec_of_day(ts_t ts=time_shield::ts()) noexcept
Get the second of the day.
TIME_SHIELD_CONSTEXPR ts_t ts(year_t year, int month, int day)
Alias for to_timestamp.
constexpr fts_t fts(T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0, T3 ms=0)
Alias for to_ftimestamp.
constexpr ts_ms_t ts_ms(year_t year, int month, int day)
Alias for to_timestamp_ms.
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 parse_iso8601(const std::string &input, DateTimeStruct &dt, TimeZoneStruct &tz)
Parse a date and time string in ISO8601 format.
T get_month_number(const std::string &month)
Get the month number by name.
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).
int64_t ts_t
Unix timestamp in seconds since 1970‑01‑01T00:00:00Z.
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 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 with functions for parsing dates and times in ISO8601 format and converting them to vario...