A growing implementation of time-related utilities for standards such as RFC 7231 (GMT) and RFC 3339 (Internet Date/Time Format). More...
Functions | |
| SOURCEMETA_CORE_TIME_EXPORT auto | sourcemeta::core::to_imf_fixdate (const std::chrono::system_clock::time_point time) -> std::string |
| SOURCEMETA_CORE_TIME_EXPORT auto | sourcemeta::core::from_imf_fixdate (const std::string_view value) noexcept -> std::optional< std::chrono::system_clock::time_point > |
| SOURCEMETA_CORE_TIME_EXPORT auto | sourcemeta::core::to_rfc850_date (const std::chrono::system_clock::time_point time) -> std::string |
| SOURCEMETA_CORE_TIME_EXPORT auto | sourcemeta::core::from_rfc850_date (const std::string_view value) noexcept -> std::optional< std::chrono::system_clock::time_point > |
| SOURCEMETA_CORE_TIME_EXPORT auto | sourcemeta::core::to_asctime (const std::chrono::system_clock::time_point time) -> std::string |
| SOURCEMETA_CORE_TIME_EXPORT auto | sourcemeta::core::from_asctime (const std::string_view value) noexcept -> std::optional< std::chrono::system_clock::time_point > |
| SOURCEMETA_CORE_TIME_EXPORT auto | sourcemeta::core::to_iso8601_basic (const std::chrono::system_clock::time_point time) -> std::string |
| SOURCEMETA_CORE_TIME_EXPORT auto | sourcemeta::core::from_iso8601_basic (const std::string_view value) noexcept -> std::optional< std::chrono::system_clock::time_point > |
| SOURCEMETA_CORE_TIME_EXPORT auto | sourcemeta::core::from_unix_timestamp (const std::chrono::duration< double > seconds) noexcept -> std::optional< std::chrono::system_clock::time_point > |
| SOURCEMETA_CORE_TIME_EXPORT auto | sourcemeta::core::to_unix_timestamp (const std::chrono::system_clock::time_point time) noexcept -> std::chrono::duration< double > |
| SOURCEMETA_CORE_TIME_EXPORT auto | sourcemeta::core::clock_shift_backward (const std::chrono::system_clock::time_point time, const std::chrono::seconds span) noexcept -> std::chrono::system_clock::time_point |
| SOURCEMETA_CORE_TIME_EXPORT auto | sourcemeta::core::clock_shift_forward (const std::chrono::system_clock::time_point time, const std::chrono::seconds span) noexcept -> std::chrono::system_clock::time_point |
| SOURCEMETA_CORE_TIME_EXPORT auto | sourcemeta::core::is_rfc3339_datetime (const std::string_view value) -> bool |
| SOURCEMETA_CORE_TIME_EXPORT auto | sourcemeta::core::is_rfc3339_fulldate (const std::string_view value) -> bool |
| SOURCEMETA_CORE_TIME_EXPORT auto | sourcemeta::core::is_rfc3339_fulltime (const std::string_view value) -> bool |
| SOURCEMETA_CORE_TIME_EXPORT auto | sourcemeta::core::is_rfc3339_partialtime_no_secfrac (const std::string_view value) -> bool |
| SOURCEMETA_CORE_TIME_EXPORT auto | sourcemeta::core::is_rfc3339_duration (const std::string_view value) -> bool |
| constexpr auto | sourcemeta::core::is_leap_year (const std::uint16_t year) -> bool |
| constexpr auto | sourcemeta::core::max_day_in_month (const std::uint8_t month, const std::uint16_t year) -> std::uint8_t |
A growing implementation of time-related utilities for standards such as RFC 7231 (GMT) and RFC 3339 (Internet Date/Time Format).
This functionality is included as follows:
|
noexcept |
Move a time point back by a span of seconds, saturating at the oldest instant the clock can represent instead of overflowing. A negative span is treated as no span at all. For example:
|
noexcept |
Move a time point forward by a span of seconds, saturating at the newest instant the clock can represent instead of overflowing. A negative span is treated as no span at all. For example:
|
noexcept |
Parse an RFC 9110 §5.6.7 asctime-date string into a time point. The format has no timezone token and is interpreted as GMT. The leading day-name is validated as a real weekday name but is not cross-checked against the calendar date, so a syntactically valid string whose day-name disagrees with its date is still accepted. RFC 9110 imposes no recipient requirement to reject such a string, the day-name is redundant with the date, and this matches how browsers and common clients behave. For example:
|
noexcept |
Parse an RFC 9110 §5.6.7 IMF-fixdate string into a time point. The leading day-name is validated as a real weekday name but is not cross-checked against the calendar date, so a syntactically valid string whose day-name disagrees with its date is still accepted. RFC 9110 imposes no recipient requirement to reject such a string, the day-name is redundant with the date, and this matches how browsers and common clients behave. For example:
|
noexcept |
Parse an ISO 8601 basic format UTC string (YYYYMMDDTHHMMSSZ) into a time point. For example:
|
noexcept |
Parse an RFC 850 date string into a time point. The two-digit year is interpreted per RFC 9110 §5.6.7. The leading day-name is validated as a real weekday name but is not cross-checked against the calendar date, so a syntactically valid string whose day-name disagrees with its date is still accepted. RFC 9110 imposes no recipient requirement to reject such a string, the day-name is redundant with the date, and this matches how browsers and common clients behave. For example:
|
noexcept |
Convert a POSIX timestamp, the number of seconds since the Unix epoch ignoring leap seconds and possibly fractional, into a time point, returning no value when the timestamp is not representable. Fractional seconds finer than the time point's tick resolution are truncated towards zero. For example:
|
inlineconstexpr |
Check whether the given year is a leap year per the Gregorian calendar (RFC 3339 Appendix C). For example:
| SOURCEMETA_CORE_TIME_EXPORT auto sourcemeta::core::is_rfc3339_datetime | ( | const std::string_view | value | ) | -> bool |
Check whether the given string is a valid date-time value per RFC 3339 Section 5.6 (Internet Date/Time Format). This implements the full date-time production rule:
where "T" may also be lowercase "t" (per RFC 3339 §5.6 NOTE). For example:
| SOURCEMETA_CORE_TIME_EXPORT auto sourcemeta::core::is_rfc3339_duration | ( | const std::string_view | value | ) | -> bool |
Check whether the given string is a valid duration value per RFC 3339 Appendix A (ISO 8601 Collected ABNF). This implements the duration production rule:
where dur-week is mutually exclusive with the date and time components. Only ASCII digits and uppercase unit letters are accepted; fractional values are not permitted by the RFC 3339 ABNF. For example:
| SOURCEMETA_CORE_TIME_EXPORT auto sourcemeta::core::is_rfc3339_fulldate | ( | const std::string_view | value | ) | -> bool |
Check whether the given string is a valid full-date value per RFC 3339 Section 5.6 (Internet Date/Time Format). This implements the full-date production rule:
with the day-of-month and leap year restrictions from RFC 3339 §5.7 and Appendix C. For example:
| SOURCEMETA_CORE_TIME_EXPORT auto sourcemeta::core::is_rfc3339_fulltime | ( | const std::string_view | value | ) | -> bool |
Check whether the given string is a valid full-time value per RFC 3339 Section 5.6 (Internet Date/Time Format). This implements the full-time production rule:
where "Z" may also be lowercase "z" (per RFC 3339 §5.6 NOTE). When time-second is 60 (leap second), only the UTC 23:59 alignment is verified; the §5.7 calendar restriction to June 30 or December 31 requires date context and is therefore out of scope. For example:
| SOURCEMETA_CORE_TIME_EXPORT auto sourcemeta::core::is_rfc3339_partialtime_no_secfrac | ( | const std::string_view | value | ) | -> bool |
Check whether the given string is a valid partial-time value per RFC 3339 Section 5.6 (Internet Date/Time Format), excluding the optional fractional seconds component. This implements the partial-time production rule without [time-secfrac]:
This matches the JSON Schema Draft 3 Time format (hh:mm:ss). For example:
|
inlineconstexpr |
Compute the maximum day-of-month for the given month and year per the Gregorian calendar. The month must be in the range 1-12. For example:
| SOURCEMETA_CORE_TIME_EXPORT auto sourcemeta::core::to_asctime | ( | const std::chrono::system_clock::time_point | time | ) | -> std::string |
Format a time point as an RFC 9110 §5.6.7 asctime-date string. The output matches the ANSI C asctime() field layout but omits the trailing newline that asctime() itself appends. For example:
| SOURCEMETA_CORE_TIME_EXPORT auto sourcemeta::core::to_imf_fixdate | ( | const std::chrono::system_clock::time_point | time | ) | -> std::string |
Format a time point as an RFC 9110 §5.6.7 IMF-fixdate string. For example:
| SOURCEMETA_CORE_TIME_EXPORT auto sourcemeta::core::to_iso8601_basic | ( | const std::chrono::system_clock::time_point | time | ) | -> std::string |
Format a time point as an ISO 8601 basic format UTC string (YYYYMMDDTHHMMSSZ). For example:
| SOURCEMETA_CORE_TIME_EXPORT auto sourcemeta::core::to_rfc850_date | ( | const std::chrono::system_clock::time_point | time | ) | -> std::string |
Format a time point as an RFC 850 date string. For example:
|
noexcept |
Convert a time point into a POSIX timestamp, the number of seconds since the Unix epoch ignoring leap seconds. For example: