From 4e426c19d08dceef7e25de6f98ad5239f96a783e Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 7 Nov 2020 09:47:56 -0800 Subject: [PATCH] Document chrono --- doc/api.rst | 28 ++++++++++++++++++++-------- doc/syntax.rst | 6 ++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/doc/api.rst b/doc/api.rst index 9b6c0f3c..67fad039 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -405,18 +405,30 @@ Using ``fmt::join``, you can separate tuple elements with a custom separator:: Date and Time Formatting ======================== -The library supports `strftime -`_-like date and time -formatting:: +``fmt/chrono.h`` provides formatters for + +* `std::chrono::duration `_ +* `std::chrono::time_point `_ +* `std::tm `_ + +For example:: #include - std::time_t t = std::time(nullptr); - // Prints "The date is 2016-04-29." (with the current date) - fmt::print("The date is {:%Y-%m-%d}.", fmt::localtime(t)); + int main() { + using namespace std::literals::chrono_literals; + fmt::print("Default format: {} {}\n", 42s, 100ms); + fmt::print("strftime-like format: {:%H:%M:%S}\n", 3h + 15min + 30s); + } -The format string syntax is described in the documentation of -`strftime `_. +prints:: + + Default format: 42s 100ms + strftime-like format: 03:15:30 + +Chrono format specifications are described in :ref:`chrono-specs`. + +.. doxygenclass:: formatter, Char> .. _compile-api: diff --git a/doc/syntax.rst b/doc/syntax.rst index 4f859cf6..8557dd4b 100644 --- a/doc/syntax.rst +++ b/doc/syntax.rst @@ -321,6 +321,12 @@ Format specifications for chrono types have the following syntax: : "q" | "Q" | "r" | "R" | "S" | "t" | "T" | "u" | "U" | "V" | : "w" | "W" | "x" | "X" | "y" | "Y" | "z" | "Z" | "%" | +Literal chars are copied unchanged to the output. Precision is valid only for +``std::chrono::duration`` types with a floating-point representation type. + +*conversion_spec* are conversion specifiers documented in `strftime +`_. + .. _formatexamples: Format Examples