|
lintel 0.2.0
|
Typedefs | |
| using | SystemTime = std::chrono::sys_time< std::chrono::microseconds > |
Functions | |
| std::time_t | timegmPortable (std::tm *tm) noexcept |
| long | localOffsetSeconds (std::time_t time, const std::tm &local) noexcept |
| bool | isEastOfUtc (long offsetSeconds) noexcept |
| std::string | formatOffset (long offsetSeconds) |
| std::string | formatSystemTime (const SystemTime &value, char dateSeparator='-') |
| SystemTime | parseSystemTime (const std::string &value) |
| std::string | formatUtcIsoSeconds (const std::chrono::sys_seconds &value) |
Portable, locale-independent timestamp formatting/parsing.
The library used to rely on the C++20 chrono integrations of <format> (std::format("{:%Y-%m-%d %H:%M:%S%Ez}", sys_time<microseconds>)) and of the stream extraction operator (std::chrono::parse(...)). Both landed in libc++ only recently (chrono formatting in LLVM 21) and are still incomplete in AppleClang's libc++, so they are not portable to macOS. libstdc++ and MSVC support them, but with platform-specific corner cases (e.g. the decimal separator of the active locale). These helpers replace both with a small, self-contained implementation that produces the same wire format on every platform and target:
"2021-09-08 17:04:49.580723+02:00"
i.e. local time with microsecond resolution and a "+HH:MM" UTC offset. The offset variants "±HH", "±HHMM" and "±HH:MM" are all accepted when parsing, matching what PostgreSQL/SQLite store in the seed data.
| using lintel::datetime::SystemTime = typedef std::chrono::sys_time<std::chrono::microseconds> |
Timestamp type used across the persistence layer.
|
inline |
| offsetSeconds | offset from UTC in seconds |
|
inline |
Format a timestamp the way the persistence layer stores it: local time, microsecond resolution, "+HH:MM" offset.
| value | the timestamp (microsecond resolution) |
| dateSeparator | separator used between the date components ('-' in the database, '.' in the human-readable user dump) |
|
inline |
Format a UTC timestamp as ISO-8601 with a second resolution and a "Z" suffix (the "{:%FT%TZ}" form used by the CLI prompt).
| value | the timestamp |
| offsetSeconds | offset from UTC in seconds |
|
inlinenoexcept |
| time | a point in time |
| local | its local-time representation (from lintel::localTime) |
|
inline |
Parse a timestamp produced by formatSystemTime (or by PostgreSQL/SQLite). Accepts "YYYY-MM-DD HH:MM:SS[.ffffff]" followed by a required UTC offset in one of the forms "Z", "+HH", "-HH", "+HHMM", "+HH:MM".
| value | the string to parse |
|
inlinenoexcept |
timegm() is POSIX, _mkgmtime() is MSVC; both interpret a std::tm as UTC.
| tm | broken-down UTC time (modified in place) |