DateTime string formatter and parser More...
#include <dateFormatter.hpp>
Public Member Functions | |
| DateFormatter (const std::string &dateFormat) | |
| DateFormatter (const DateFormatter &)=delete | |
| DateFormatter (DateFormatter &&) noexcept=default | |
| virtual | ~DateFormatter () noexcept |
| void | format (const anch::date::DateTime &date, std::string &output) const noexcept |
| void | format (const anch::date::DateTime &date, std::ostream &output) const noexcept |
| void | parse (const std::string &strDate, anch::date::DateTime &date) const |
| anch::date::DateTime | parse (const std::string &strDate) const |
Static Public Member Functions | |
| static void | registerFormatterPart (const std::string &pattern, getInstance instGetter) noexcept |
DateTime string formatter and parser
Patterns are:
strptime )strptime %I ; 12 for noon and midnight)Other characters, and unknown patterns, are written as is. Other patterns can be registered with registerFormatterPart .
Parsing requires every field to have its exact size (no sign, no space) ; fields which are not in the pattern are set to 1970-01-01 00:00:00.000 local time ; impossible dates (2025-02-30 for example) are refused.
format and parse can be called concurrently. Formatter parts have to be registered before formatters which use them are built.
|
explicit |
DateFormatter constructor
| dateFormat | the date format |
|
delete |
|
defaultnoexcept |
|
virtualnoexcept |
|
noexcept |
Format date
| date | the date to format |
| output | the output stream |
|
noexcept |
Format date
| date | the date to format |
| output | the output string |
| anch::date::DateTime anch::date::DateFormatter::parse | ( | const std::string & | strDate | ) | const |
Build date from string
| strDate | string formatted date |
| std::invalid_argument | invalid format, impossible date or date out of range (years 1678 to 2261) |
| void anch::date::DateFormatter::parse | ( | const std::string & | strDate, |
| anch::date::DateTime & | date ) const |
Build date from string
| strDate | string formatted date |
| date | the output date (all its fields are set) |
| std::invalid_argument | invalid format, impossible date or date out of range (years 1678 to 2261) |
|
staticnoexcept |
Register a new formatter part (when pattern has not already been registered)
| pattern | the formatter part pattern ('%' followed by one character) |
| instGetter | the formatter part new instance getter |