AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::date::rfc3339 Namespace Reference

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

Detailed Description

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.

Author
Vincent Lachenal
Since
0.2

Enumeration Type Documentation

◆ Offset

enum class anch::date::rfc3339::Offset
strong

Offset used to format date-time.

Since
0.2
Enumerator
UTC 

UTC time, with Z offset

LOCAL 

Local time (follows TZ environment variable), with its numeric offset (+02:00 for example) ; historic offsets with seconds are truncated to the minute (written time is shifted, the point in time is preserved)

Function Documentation

◆ formatDate() [1/2]

std::string anch::date::rfc3339::formatDate ( const anch::date::Date & date)

Format full-date

Parameters
datethe date to format
Returns
the formatted date
Here is the call graph for this function:

◆ formatDate() [2/2]

std::size_t anch::date::rfc3339::formatDate ( const anch::date::Date & date,
char * output )
noexcept

Format full-date

Parameters
datethe date to format
outputthe output buffer (at least DATE_SIZE characters ; not '\0' terminated)
Returns
the number of characters written (DATE_SIZE )
Here is the call graph for this function:

◆ formatDateTime() [1/2]

std::size_t anch::date::rfc3339::formatDateTime ( const anch::date::DateTime & date,
char * output,
Offset offset = Offset::UTC )
noexcept

Format date-time .
Fraction is written with the number of digits needed by the date: none, 3, 6 or 9.

Parameters
datethe date to format
outputthe output buffer (at least DATE_TIME_MAX_SIZE characters ; not '\0' terminated)
offsetthe offset to use (default UTC)
Returns
the number of characters written
Here is the call graph for this function:

◆ formatDateTime() [2/2]

std::string anch::date::rfc3339::formatDateTime ( const anch::date::DateTime & date,
Offset offset = Offset::UTC )

Format date-time

Parameters
datethe date to format
offsetthe offset to use (default UTC)
Returns
the formatted date
Here is the call graph for this function:

◆ formatFullTime() [1/2]

std::string anch::date::rfc3339::formatFullTime ( const anch::date::OffsetTime & time)

Format full-time

Parameters
timethe time to format
Returns
the formatted time
Since
0.3
Here is the call graph for this function:

◆ formatFullTime() [2/2]

std::size_t anch::date::rfc3339::formatFullTime ( const anch::date::OffsetTime & time,
char * output )
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.

Parameters
timethe time to format
outputthe output buffer (at least FULL_TIME_MAX_SIZE characters ; not '\0' terminated)
Returns
the number of characters written
Since
0.3
Here is the call graph for this function:

◆ formatTime() [1/2]

std::string anch::date::rfc3339::formatTime ( const anch::date::Time & time)

Format partial-time

Parameters
timethe time to format
Returns
the formatted time
Since
0.3
Here is the call graph for this function:

◆ formatTime() [2/2]

std::size_t anch::date::rfc3339::formatTime ( const anch::date::Time & time,
char * output )
noexcept

Format partial-time .
Fraction is written with the number of digits needed by the time: none, 3, 6 or 9.

Parameters
timethe time to format
outputthe output buffer (at least TIME_MAX_SIZE characters ; not '\0' terminated)
Returns
the number of characters written
Since
0.3
Here is the call graph for this function:

◆ parseDate()

anch::date::Date anch::date::rfc3339::parseDate ( std::string_view text)

Parse full-date

Parameters
textthe text to parse
Returns
the date
Exceptions
std::invalid_argumentinvalid format or impossible date
Here is the call graph for this function:

◆ parseDateTime()

anch::date::DateTime anch::date::rfc3339::parseDateTime ( std::string_view text)

Parse date-time

Parameters
textthe text to parse
Returns
the date
Exceptions
std::invalid_argumentinvalid format, impossible date or point in time out of anch::date::DateTime range (years 1678 to 2261)
Here is the call graph for this function:

◆ parseFullTime()

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)

Parameters
textthe text to parse
Returns
the time
Exceptions
std::invalid_argumentinvalid format (offset is required), impossible time or leap second
Since
0.3
Here is the call graph for this function:

◆ parseTime()

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)

Parameters
textthe text to parse
Returns
the time
Exceptions
std::invalid_argumentinvalid format, impossible time or leap second
Since
0.3
Here is the call graph for this function:

Variable Documentation

◆ DATE_SIZE

std::size_t anch::date::rfc3339::DATE_SIZE = 10
constexpr

full-date string size: YYYY-MM-DD

◆ DATE_TIME_MAX_SIZE

std::size_t anch::date::rfc3339::DATE_TIME_MAX_SIZE = 35
constexpr

Maximum date-time string size: YYYY-MM-DDTHH:MM:SS.nnnnnnnnn+HH:MM

◆ FULL_TIME_MAX_SIZE

std::size_t anch::date::rfc3339::FULL_TIME_MAX_SIZE = 24
constexpr

Maximum full-time string size: HH:MM:SS.nnnnnnnnn+HH:MM

◆ TIME_MAX_SIZE

std::size_t anch::date::rfc3339::TIME_MAX_SIZE = 18
constexpr

Maximum partial-time string size: HH:MM:SS.nnnnnnnnn