- tmp/tmpu4zciyft/{from.md → to.md} +167 -55
tmp/tmpu4zciyft/{from.md → to.md}
RENAMED
|
@@ -19,16 +19,14 @@ summarized in [[time.summary]].
|
|
| 19 |
| [[time.hms]] | Class template `hh_mm_ss` | |
|
| 20 |
| [[time.12]] | 12/24 hour functions | |
|
| 21 |
| [[time.zone]] | Time zones | |
|
| 22 |
| [[time.format]] | Formatting | |
|
| 23 |
| [[time.parse]] | Parsing | |
|
|
|
|
| 24 |
| [[ctime.syn]] | C library time utilities | `<ctime>` |
|
| 25 |
|
| 26 |
|
| 27 |
-
Let *`STATICALLY-WIDEN`*`<charT>("...")` be `"..."` if `charT` is `char`
|
| 28 |
-
and `L"..."` if `charT` is `wchar_t`.
|
| 29 |
-
|
| 30 |
## Header `<chrono>` synopsis <a id="time.syn">[[time.syn]]</a>
|
| 31 |
|
| 32 |
``` cpp
|
| 33 |
#include <compare> // see [compare.syn]
|
| 34 |
|
|
@@ -907,10 +905,35 @@ namespace std::inline literals::inline chrono_literals {
|
|
| 907 |
}
|
| 908 |
|
| 909 |
namespace std::chrono {
|
| 910 |
using namespace literals::chrono_literals;
|
| 911 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 912 |
```
|
| 913 |
|
| 914 |
## *Cpp17Clock* requirements <a id="time.clock.req">[[time.clock.req]]</a>
|
| 915 |
|
| 916 |
A clock is a bundle consisting of a `duration`, a `time_point`, and a
|
|
@@ -928,11 +951,11 @@ calls occur before `C1::time_point::max()`.
|
|
| 928 |
|
| 929 |
[*Note 2*: The relative difference in durations between those reported
|
| 930 |
by a given clock and the SI definition is a measure of the quality of
|
| 931 |
implementation. — *end note*]
|
| 932 |
|
| 933 |
-
A type `TC` meets the
|
| 934 |
|
| 935 |
- `TC` meets the *Cpp17Clock* requirements,
|
| 936 |
- the types `TC::rep`, `TC::duration`, and `TC::time_point` meet the
|
| 937 |
*Cpp17EqualityComparable* ([[cpp17.equalitycomparable]]) and
|
| 938 |
*Cpp17LessThanComparable* ([[cpp17.lessthancomparable]]) and
|
|
@@ -1085,11 +1108,11 @@ as a rational constant using the template `ratio`.
|
|
| 1085 |
namespace std::chrono {
|
| 1086 |
template<class Rep, class Period = ratio<1>>
|
| 1087 |
class duration {
|
| 1088 |
public:
|
| 1089 |
using rep = Rep;
|
| 1090 |
-
using period =
|
| 1091 |
|
| 1092 |
private:
|
| 1093 |
rep rep_; // exposition only
|
| 1094 |
|
| 1095 |
public:
|
|
@@ -1138,13 +1161,14 @@ If `Period` is not a specialization of `ratio`, the program is
|
|
| 1138 |
ill-formed. If `Period::num` is not positive, the program is ill-formed.
|
| 1139 |
|
| 1140 |
Members of `duration` do not throw exceptions other than those thrown by
|
| 1141 |
the indicated operations on their representations.
|
| 1142 |
|
| 1143 |
-
The defaulted copy constructor of duration shall be a constexpr
|
| 1144 |
-
if and only if the required initialization of the member `rep_`
|
| 1145 |
-
and move, respectively, would be constexpr-suitable
|
|
|
|
| 1146 |
|
| 1147 |
[*Example 1*:
|
| 1148 |
|
| 1149 |
``` cpp
|
| 1150 |
duration<long, ratio<60>> d0; // holds a count of minutes using a long
|
|
@@ -1169,11 +1193,11 @@ template<class Rep2>
|
|
| 1169 |
|
| 1170 |
[*Example 1*:
|
| 1171 |
|
| 1172 |
``` cpp
|
| 1173 |
duration<int, milli> d(3); // OK
|
| 1174 |
-
duration<int, milli>
|
| 1175 |
```
|
| 1176 |
|
| 1177 |
— *end example*]
|
| 1178 |
|
| 1179 |
*Effects:* Initializes `rep_` with `r`.
|
|
@@ -1708,12 +1732,12 @@ namespace std::chrono {
|
|
| 1708 |
template<class Clock, class Duration = typename Clock::duration>
|
| 1709 |
class time_point {
|
| 1710 |
public:
|
| 1711 |
using clock = Clock;
|
| 1712 |
using duration = Duration;
|
| 1713 |
-
using rep =
|
| 1714 |
-
using period =
|
| 1715 |
|
| 1716 |
private:
|
| 1717 |
duration d_; // exposition only
|
| 1718 |
|
| 1719 |
public:
|
|
@@ -2992,11 +3016,11 @@ the above list, there is a unique best expression.
|
|
| 2992 |
*Returns:* The best well-formed clock time conversion expression in the
|
| 2993 |
above list.
|
| 2994 |
|
| 2995 |
## The civil calendar <a id="time.cal">[[time.cal]]</a>
|
| 2996 |
|
| 2997 |
-
###
|
| 2998 |
|
| 2999 |
The types in [[time.cal]] describe the civil (Gregorian) calendar and
|
| 3000 |
its relationship to `sys_days` and `local_days`.
|
| 3001 |
|
| 3002 |
### Class `last_spec` <a id="time.cal.last">[[time.cal.last]]</a>
|
|
@@ -5628,12 +5652,11 @@ The year, month, and day are accepted in any of the following 3 orders:
|
|
| 5628 |
year/month/day
|
| 5629 |
month/day/year
|
| 5630 |
day/month/year
|
| 5631 |
```
|
| 5632 |
|
| 5633 |
-
Anywhere a `day` is
|
| 5634 |
-
specified:
|
| 5635 |
|
| 5636 |
``` cpp
|
| 5637 |
last
|
| 5638 |
weekday[i]
|
| 5639 |
weekday[last]
|
|
@@ -6181,11 +6204,11 @@ hour. Otherwise, returns the 24-hour equivalent of `h` in the range
|
|
| 6181 |
\[`12h`, `23h`\], assuming `h` represents a post meridiem hour. If `h`
|
| 6182 |
is not in the range \[`1h`, `12h`\], the value returned is unspecified.
|
| 6183 |
|
| 6184 |
## Time zones <a id="time.zone">[[time.zone]]</a>
|
| 6185 |
|
| 6186 |
-
###
|
| 6187 |
|
| 6188 |
[[time.zone]] describes an interface for accessing the IANA Time Zone
|
| 6189 |
Database that interoperates with `sys_time` and `local_time`. This
|
| 6190 |
interface provides time zone support to both the civil calendar types
|
| 6191 |
[[time.cal]] and to user-defined calendars.
|
|
@@ -7193,11 +7216,11 @@ database when initialized.
|
|
| 7193 |
|
| 7194 |
[*Example 1*:
|
| 7195 |
|
| 7196 |
``` cpp
|
| 7197 |
for (auto& l : get_tzdb().leap_seconds)
|
| 7198 |
-
if (l <= 2018y/March/17d)
|
| 7199 |
cout << l.date() << ": " << l.value() << '\n';
|
| 7200 |
```
|
| 7201 |
|
| 7202 |
Produces the output:
|
| 7203 |
|
|
@@ -7446,11 +7469,11 @@ function, defined as
|
|
| 7446 |
- the locale passed to the formatting function if any, otherwise
|
| 7447 |
- the global locale.
|
| 7448 |
|
| 7449 |
Each conversion specifier *conversion-spec* is replaced by appropriate
|
| 7450 |
characters as described in [[time.format.spec]]; the formats specified
|
| 7451 |
-
in ISO 8601:
|
| 7452 |
conversion specifiers depend on the formatting locale. If the string
|
| 7453 |
literal encoding is a Unicode encoding form and the locale is among an
|
| 7454 |
*implementation-defined* set of locales, each replacement that depends
|
| 7455 |
on the locale is performed as if the replacement character sequence is
|
| 7456 |
converted to the string literal encoding. If the formatted object does
|
|
@@ -7505,16 +7528,16 @@ day elapsed since midnight.
|
|
| 7505 |
| `%C` | The year divided by 100 using floored division. If the result is a single decimal digit, it is prefixed with `0`. The modified command `%EC` produces the locale's alternative representation of the century. |
|
| 7506 |
| `%d` | The day of month as a decimal number. If the result is a single decimal digit, it is prefixed with `0`. The modified command `%Od` produces the locale's alternative representation. |
|
| 7507 |
| `%D` | Equivalent to `%m/%d/%y`. |
|
| 7508 |
| `%e` | The day of month as a decimal number. If the result is a single decimal digit, it is prefixed with a space. The modified command `%Oe` produces the locale's alternative representation. |
|
| 7509 |
| `%F` | Equivalent to `%Y-%m-%d`. |
|
| 7510 |
-
| `%g` | The last two decimal digits of the ISO
|
| 7511 |
-
| `%G` | The
|
| 7512 |
| `%h` | Equivalent to `%b`. |
|
| 7513 |
| `%H` | The hour (24-hour clock) as a decimal number. If the result is a single digit, it is prefixed with `0`. The modified command `%OH` produces the locale's alternative representation. |
|
| 7514 |
| `%I` | The hour (12-hour clock) as a decimal number. If the result is a single digit, it is prefixed with `0`. The modified command `%OI` produces the locale's alternative representation. |
|
| 7515 |
-
| `%j` | If the type being formatted is a specialization of `duration`, the decimal number of `days` without padding. Otherwise, the day of the year as a decimal number.
|
| 7516 |
| `%m` | The month as a decimal number. Jan is `01`. If the result is a single digit, it is prefixed with `0`. The modified command `%Om` produces the locale's alternative representation. |
|
| 7517 |
| `%M` | The minute as a decimal number. If the result is a single digit, it is prefixed with `0`. The modified command `%OM` produces the locale's alternative representation. |
|
| 7518 |
| `%n` | A new-line character. |
|
| 7519 |
| `%p` | The locale's equivalent of the AM/PM designations associated with a 12-hour clock. |
|
| 7520 |
| `%q` | The duration's unit suffix as specified in [[time.duration.io]]. |
|
|
@@ -7522,38 +7545,58 @@ day elapsed since midnight.
|
|
| 7522 |
| `%r` | The locale's 12-hour clock time. |
|
| 7523 |
| `%R` | Equivalent to `%H:%M`. |
|
| 7524 |
| `%S` | Seconds as a decimal number. If the number of seconds is less than `10`, the result is prefixed with `0`. If the precision of the input cannot be exactly represented with seconds, then the format is a decimal floating-point number with a fixed format and a precision matching that of the precision of the input (or to a microseconds precision if the conversion to floating-point decimal seconds cannot be made within 18 fractional digits). The character for the decimal point is localized according to the locale. The modified command `%OS` produces the locale's alternative representation. |
|
| 7525 |
| `%t` | A horizontal-tab character. |
|
| 7526 |
| `%T` | Equivalent to `%H:%M:%S`. |
|
| 7527 |
-
| `%u` | The
|
| 7528 |
| `%U` | The week number of the year as a decimal number. The first Sunday of the year is the first day of week `01`. Days of the same year prior to that are in week `00`. If the result is a single digit, it is prefixed with `0`. The modified command `%OU` produces the locale's alternative representation. |
|
| 7529 |
-
| `%V` | The
|
| 7530 |
| `%w` | The weekday as a decimal number (`0`-`6`), where Sunday is `0`. The modified command `%Ow` produces the locale's alternative representation. |
|
| 7531 |
| `%W` | The week number of the year as a decimal number. The first Monday of the year is the first day of week `01`. Days of the same year prior to that are in week `00`. If the result is a single digit, it is prefixed with `0`. The modified command `%OW` produces the locale's alternative representation. |
|
| 7532 |
| `%x` | The locale's date representation. The modified command `%Ex` produces the locale's alternate date representation. |
|
| 7533 |
| `%X` | The locale's time representation. The modified command `%EX` produces the locale's alternate time representation. |
|
| 7534 |
-
| `%y` | The last two decimal digits of the year. If the result is a single digit it is prefixed by `0`. The modified command `%Oy` produces the locale's alternative representation. The modified command `%Ey` produces the locale's alternative representation of offset from `%EC` (year only).
|
| 7535 |
-
| `%Y` | The year as a decimal number. If the result is less than four digits it is left-padded with `0` to four digits. The modified command `%EY` produces the locale's alternative full year representation.
|
| 7536 |
-
| `%z` | The offset from UTC
|
| 7537 |
| `%Z` | The time zone abbreviation. If the time zone abbreviation is not available, an exception of type `format_error` is thrown. |
|
| 7538 |
| `%%` | A `%` character. |
|
| 7539 |
|
| 7540 |
|
| 7541 |
-
|
| 7542 |
-
|
| 7543 |
-
|
| 7544 |
-
|
| 7545 |
-
|
|
|
|
| 7546 |
|
| 7547 |
[*Example 3*:
|
| 7548 |
|
| 7549 |
``` cpp
|
| 7550 |
string s = format("{:=>8}", 42ms); // value of s is "====42ms"
|
| 7551 |
```
|
| 7552 |
|
| 7553 |
— *end example*]
|
| 7554 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7555 |
``` cpp
|
| 7556 |
template<class Duration, class charT>
|
| 7557 |
struct formatter<chrono::sys_time<Duration>, charT>;
|
| 7558 |
```
|
| 7559 |
|
|
@@ -7648,23 +7691,24 @@ template<class Duration, class charT>
|
|
| 7648 |
```
|
| 7649 |
|
| 7650 |
Let `f` be a *`local-time-format-t`*`<Duration>` object passed to
|
| 7651 |
`formatter::format`.
|
| 7652 |
|
| 7653 |
-
*Remarks:* If
|
| 7654 |
-
`
|
| 7655 |
-
is a null pointer value
|
| 7656 |
-
|
| 7657 |
-
|
| 7658 |
-
|
| 7659 |
-
`f.offset_sec` is a null pointer value
|
| 7660 |
-
`
|
|
|
|
| 7661 |
|
| 7662 |
``` cpp
|
| 7663 |
template<class Duration, class TimeZonePtr, class charT>
|
| 7664 |
struct formatter<chrono::zoned_time<Duration, TimeZonePtr>, charT>
|
| 7665 |
-
: formatter<chrono::local-time-format-t<Duration>, charT> {
|
| 7666 |
template<class FormatContext>
|
| 7667 |
typename FormatContext::iterator
|
| 7668 |
format(const chrono::zoned_time<Duration, TimeZonePtr>& tp, FormatContext& ctx) const;
|
| 7669 |
};
|
| 7670 |
```
|
|
@@ -7677,18 +7721,18 @@ template<class FormatContext>
|
|
| 7677 |
|
| 7678 |
*Effects:* Equivalent to:
|
| 7679 |
|
| 7680 |
``` cpp
|
| 7681 |
sys_info info = tp.get_info();
|
| 7682 |
-
return formatter<chrono::local-time-format-t<Duration>, charT>::
|
| 7683 |
format({tp.get_local_time(), &info.abbrev, &info.offset}, ctx);
|
| 7684 |
```
|
| 7685 |
|
| 7686 |
## Parsing <a id="time.parse">[[time.parse]]</a>
|
| 7687 |
|
| 7688 |
Each `parse` overload specified in this subclause calls `from_stream`
|
| 7689 |
-
unqualified, so as to enable argument
|
| 7690 |
[[basic.lookup.argdep]]. In the following paragraphs, let `is` denote an
|
| 7691 |
object of type `basic_istream<charT, traits>` and let `I` be
|
| 7692 |
`basic_istream<charT, traits>&`, where `charT` and `traits` are template
|
| 7693 |
parameters in that context.
|
| 7694 |
|
|
@@ -7854,28 +7898,28 @@ complete duration, time point, or calendrical data structure,
|
|
| 7854 |
| `%C` | The century as a decimal number. The modified command `%*N*C` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command `%EC` interprets the locale's alternative representation of the century. |
|
| 7855 |
| `%d` | The day of the month as a decimal number. The modified command `%*N*d` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command `%Od` interprets the locale's alternative representation of the day of the month. |
|
| 7856 |
| `%D` | Equivalent to `%m/%d/%y`. |
|
| 7857 |
| `%e` | Equivalent to `%d` and can be modified like `%d`. |
|
| 7858 |
| `%F` | Equivalent to `%Y-%m-%d`. If modified with a width `*N*`, the width is applied to only `%Y`. |
|
| 7859 |
-
| `%g` | The last two decimal digits of the ISO
|
| 7860 |
-
| `%G` | The
|
| 7861 |
| `%h` | Equivalent to `%b`. |
|
| 7862 |
| `%H` | The hour (24-hour clock) as a decimal number. The modified command `%*N*H` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command `%OH` interprets the locale's alternative representation. |
|
| 7863 |
| `%I` | The hour (12-hour clock) as a decimal number. The modified command `%*N*I` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command `%OI` interprets the locale's alternative representation. |
|
| 7864 |
-
| `%j` | If the type being parsed is a specialization of `duration`, a decimal number of `days`. Otherwise, the day of the year as a decimal number.
|
| 7865 |
-
| `%m` | The month as a decimal number.
|
| 7866 |
| `%M` | The minutes as a decimal number. The modified command `%*N*M` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command `%OM` interprets the locale's alternative representation. |
|
| 7867 |
| `%n` | Matches one whitespace character. *`%n`, `%t`, and a space can be combined to match a wide range of whitespace patterns. For example, `"%n "` matches one or more whitespace characters, and `"%n%t%t"` matches one to three whitespace characters.* |
|
| 7868 |
| `%p` | The locale's equivalent of the AM/PM designations associated with a 12-hour clock. |
|
| 7869 |
| `%r` | The locale's 12-hour clock time. |
|
| 7870 |
| `%R` | Equivalent to `%H:%M`. |
|
| 7871 |
| `%S` | The seconds as a decimal number. The modified command `%*N*S` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2 if the input time has a precision convertible to seconds. Otherwise the default width is determined by the decimal precision of the input and the field is interpreted as a `long double` in a fixed format. If encountered, the locale determines the decimal point character. Leading zeroes are permitted but not required. The modified command `%OS` interprets the locale's alternative representation. |
|
| 7872 |
| `%t` | Matches zero or one whitespace characters. |
|
| 7873 |
| `%T` | Equivalent to `%H:%M:%S`. |
|
| 7874 |
-
| `%u` | The
|
| 7875 |
| `%U` | The week number of the year as a decimal number. The first Sunday of the year is the first day of week `01`. Days of the same year prior to that are in week `00`. The modified command `%*N*U` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command `%OU` interprets the locale's alternative representation. |
|
| 7876 |
-
| `%V` | The
|
| 7877 |
| `%w` | The weekday as a decimal number (`0`-`6`), where Sunday is `0`. The modified command `%*N*w` specifies the maximum number of characters to read. If `*N*` is not specified, the default is `1`. Leading zeroes are permitted but not required. The modified command `%Ow` interprets the locale's alternative representation. |
|
| 7878 |
| `%W` | The week number of the year as a decimal number. The first Monday of the year is the first day of week `01`. Days of the same year prior to that are in week `00`. The modified command `%*N*W` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command `%OW` interprets the locale's alternative representation. |
|
| 7879 |
| `%x` | The locale's date representation. The modified command `%Ex` interprets the locale's alternate date representation. |
|
| 7880 |
| `%X` | The locale's time representation. The modified command `%EX` interprets the locale's alternate time representation. |
|
| 7881 |
| `%y` | The last two decimal digits of the year. If the century is not otherwise specified (e.g., with `%C`), values in the range {[}`69`, `99`{]} are presumed to refer to the years 1969 to 1999, and values in the range {[}`00`, `68`{]} are presumed to refer to the years 2000 to 2068. The modified command `%*N*y` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. The modified commands `%Ey` and `%Oy` interpret the locale's alternative representation. |
|
|
@@ -7883,16 +7927,80 @@ complete duration, time point, or calendrical data structure,
|
|
| 7883 |
| `%z` | The offset from UTC in the format `[+|-]hh[mm]`. For example `-0430` refers to 4 hours 30 minutes behind UTC, and `04` refers to 4 hours ahead of UTC. The modified commands `%Ez` and `%Oz` parse a `:` between the hours and minutes and render leading zeroes on the hour field optional: `[+|-]h[h][:mm]`. For example `-04:30` refers to 4 hours 30 minutes behind UTC, and `4` refers to 4 hours ahead of UTC. |
|
| 7884 |
| `%Z` | The time zone abbreviation or name. A single word is parsed. This word can only contain characters from the basic character set [[lex.charset]] that are alphanumeric, or one of `'_'`, `'/'`, `'-'`, or `'+'`. |
|
| 7885 |
| `%%` | A `%` character is extracted. |
|
| 7886 |
|
| 7887 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7888 |
## Header `<ctime>` synopsis <a id="ctime.syn">[[ctime.syn]]</a>
|
| 7889 |
|
| 7890 |
``` cpp
|
|
|
|
|
|
|
| 7891 |
#define NULL see [support.types.nullptr]
|
| 7892 |
#define CLOCKS_PER_SEC see below
|
| 7893 |
#define TIME_UTC see below
|
|
|
|
|
|
|
|
|
|
| 7894 |
|
| 7895 |
namespace std {
|
| 7896 |
using size_t = see [support.types.layout];
|
| 7897 |
using clock_t = see below;
|
| 7898 |
using time_t = see below;
|
|
@@ -7901,38 +8009,40 @@ namespace std {
|
|
| 7901 |
struct tm;
|
| 7902 |
|
| 7903 |
clock_t clock();
|
| 7904 |
double difftime(time_t time1, time_t time0);
|
| 7905 |
time_t mktime(tm* timeptr);
|
|
|
|
| 7906 |
time_t time(time_t* timer);
|
| 7907 |
int timespec_get(timespec* ts, int base);
|
| 7908 |
-
|
| 7909 |
-
char* ctime(const time_t* timer);
|
| 7910 |
tm* gmtime(const time_t* timer);
|
|
|
|
| 7911 |
tm* localtime(const time_t* timer);
|
|
|
|
| 7912 |
size_t strftime(char* s, size_t maxsize, const char* format, const tm* timeptr);
|
| 7913 |
}
|
| 7914 |
```
|
| 7915 |
|
| 7916 |
The contents of the header `<ctime>` are the same as the C standard
|
| 7917 |
library header `<time.h>`.[^1]
|
| 7918 |
|
| 7919 |
-
The functions `
|
| 7920 |
-
|
| 7921 |
|
| 7922 |
-
See also: ISO C 7.
|
| 7923 |
|
| 7924 |
<!-- Link reference definitions -->
|
| 7925 |
[basic.lookup.argdep]: basic.md#basic.lookup.argdep
|
| 7926 |
[cpp17.equalitycomparable]: #cpp17.equalitycomparable
|
| 7927 |
[cpp17.lessthancomparable]: #cpp17.lessthancomparable
|
| 7928 |
[ctime.syn]: #ctime.syn
|
| 7929 |
[dcl.constexpr]: dcl.md#dcl.constexpr
|
| 7930 |
[filesystems]: input.md#filesystems
|
| 7931 |
-
[format.formatter]:
|
| 7932 |
-
[format.string]:
|
| 7933 |
-
[formatter.requirements]:
|
| 7934 |
[intro.multithread]: basic.md#intro.multithread
|
| 7935 |
[lex.charset]: lex.md#lex.charset
|
| 7936 |
[meta.rqmts]: meta.md#meta.rqmts
|
| 7937 |
[numeric.requirements]: numerics.md#numeric.requirements
|
| 7938 |
[over.ics.rank]: over.md#over.ics.rank
|
|
@@ -8050,10 +8160,11 @@ See also: ISO C 7.27
|
|
| 8050 |
[time.duration.observer]: #time.duration.observer
|
| 8051 |
[time.duration.special]: #time.duration.special
|
| 8052 |
[time.format]: #time.format
|
| 8053 |
[time.format.spec]: #time.format.spec
|
| 8054 |
[time.general]: #time.general
|
|
|
|
| 8055 |
[time.hms]: #time.hms
|
| 8056 |
[time.hms.members]: #time.hms.members
|
| 8057 |
[time.hms.nonmembers]: #time.hms.nonmembers
|
| 8058 |
[time.hms.overview]: #time.hms.overview
|
| 8059 |
[time.hms.width]: #time.hms.width
|
|
@@ -8104,9 +8215,10 @@ See also: ISO C 7.27
|
|
| 8104 |
[time.zone.zonedtime.ctor]: #time.zone.zonedtime.ctor
|
| 8105 |
[time.zone.zonedtime.members]: #time.zone.zonedtime.members
|
| 8106 |
[time.zone.zonedtime.nonmembers]: #time.zone.zonedtime.nonmembers
|
| 8107 |
[time.zone.zonedtime.overview]: #time.zone.zonedtime.overview
|
| 8108 |
[time.zone.zonedtraits]: #time.zone.zonedtraits
|
|
|
|
| 8109 |
|
| 8110 |
[^1]: `strftime` supports the C conversion specifiers `C`, `D`, `e`,
|
| 8111 |
`F`, `g`, `G`, `h`, `r`, `R`, `t`, `T`, `u`, `V`, and `z`, and the
|
| 8112 |
modifiers `E` and `O`.
|
|
|
|
| 19 |
| [[time.hms]] | Class template `hh_mm_ss` | |
|
| 20 |
| [[time.12]] | 12/24 hour functions | |
|
| 21 |
| [[time.zone]] | Time zones | |
|
| 22 |
| [[time.format]] | Formatting | |
|
| 23 |
| [[time.parse]] | Parsing | |
|
| 24 |
+
| [[time.hash]] | Hash support | |
|
| 25 |
| [[ctime.syn]] | C library time utilities | `<ctime>` |
|
| 26 |
|
| 27 |
|
|
|
|
|
|
|
|
|
|
| 28 |
## Header `<chrono>` synopsis <a id="time.syn">[[time.syn]]</a>
|
| 29 |
|
| 30 |
``` cpp
|
| 31 |
#include <compare> // see [compare.syn]
|
| 32 |
|
|
|
|
| 905 |
}
|
| 906 |
|
| 907 |
namespace std::chrono {
|
| 908 |
using namespace literals::chrono_literals;
|
| 909 |
}
|
| 910 |
+
|
| 911 |
+
namespace std {
|
| 912 |
+
// [time.hash], hash support
|
| 913 |
+
template<class T> struct hash;
|
| 914 |
+
template<class Rep, class Period> struct hash<chrono::duration<Rep, Period>>;
|
| 915 |
+
template<class Clock, class Duration> struct hash<chrono::time_point<Clock, Duration>>;
|
| 916 |
+
template<> struct hash<chrono::day>;
|
| 917 |
+
template<> struct hash<chrono::month>;
|
| 918 |
+
template<> struct hash<chrono::year>;
|
| 919 |
+
template<> struct hash<chrono::weekday>;
|
| 920 |
+
template<> struct hash<chrono::weekday_indexed>;
|
| 921 |
+
template<> struct hash<chrono::weekday_last>;
|
| 922 |
+
template<> struct hash<chrono::month_day>;
|
| 923 |
+
template<> struct hash<chrono::month_day_last>;
|
| 924 |
+
template<> struct hash<chrono::month_weekday>;
|
| 925 |
+
template<> struct hash<chrono::month_weekday_last>;
|
| 926 |
+
template<> struct hash<chrono::year_month>;
|
| 927 |
+
template<> struct hash<chrono::year_month_day>;
|
| 928 |
+
template<> struct hash<chrono::year_month_day_last>;
|
| 929 |
+
template<> struct hash<chrono::year_month_weekday>;
|
| 930 |
+
template<> struct hash<chrono::year_month_weekday_last>;
|
| 931 |
+
template<class Duration, class TimeZonePtr>
|
| 932 |
+
struct hash<chrono::zoned_time<Duration, TimeZonePtr>>;
|
| 933 |
+
template<> struct hash<chrono::leap_second>;
|
| 934 |
+
}
|
| 935 |
```
|
| 936 |
|
| 937 |
## *Cpp17Clock* requirements <a id="time.clock.req">[[time.clock.req]]</a>
|
| 938 |
|
| 939 |
A clock is a bundle consisting of a `duration`, a `time_point`, and a
|
|
|
|
| 951 |
|
| 952 |
[*Note 2*: The relative difference in durations between those reported
|
| 953 |
by a given clock and the SI definition is a measure of the quality of
|
| 954 |
implementation. — *end note*]
|
| 955 |
|
| 956 |
+
A type `TC` meets the requirements if
|
| 957 |
|
| 958 |
- `TC` meets the *Cpp17Clock* requirements,
|
| 959 |
- the types `TC::rep`, `TC::duration`, and `TC::time_point` meet the
|
| 960 |
*Cpp17EqualityComparable* ([[cpp17.equalitycomparable]]) and
|
| 961 |
*Cpp17LessThanComparable* ([[cpp17.lessthancomparable]]) and
|
|
|
|
| 1108 |
namespace std::chrono {
|
| 1109 |
template<class Rep, class Period = ratio<1>>
|
| 1110 |
class duration {
|
| 1111 |
public:
|
| 1112 |
using rep = Rep;
|
| 1113 |
+
using period = Period::type;
|
| 1114 |
|
| 1115 |
private:
|
| 1116 |
rep rep_; // exposition only
|
| 1117 |
|
| 1118 |
public:
|
|
|
|
| 1161 |
ill-formed. If `Period::num` is not positive, the program is ill-formed.
|
| 1162 |
|
| 1163 |
Members of `duration` do not throw exceptions other than those thrown by
|
| 1164 |
the indicated operations on their representations.
|
| 1165 |
|
| 1166 |
+
The defaulted copy constructor of `duration` shall be a constexpr
|
| 1167 |
+
function if and only if the required initialization of the member `rep_`
|
| 1168 |
+
for copy and move, respectively, would be constexpr-suitable
|
| 1169 |
+
[[dcl.constexpr]].
|
| 1170 |
|
| 1171 |
[*Example 1*:
|
| 1172 |
|
| 1173 |
``` cpp
|
| 1174 |
duration<long, ratio<60>> d0; // holds a count of minutes using a long
|
|
|
|
| 1193 |
|
| 1194 |
[*Example 1*:
|
| 1195 |
|
| 1196 |
``` cpp
|
| 1197 |
duration<int, milli> d(3); // OK
|
| 1198 |
+
duration<int, milli> d2(3.5); // error
|
| 1199 |
```
|
| 1200 |
|
| 1201 |
— *end example*]
|
| 1202 |
|
| 1203 |
*Effects:* Initializes `rep_` with `r`.
|
|
|
|
| 1732 |
template<class Clock, class Duration = typename Clock::duration>
|
| 1733 |
class time_point {
|
| 1734 |
public:
|
| 1735 |
using clock = Clock;
|
| 1736 |
using duration = Duration;
|
| 1737 |
+
using rep = duration::rep;
|
| 1738 |
+
using period = duration::period;
|
| 1739 |
|
| 1740 |
private:
|
| 1741 |
duration d_; // exposition only
|
| 1742 |
|
| 1743 |
public:
|
|
|
|
| 3016 |
*Returns:* The best well-formed clock time conversion expression in the
|
| 3017 |
above list.
|
| 3018 |
|
| 3019 |
## The civil calendar <a id="time.cal">[[time.cal]]</a>
|
| 3020 |
|
| 3021 |
+
### General <a id="time.cal.general">[[time.cal.general]]</a>
|
| 3022 |
|
| 3023 |
The types in [[time.cal]] describe the civil (Gregorian) calendar and
|
| 3024 |
its relationship to `sys_days` and `local_days`.
|
| 3025 |
|
| 3026 |
### Class `last_spec` <a id="time.cal.last">[[time.cal.last]]</a>
|
|
|
|
| 5652 |
year/month/day
|
| 5653 |
month/day/year
|
| 5654 |
day/month/year
|
| 5655 |
```
|
| 5656 |
|
| 5657 |
+
Anywhere a `day` is needed, any of the following can also be specified:
|
|
|
|
| 5658 |
|
| 5659 |
``` cpp
|
| 5660 |
last
|
| 5661 |
weekday[i]
|
| 5662 |
weekday[last]
|
|
|
|
| 6204 |
\[`12h`, `23h`\], assuming `h` represents a post meridiem hour. If `h`
|
| 6205 |
is not in the range \[`1h`, `12h`\], the value returned is unspecified.
|
| 6206 |
|
| 6207 |
## Time zones <a id="time.zone">[[time.zone]]</a>
|
| 6208 |
|
| 6209 |
+
### General <a id="time.zone.general">[[time.zone.general]]</a>
|
| 6210 |
|
| 6211 |
[[time.zone]] describes an interface for accessing the IANA Time Zone
|
| 6212 |
Database that interoperates with `sys_time` and `local_time`. This
|
| 6213 |
interface provides time zone support to both the civil calendar types
|
| 6214 |
[[time.cal]] and to user-defined calendars.
|
|
|
|
| 7216 |
|
| 7217 |
[*Example 1*:
|
| 7218 |
|
| 7219 |
``` cpp
|
| 7220 |
for (auto& l : get_tzdb().leap_seconds)
|
| 7221 |
+
if (l <= sys_days{2018y/March/17d})
|
| 7222 |
cout << l.date() << ": " << l.value() << '\n';
|
| 7223 |
```
|
| 7224 |
|
| 7225 |
Produces the output:
|
| 7226 |
|
|
|
|
| 7469 |
- the locale passed to the formatting function if any, otherwise
|
| 7470 |
- the global locale.
|
| 7471 |
|
| 7472 |
Each conversion specifier *conversion-spec* is replaced by appropriate
|
| 7473 |
characters as described in [[time.format.spec]]; the formats specified
|
| 7474 |
+
in ISO 8601-1:2019 shall be used where so described. Some of the
|
| 7475 |
conversion specifiers depend on the formatting locale. If the string
|
| 7476 |
literal encoding is a Unicode encoding form and the locale is among an
|
| 7477 |
*implementation-defined* set of locales, each replacement that depends
|
| 7478 |
on the locale is performed as if the replacement character sequence is
|
| 7479 |
converted to the string literal encoding. If the formatted object does
|
|
|
|
| 7528 |
| `%C` | The year divided by 100 using floored division. If the result is a single decimal digit, it is prefixed with `0`. The modified command `%EC` produces the locale's alternative representation of the century. |
|
| 7529 |
| `%d` | The day of month as a decimal number. If the result is a single decimal digit, it is prefixed with `0`. The modified command `%Od` produces the locale's alternative representation. |
|
| 7530 |
| `%D` | Equivalent to `%m/%d/%y`. |
|
| 7531 |
| `%e` | The day of month as a decimal number. If the result is a single decimal digit, it is prefixed with a space. The modified command `%Oe` produces the locale's alternative representation. |
|
| 7532 |
| `%F` | Equivalent to `%Y-%m-%d`. |
|
| 7533 |
+
| `%g` | The last two decimal digits of the calendar year as specified in ISO 8601-1:2019 for the week calendar. If the result is a single digit it is prefixed by `0`. |
|
| 7534 |
+
| `%G` | The calendar year as a decimal number, as specified in ISO 8601-1:2019 for the week calendar. If the result is less than four digits it is left-padded with `0` to four digits. |
|
| 7535 |
| `%h` | Equivalent to `%b`. |
|
| 7536 |
| `%H` | The hour (24-hour clock) as a decimal number. If the result is a single digit, it is prefixed with `0`. The modified command `%OH` produces the locale's alternative representation. |
|
| 7537 |
| `%I` | The hour (12-hour clock) as a decimal number. If the result is a single digit, it is prefixed with `0`. The modified command `%OI` produces the locale's alternative representation. |
|
| 7538 |
+
| `%j` | If the type being formatted is a specialization of `duration`, the decimal number of `days` without padding. Otherwise, the day of the year as a decimal number. January 1 is `001`. If the result is less than three digits, it is left-padded with `0` to three digits. |
|
| 7539 |
| `%m` | The month as a decimal number. Jan is `01`. If the result is a single digit, it is prefixed with `0`. The modified command `%Om` produces the locale's alternative representation. |
|
| 7540 |
| `%M` | The minute as a decimal number. If the result is a single digit, it is prefixed with `0`. The modified command `%OM` produces the locale's alternative representation. |
|
| 7541 |
| `%n` | A new-line character. |
|
| 7542 |
| `%p` | The locale's equivalent of the AM/PM designations associated with a 12-hour clock. |
|
| 7543 |
| `%q` | The duration's unit suffix as specified in [[time.duration.io]]. |
|
|
|
|
| 7545 |
| `%r` | The locale's 12-hour clock time. |
|
| 7546 |
| `%R` | Equivalent to `%H:%M`. |
|
| 7547 |
| `%S` | Seconds as a decimal number. If the number of seconds is less than `10`, the result is prefixed with `0`. If the precision of the input cannot be exactly represented with seconds, then the format is a decimal floating-point number with a fixed format and a precision matching that of the precision of the input (or to a microseconds precision if the conversion to floating-point decimal seconds cannot be made within 18 fractional digits). The character for the decimal point is localized according to the locale. The modified command `%OS` produces the locale's alternative representation. |
|
| 7548 |
| `%t` | A horizontal-tab character. |
|
| 7549 |
| `%T` | Equivalent to `%H:%M:%S`. |
|
| 7550 |
+
| `%u` | The calendar day of week as a decimal number (`1`-`7`), as specified in ISO 8601-1:2019, where Monday is `1`. The modified command `%Ou` produces the locale's alternative representation. |
|
| 7551 |
| `%U` | The week number of the year as a decimal number. The first Sunday of the year is the first day of week `01`. Days of the same year prior to that are in week `00`. If the result is a single digit, it is prefixed with `0`. The modified command `%OU` produces the locale's alternative representation. |
|
| 7552 |
+
| `%V` | The calendar week of year as a decimal number, as specified in ISO 8601-1:2019 for the week calendar. If the result is a single digit, it is prefixed with `0`. The modified command `%OV` produces the locale's alternative representation. |
|
| 7553 |
| `%w` | The weekday as a decimal number (`0`-`6`), where Sunday is `0`. The modified command `%Ow` produces the locale's alternative representation. |
|
| 7554 |
| `%W` | The week number of the year as a decimal number. The first Monday of the year is the first day of week `01`. Days of the same year prior to that are in week `00`. If the result is a single digit, it is prefixed with `0`. The modified command `%OW` produces the locale's alternative representation. |
|
| 7555 |
| `%x` | The locale's date representation. The modified command `%Ex` produces the locale's alternate date representation. |
|
| 7556 |
| `%X` | The locale's time representation. The modified command `%EX` produces the locale's alternate time representation. |
|
| 7557 |
+
| `%y` | The last two decimal digits of the year. If the result is a single digit, it is prefixed by `0`. The modified command `%Oy` produces the locale's alternative representation. The modified command `%Ey` produces the locale's alternative representation of offset from `%EC` (year only). |
|
| 7558 |
+
| `%Y` | The year as a decimal number. If the result is less than four digits, it is left-padded with `0` to four digits. The modified command `%EY` produces the locale's alternative full year representation. |
|
| 7559 |
+
| `%z` | The offset from UTC as specified in ISO 8601-1:2019, 5.3.4.1. For example `-0430` refers to 4 hours 30 minutes behind UTC. If the offset is zero, `+0000` is used. The modified commands `%Ez` and `%Oz` insert a `:` between the hours and minutes: `-04:30`. If the offset information is not available, an exception of type `format_error` is thrown. |
|
| 7560 |
| `%Z` | The time zone abbreviation. If the time zone abbreviation is not available, an exception of type `format_error` is thrown. |
|
| 7561 |
| `%%` | A `%` character. |
|
| 7562 |
|
| 7563 |
|
| 7564 |
+
Unless otherwise specified, if the *chrono-specs* is omitted, the chrono
|
| 7565 |
+
object is formatted as if by streaming it to
|
| 7566 |
+
`basic_ostringstream<charT> os` with the formatting locale imbued and
|
| 7567 |
+
copying `os.str()` through the output iterator of the context with
|
| 7568 |
+
additional padding and adjustments as specified by the format
|
| 7569 |
+
specifiers.
|
| 7570 |
|
| 7571 |
[*Example 3*:
|
| 7572 |
|
| 7573 |
``` cpp
|
| 7574 |
string s = format("{:=>8}", 42ms); // value of s is "====42ms"
|
| 7575 |
```
|
| 7576 |
|
| 7577 |
— *end example*]
|
| 7578 |
|
| 7579 |
+
For `chrono::duration` the library only provides the following
|
| 7580 |
+
specialization of `enable_nonlocking_formatter_optimization`:
|
| 7581 |
+
|
| 7582 |
+
``` cpp
|
| 7583 |
+
template<class Rep, class Period>
|
| 7584 |
+
constexpr bool enable_nonlocking_formatter_optimization<
|
| 7585 |
+
chrono::duration<Rep, Period>> =
|
| 7586 |
+
enable_nonlocking_formatter_optimization<Rep>;
|
| 7587 |
+
```
|
| 7588 |
+
|
| 7589 |
+
For `chrono::zoned_time` the library only provides the following
|
| 7590 |
+
specialization of `enable_nonlocking_formatter_optimization`:
|
| 7591 |
+
|
| 7592 |
+
``` cpp
|
| 7593 |
+
template<class Duration>
|
| 7594 |
+
constexpr bool enable_nonlocking_formatter_optimization<
|
| 7595 |
+
chrono::zoned_time<Duration, const std::chrono::time_zone*>> = true;
|
| 7596 |
+
```
|
| 7597 |
+
|
| 7598 |
``` cpp
|
| 7599 |
template<class Duration, class charT>
|
| 7600 |
struct formatter<chrono::sys_time<Duration>, charT>;
|
| 7601 |
```
|
| 7602 |
|
|
|
|
| 7691 |
```
|
| 7692 |
|
| 7693 |
Let `f` be a *`local-time-format-t`*`<Duration>` object passed to
|
| 7694 |
`formatter::format`.
|
| 7695 |
|
| 7696 |
+
*Remarks:* If the *chrono-specs* is omitted, the result is equivalent to
|
| 7697 |
+
using `%F %T %Z` as the *chrono-specs*. If `%Z` is used, it is replaced
|
| 7698 |
+
with `*f.abbrev` if `f.abbrev` is not a null pointer value. If `%Z` is
|
| 7699 |
+
used and `f.abbrev` is a null pointer value, an exception of type
|
| 7700 |
+
`format_error` is thrown. If `%z` (or a modified variant of `%z`) is
|
| 7701 |
+
used, it is formatted with the value of `*f.offset_sec` if
|
| 7702 |
+
`f.offset_sec` is not a null pointer value. If `%z` (or a modified
|
| 7703 |
+
variant of `%z`) is used and `f.offset_sec` is a null pointer value,
|
| 7704 |
+
then an exception of type `format_error` is thrown.
|
| 7705 |
|
| 7706 |
``` cpp
|
| 7707 |
template<class Duration, class TimeZonePtr, class charT>
|
| 7708 |
struct formatter<chrono::zoned_time<Duration, TimeZonePtr>, charT>
|
| 7709 |
+
: formatter<chrono::local-time-format-t<common_type_t<Duration, seconds>>, charT> {
|
| 7710 |
template<class FormatContext>
|
| 7711 |
typename FormatContext::iterator
|
| 7712 |
format(const chrono::zoned_time<Duration, TimeZonePtr>& tp, FormatContext& ctx) const;
|
| 7713 |
};
|
| 7714 |
```
|
|
|
|
| 7721 |
|
| 7722 |
*Effects:* Equivalent to:
|
| 7723 |
|
| 7724 |
``` cpp
|
| 7725 |
sys_info info = tp.get_info();
|
| 7726 |
+
return formatter<chrono::local-time-format-t<common_type_t<Duration, seconds>>, charT>::
|
| 7727 |
format({tp.get_local_time(), &info.abbrev, &info.offset}, ctx);
|
| 7728 |
```
|
| 7729 |
|
| 7730 |
## Parsing <a id="time.parse">[[time.parse]]</a>
|
| 7731 |
|
| 7732 |
Each `parse` overload specified in this subclause calls `from_stream`
|
| 7733 |
+
unqualified, so as to enable argument-dependent lookup
|
| 7734 |
[[basic.lookup.argdep]]. In the following paragraphs, let `is` denote an
|
| 7735 |
object of type `basic_istream<charT, traits>` and let `I` be
|
| 7736 |
`basic_istream<charT, traits>&`, where `charT` and `traits` are template
|
| 7737 |
parameters in that context.
|
| 7738 |
|
|
|
|
| 7898 |
| `%C` | The century as a decimal number. The modified command `%*N*C` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command `%EC` interprets the locale's alternative representation of the century. |
|
| 7899 |
| `%d` | The day of the month as a decimal number. The modified command `%*N*d` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command `%Od` interprets the locale's alternative representation of the day of the month. |
|
| 7900 |
| `%D` | Equivalent to `%m/%d/%y`. |
|
| 7901 |
| `%e` | Equivalent to `%d` and can be modified like `%d`. |
|
| 7902 |
| `%F` | Equivalent to `%Y-%m-%d`. If modified with a width `*N*`, the width is applied to only `%Y`. |
|
| 7903 |
+
| `%g` | The last two decimal digits of the calendar year, as specified in ISO 8601-1:2019 for the week calendar. The modified command `%*N*g` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. |
|
| 7904 |
+
| `%G` | The calendar year as a decimal number, as specified in ISO 8601-1:2019 for the week calendar. The modified command `%*N*G` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 4. Leading zeroes are permitted but not required. |
|
| 7905 |
| `%h` | Equivalent to `%b`. |
|
| 7906 |
| `%H` | The hour (24-hour clock) as a decimal number. The modified command `%*N*H` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command `%OH` interprets the locale's alternative representation. |
|
| 7907 |
| `%I` | The hour (12-hour clock) as a decimal number. The modified command `%*N*I` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command `%OI` interprets the locale's alternative representation. |
|
| 7908 |
+
| `%j` | If the type being parsed is a specialization of `duration`, a decimal number of `days`. Otherwise, the day of the year as a decimal number. January 1 is `1`. In either case, the modified command `%*N*j` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 3. Leading zeroes are permitted but not required. |
|
| 7909 |
+
| `%m` | The month as a decimal number. January is `1`. The modified command `%*N*m` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command `%Om` interprets the locale's alternative representation. |
|
| 7910 |
| `%M` | The minutes as a decimal number. The modified command `%*N*M` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command `%OM` interprets the locale's alternative representation. |
|
| 7911 |
| `%n` | Matches one whitespace character. *`%n`, `%t`, and a space can be combined to match a wide range of whitespace patterns. For example, `"%n "` matches one or more whitespace characters, and `"%n%t%t"` matches one to three whitespace characters.* |
|
| 7912 |
| `%p` | The locale's equivalent of the AM/PM designations associated with a 12-hour clock. |
|
| 7913 |
| `%r` | The locale's 12-hour clock time. |
|
| 7914 |
| `%R` | Equivalent to `%H:%M`. |
|
| 7915 |
| `%S` | The seconds as a decimal number. The modified command `%*N*S` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2 if the input time has a precision convertible to seconds. Otherwise the default width is determined by the decimal precision of the input and the field is interpreted as a `long double` in a fixed format. If encountered, the locale determines the decimal point character. Leading zeroes are permitted but not required. The modified command `%OS` interprets the locale's alternative representation. |
|
| 7916 |
| `%t` | Matches zero or one whitespace characters. |
|
| 7917 |
| `%T` | Equivalent to `%H:%M:%S`. |
|
| 7918 |
+
| `%u` | The calendar day of week as a decimal number (`1`-`7`), as specified in ISO 8601-1:2019, where Monday is `1`. The modified command `%*N*u` specifies the maximum number of characters to read. If `*N*` is not specified, the default is `1`. Leading zeroes are permitted but not required. |
|
| 7919 |
| `%U` | The week number of the year as a decimal number. The first Sunday of the year is the first day of week `01`. Days of the same year prior to that are in week `00`. The modified command `%*N*U` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command `%OU` interprets the locale's alternative representation. |
|
| 7920 |
+
| `%V` | The calendar week of year as a decimal number, as specified in ISO 8601-1:2019 for the week calendar. The modified command `%*N*V` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. |
|
| 7921 |
| `%w` | The weekday as a decimal number (`0`-`6`), where Sunday is `0`. The modified command `%*N*w` specifies the maximum number of characters to read. If `*N*` is not specified, the default is `1`. Leading zeroes are permitted but not required. The modified command `%Ow` interprets the locale's alternative representation. |
|
| 7922 |
| `%W` | The week number of the year as a decimal number. The first Monday of the year is the first day of week `01`. Days of the same year prior to that are in week `00`. The modified command `%*N*W` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command `%OW` interprets the locale's alternative representation. |
|
| 7923 |
| `%x` | The locale's date representation. The modified command `%Ex` interprets the locale's alternate date representation. |
|
| 7924 |
| `%X` | The locale's time representation. The modified command `%EX` interprets the locale's alternate time representation. |
|
| 7925 |
| `%y` | The last two decimal digits of the year. If the century is not otherwise specified (e.g., with `%C`), values in the range {[}`69`, `99`{]} are presumed to refer to the years 1969 to 1999, and values in the range {[}`00`, `68`{]} are presumed to refer to the years 2000 to 2068. The modified command `%*N*y` specifies the maximum number of characters to read. If `*N*` is not specified, the default is 2. Leading zeroes are permitted but not required. The modified commands `%Ey` and `%Oy` interpret the locale's alternative representation. |
|
|
|
|
| 7927 |
| `%z` | The offset from UTC in the format `[+|-]hh[mm]`. For example `-0430` refers to 4 hours 30 minutes behind UTC, and `04` refers to 4 hours ahead of UTC. The modified commands `%Ez` and `%Oz` parse a `:` between the hours and minutes and render leading zeroes on the hour field optional: `[+|-]h[h][:mm]`. For example `-04:30` refers to 4 hours 30 minutes behind UTC, and `4` refers to 4 hours ahead of UTC. |
|
| 7928 |
| `%Z` | The time zone abbreviation or name. A single word is parsed. This word can only contain characters from the basic character set [[lex.charset]] that are alphanumeric, or one of `'_'`, `'/'`, `'-'`, or `'+'`. |
|
| 7929 |
| `%%` | A `%` character is extracted. |
|
| 7930 |
|
| 7931 |
|
| 7932 |
+
## Hash support <a id="time.hash">[[time.hash]]</a>
|
| 7933 |
+
|
| 7934 |
+
``` cpp
|
| 7935 |
+
template<class Rep, class Period> struct hash<chrono::duration<Rep, Period>>;
|
| 7936 |
+
```
|
| 7937 |
+
|
| 7938 |
+
The specialization `hash<chrono::duration<Rep, Period>>` is
|
| 7939 |
+
enabled [[unord.hash]] if and only if
|
| 7940 |
+
`hash<Rep>` is enabled. The member functions are not guaranteed to be
|
| 7941 |
+
`noexcept`.
|
| 7942 |
+
|
| 7943 |
+
``` cpp
|
| 7944 |
+
template<class Clock, class Duration> struct hash<chrono::time_point<Clock, Duration>>;
|
| 7945 |
+
```
|
| 7946 |
+
|
| 7947 |
+
The specialization `hash<chrono::time_point<Clock, Duration>>` is
|
| 7948 |
+
enabled [[unord.hash]] if and only if `hash<Duration>` is enabled. The
|
| 7949 |
+
member functions are not guaranteed to be `noexcept`.
|
| 7950 |
+
|
| 7951 |
+
``` cpp
|
| 7952 |
+
template<> struct hash<chrono::day>;
|
| 7953 |
+
template<> struct hash<chrono::month>;
|
| 7954 |
+
template<> struct hash<chrono::year>;
|
| 7955 |
+
template<> struct hash<chrono::weekday>;
|
| 7956 |
+
template<> struct hash<chrono::weekday_indexed>;
|
| 7957 |
+
template<> struct hash<chrono::weekday_last>;
|
| 7958 |
+
template<> struct hash<chrono::month_day>;
|
| 7959 |
+
template<> struct hash<chrono::month_day_last>;
|
| 7960 |
+
template<> struct hash<chrono::month_weekday>;
|
| 7961 |
+
template<> struct hash<chrono::month_weekday_last>;
|
| 7962 |
+
template<> struct hash<chrono::year_month>;
|
| 7963 |
+
template<> struct hash<chrono::year_month_day>;
|
| 7964 |
+
template<> struct hash<chrono::year_month_day_last>;
|
| 7965 |
+
template<> struct hash<chrono::year_month_weekday>;
|
| 7966 |
+
template<> struct hash<chrono::year_month_weekday_last>;
|
| 7967 |
+
```
|
| 7968 |
+
|
| 7969 |
+
The specializations are enabled [[unord.hash]].
|
| 7970 |
+
|
| 7971 |
+
[*Note 1*: All the `hash<Key>` specializations listed above meet the
|
| 7972 |
+
*Cpp17Hash* requirements, even when called on objects `k` of type `Key`
|
| 7973 |
+
such that `k.ok()` is `false`. — *end note*]
|
| 7974 |
+
|
| 7975 |
+
``` cpp
|
| 7976 |
+
template<class Duration, class TimeZonePtr>
|
| 7977 |
+
struct hash<chrono::zoned_time<Duration, TimeZonePtr>>;
|
| 7978 |
+
```
|
| 7979 |
+
|
| 7980 |
+
The specialization `hash<chrono::zoned_time<Duration, TimeZonePtr>>` is
|
| 7981 |
+
enabled [[unord.hash]] if and only if `hash<Duration>` is enabled and
|
| 7982 |
+
`hash<TimeZonePtr>` is enabled. The member functions are not guaranteed
|
| 7983 |
+
to be `noexcept`.
|
| 7984 |
+
|
| 7985 |
+
``` cpp
|
| 7986 |
+
template<> struct hash<chrono::leap_second>;
|
| 7987 |
+
```
|
| 7988 |
+
|
| 7989 |
+
The specialization is enabled [[unord.hash]].
|
| 7990 |
+
|
| 7991 |
## Header `<ctime>` synopsis <a id="ctime.syn">[[ctime.syn]]</a>
|
| 7992 |
|
| 7993 |
``` cpp
|
| 7994 |
+
#define __STDC_VERSION_TIME_H__ 202311L
|
| 7995 |
+
|
| 7996 |
#define NULL see [support.types.nullptr]
|
| 7997 |
#define CLOCKS_PER_SEC see below
|
| 7998 |
#define TIME_UTC see below
|
| 7999 |
+
#define TIME_MONOTONIC see below // optional
|
| 8000 |
+
#define TIME_ACTIVE see below // optional
|
| 8001 |
+
#define TIME_THREAD_ACTIVE see below // optional
|
| 8002 |
|
| 8003 |
namespace std {
|
| 8004 |
using size_t = see [support.types.layout];
|
| 8005 |
using clock_t = see below;
|
| 8006 |
using time_t = see below;
|
|
|
|
| 8009 |
struct tm;
|
| 8010 |
|
| 8011 |
clock_t clock();
|
| 8012 |
double difftime(time_t time1, time_t time0);
|
| 8013 |
time_t mktime(tm* timeptr);
|
| 8014 |
+
time_t timegm(tm* timeptr);
|
| 8015 |
time_t time(time_t* timer);
|
| 8016 |
int timespec_get(timespec* ts, int base);
|
| 8017 |
+
int timespec_getres(timespec* ts, int base);
|
|
|
|
| 8018 |
tm* gmtime(const time_t* timer);
|
| 8019 |
+
tm* gmtime_r(const time_t* timer, tm* buf);
|
| 8020 |
tm* localtime(const time_t* timer);
|
| 8021 |
+
tm* localtime_r(const time_t* timer, tm* buf);
|
| 8022 |
size_t strftime(char* s, size_t maxsize, const char* format, const tm* timeptr);
|
| 8023 |
}
|
| 8024 |
```
|
| 8025 |
|
| 8026 |
The contents of the header `<ctime>` are the same as the C standard
|
| 8027 |
library header `<time.h>`.[^1]
|
| 8028 |
|
| 8029 |
+
The functions `gmtime` and `localtime` are not required to avoid data
|
| 8030 |
+
races [[res.on.data.races]].
|
| 8031 |
|
| 8032 |
+
See also: ISO C 7.29
|
| 8033 |
|
| 8034 |
<!-- Link reference definitions -->
|
| 8035 |
[basic.lookup.argdep]: basic.md#basic.lookup.argdep
|
| 8036 |
[cpp17.equalitycomparable]: #cpp17.equalitycomparable
|
| 8037 |
[cpp17.lessthancomparable]: #cpp17.lessthancomparable
|
| 8038 |
[ctime.syn]: #ctime.syn
|
| 8039 |
[dcl.constexpr]: dcl.md#dcl.constexpr
|
| 8040 |
[filesystems]: input.md#filesystems
|
| 8041 |
+
[format.formatter]: text.md#format.formatter
|
| 8042 |
+
[format.string]: text.md#format.string
|
| 8043 |
+
[formatter.requirements]: text.md#formatter.requirements
|
| 8044 |
[intro.multithread]: basic.md#intro.multithread
|
| 8045 |
[lex.charset]: lex.md#lex.charset
|
| 8046 |
[meta.rqmts]: meta.md#meta.rqmts
|
| 8047 |
[numeric.requirements]: numerics.md#numeric.requirements
|
| 8048 |
[over.ics.rank]: over.md#over.ics.rank
|
|
|
|
| 8160 |
[time.duration.observer]: #time.duration.observer
|
| 8161 |
[time.duration.special]: #time.duration.special
|
| 8162 |
[time.format]: #time.format
|
| 8163 |
[time.format.spec]: #time.format.spec
|
| 8164 |
[time.general]: #time.general
|
| 8165 |
+
[time.hash]: #time.hash
|
| 8166 |
[time.hms]: #time.hms
|
| 8167 |
[time.hms.members]: #time.hms.members
|
| 8168 |
[time.hms.nonmembers]: #time.hms.nonmembers
|
| 8169 |
[time.hms.overview]: #time.hms.overview
|
| 8170 |
[time.hms.width]: #time.hms.width
|
|
|
|
| 8215 |
[time.zone.zonedtime.ctor]: #time.zone.zonedtime.ctor
|
| 8216 |
[time.zone.zonedtime.members]: #time.zone.zonedtime.members
|
| 8217 |
[time.zone.zonedtime.nonmembers]: #time.zone.zonedtime.nonmembers
|
| 8218 |
[time.zone.zonedtime.overview]: #time.zone.zonedtime.overview
|
| 8219 |
[time.zone.zonedtraits]: #time.zone.zonedtraits
|
| 8220 |
+
[unord.hash]: utilities.md#unord.hash
|
| 8221 |
|
| 8222 |
[^1]: `strftime` supports the C conversion specifiers `C`, `D`, `e`,
|
| 8223 |
`F`, `g`, `G`, `h`, `r`, `R`, `t`, `T`, `u`, `V`, and `z`, and the
|
| 8224 |
modifiers `E` and `O`.
|