RFC 3339 dates formatting and parsing. More...
Enumerations | |
| enum class | Offset { UTC , LOCAL } |
Offset used to format date-time. More... | |
Functions | |
| std::size_t | formatDateTime (const anch::date::DateTime &date, char *output, Offset offset=Offset::UTC) noexcept |
| std::string | formatDateTime (const anch::date::DateTime &date, Offset offset=Offset::UTC) |
| anch::date::DateTime | parseDateTime (std::string_view text) |
| std::size_t | formatDate (const anch::date::Date &date, char *output) noexcept |
| std::string | formatDate (const anch::date::Date &date) |
| anch::date::Date | parseDate (std::string_view text) |
| std::size_t | formatTime (const anch::date::Time &time, char *output) noexcept |
| std::string | formatTime (const anch::date::Time &time) |
| anch::date::Time | parseTime (std::string_view text) |
| std::size_t | formatFullTime (const anch::date::OffsetTime &time, char *output) noexcept |
| std::string | formatFullTime (const anch::date::OffsetTime &time) |
| anch::date::OffsetTime | parseFullTime (std::string_view text) |
Variables | |
| constexpr std::size_t | DATE_TIME_MAX_SIZE = 35 |
| constexpr std::size_t | DATE_SIZE = 10 |
| constexpr std::size_t | TIME_MAX_SIZE = 18 |
| constexpr std::size_t | FULL_TIME_MAX_SIZE = 24 |
RFC 3339 dates formatting and parsing.
RFC 3339 (https://www.rfc-editor.org/rfc/rfc3339#section-5.6) defines:
date-time : YYYY-MM-DDTHH:MM:SS[.fraction](Z|+HH:MM|-HH:MM) (a point in time), mapped to anch::date::DateTime ;full-date : YYYY-MM-DD (a calendar day without time zone), mapped to anch::date::Date ;partial-time : HH:MM:SS[.fraction] (a time of day without time zone), mapped to anch::date::Time (leap seconds are refused: a time of day without day can not hold them) ;full-time : HH:MM:SS[.fraction](Z|+HH:MM|-HH:MM) (a time of day with an offset from UTC), mapped to anch::date::OffsetTime (leap seconds are refused).date-time , full-date and full-time are the date-time , date and time formats of JSON schema and OpenAPI.
Parsing follows the RFC grammar: T and Z can be lower case ; the space separator allowed by the RFC note is refused ; fraction can have any number of digits (digits after the nanosecond are truncated) ; offset -00:00 (unknown local offset) is read as UTC ; leap second ( 60 ) is accepted at 23:59 UTC only, and is read as the next second (time points have no leap seconds).
Functions are thread safe.
|
strong |
Offset used to format date-time.
| std::string anch::date::rfc3339::formatDate | ( | const anch::date::Date & | date | ) |
Format full-date
| date | the date to format |
|
noexcept |
|
noexcept |
Format date-time .
Fraction is written with the number of digits needed by the date: none, 3, 6 or 9.
| date | the date to format |
| output | the output buffer (at least DATE_TIME_MAX_SIZE characters ; not '\0' terminated) |
| offset | the offset to use (default UTC) |
| std::string anch::date::rfc3339::formatDateTime | ( | const anch::date::DateTime & | date, |
| Offset | offset = Offset::UTC ) |
Format date-time
| date | the date to format |
| offset | the offset to use (default UTC) |
| std::string anch::date::rfc3339::formatFullTime | ( | const anch::date::OffsetTime & | time | ) |
Format full-time
| time | the time to format |
|
noexcept |
Format full-time .
Fraction is written with the number of digits needed by the time: none, 3, 6 or 9 ; offset is Z for UTC.
| time | the time to format |
| output | the output buffer (at least FULL_TIME_MAX_SIZE characters ; not '\0' terminated) |
| std::string anch::date::rfc3339::formatTime | ( | const anch::date::Time & | time | ) |
Format partial-time
| time | the time to format |
|
noexcept |
Format partial-time .
Fraction is written with the number of digits needed by the time: none, 3, 6 or 9.
| time | the time to format |
| output | the output buffer (at least TIME_MAX_SIZE characters ; not '\0' terminated) |
| anch::date::Date anch::date::rfc3339::parseDate | ( | std::string_view | text | ) |
Parse full-date
| text | the text to parse |
| std::invalid_argument | invalid format or impossible date |
| anch::date::DateTime anch::date::rfc3339::parseDateTime | ( | std::string_view | text | ) |
Parse date-time
| text | the text to parse |
| std::invalid_argument | invalid format, impossible date or point in time out of anch::date::DateTime range (years 1678 to 2261) |
| anch::date::OffsetTime anch::date::rfc3339::parseFullTime | ( | std::string_view | text | ) |
Parse full-time (fraction can have any number of digits: digits after the nanosecond are truncated ; Z can be lower case ; offset -00:00 is read as UTC)
| text | the text to parse |
| std::invalid_argument | invalid format (offset is required), impossible time or leap second |
| anch::date::Time anch::date::rfc3339::parseTime | ( | std::string_view | text | ) |
Parse partial-time (fraction can have any number of digits: digits after the nanosecond are truncated)
| text | the text to parse |
| std::invalid_argument | invalid format, impossible time or leap second |
|
constexpr |
full-date string size: YYYY-MM-DD
|
constexpr |
Maximum date-time string size: YYYY-MM-DDTHH:MM:SS.nnnnnnnnn+HH:MM
|
constexpr |
Maximum full-time string size: HH:MM:SS.nnnnnnnnn+HH:MM
|
constexpr |
Maximum partial-time string size: HH:MM:SS.nnnnnnnnn