Files
2025-10-25 03:02:53 +03:00

296 lines
9.3 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[time.cal.day]
# 30 Time library [[time]](./#time)
## 30.8 The civil calendar [[time.cal]](time.cal#day)
### 30.8.3 Class day [time.cal.day]
#### [30.8.3.1](#overview) Overview [[time.cal.day.overview]](time.cal.day.overview)
namespace std::chrono {class day {unsigned char d_; // *exposition only*public: day() = default; constexpr explicit day(unsigned d) noexcept; constexpr day& operator++() noexcept; constexpr day operator++(int) noexcept; constexpr day& operator--() noexcept; constexpr day operator--(int) noexcept; constexpr day& operator+=(const days& d) noexcept; constexpr day& operator-=(const days& d) noexcept; constexpr explicit operator unsigned() const noexcept; constexpr bool ok() const noexcept; };}
[1](#overview-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3968)
day represents a day of a month[.](#overview-1.sentence-1)
It normally holds values in the range 1 to 31,
but may hold non-negative values outside this range[.](#overview-1.sentence-2)
It can be constructed with any unsigned value,
which will be subsequently truncated to fit into day's unspecified internal storage[.](#overview-1.sentence-3)
day meets the [*Cpp17EqualityComparable*](utility.arg.requirements#:Cpp17EqualityComparable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [28](utility.arg.requirements#tab:cpp17.equalitycomparable "Table 28: Cpp17EqualityComparable requirements"))
and [*Cpp17LessThanComparable*](utility.arg.requirements#:Cpp17LessThanComparable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [29](utility.arg.requirements#tab:cpp17.lessthancomparable "Table 29: Cpp17LessThanComparable requirements")) requirements,
and participates in basic arithmetic with days objects,
which represent a difference between two day objects[.](#overview-1.sentence-4)
[2](#overview-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3979)
day is a trivially copyable and standard-layout class type[.](#overview-2.sentence-1)
#### [30.8.3.2](#members) Member functions [[time.cal.day.members]](time.cal.day.members)
[🔗](#lib:day,constructor)
`constexpr explicit day(unsigned d) noexcept;
`
[1](#members-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3990)
*Effects*: Initializes d_ with d[.](#members-1.sentence-1)
The value held is unspecified if d is not in the range [0, 255][.](#members-1.sentence-2)
[🔗](#lib:operator++,day)
`constexpr day& operator++() noexcept;
`
[2](#members-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4002)
*Effects*: ++d_[.](#members-2.sentence-1)
[3](#members-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4006)
*Returns*: *this[.](#members-3.sentence-1)
[🔗](#lib:operator++,day_)
`constexpr day operator++(int) noexcept;
`
[4](#members-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4017)
*Effects*: ++(*this)[.](#members-4.sentence-1)
[5](#members-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4021)
*Returns*: A copy of *this as it existed on entry to this member function[.](#members-5.sentence-1)
[🔗](#lib:operator--,day)
`constexpr day& operator--() noexcept;
`
[6](#members-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4032)
*Effects*: Equivalent to: --d_[.](#members-6.sentence-1)
[7](#members-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4036)
*Returns*: *this[.](#members-7.sentence-1)
[🔗](#lib:operator--,day_)
`constexpr day operator--(int) noexcept;
`
[8](#members-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4047)
*Effects*: --(*this)[.](#members-8.sentence-1)
[9](#members-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4051)
*Returns*: A copy of *this as it existed on entry to this member function[.](#members-9.sentence-1)
[🔗](#lib:operator+=,day)
`constexpr day& operator+=(const days& d) noexcept;
`
[10](#members-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4062)
*Effects*: *this = *this + d[.](#members-10.sentence-1)
[11](#members-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4066)
*Returns*: *this[.](#members-11.sentence-1)
[🔗](#lib:operator-=,day)
`constexpr day& operator-=(const days& d) noexcept;
`
[12](#members-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4077)
*Effects*: *this = *this - d[.](#members-12.sentence-1)
[13](#members-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4081)
*Returns*: *this[.](#members-13.sentence-1)
[🔗](#lib:operator_unsigned,day)
`constexpr explicit operator unsigned() const noexcept;
`
[14](#members-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4092)
*Returns*: d_[.](#members-14.sentence-1)
[🔗](#lib:ok,day)
`constexpr bool ok() const noexcept;
`
[15](#members-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4103)
*Returns*: 1 <= d_ && d_ <= 31[.](#members-15.sentence-1)
#### [30.8.3.3](#nonmembers) Non-member functions [[time.cal.day.nonmembers]](time.cal.day.nonmembers)
[🔗](#lib:operator==,day)
`constexpr bool operator==(const day& x, const day& y) noexcept;
`
[1](#nonmembers-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4116)
*Returns*: unsigned{x} == unsigned{y}[.](#nonmembers-1.sentence-1)
[🔗](#lib:operator%3c=%3e,day)
`constexpr strong_ordering operator<=>(const day& x, const day& y) noexcept;
`
[2](#nonmembers-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4127)
*Returns*: unsigned{x} <=> unsigned{y}[.](#nonmembers-2.sentence-1)
[🔗](#lib:operator+,day)
`constexpr day operator+(const day& x, const days& y) noexcept;
`
[3](#nonmembers-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4138)
*Returns*: day(unsigned{x} + y.count())[.](#nonmembers-3.sentence-1)
[🔗](#lib:operator+,day_)
`constexpr day operator+(const days& x, const day& y) noexcept;
`
[4](#nonmembers-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4149)
*Returns*: y + x[.](#nonmembers-4.sentence-1)
[🔗](#lib:operator-,day)
`constexpr day operator-(const day& x, const days& y) noexcept;
`
[5](#nonmembers-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4160)
*Returns*: x + -y[.](#nonmembers-5.sentence-1)
[🔗](#lib:operator-,day_)
`constexpr days operator-(const day& x, const day& y) noexcept;
`
[6](#nonmembers-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4171)
*Returns*: days{int(unsigned{x}) - int(unsigned{y})}[.](#nonmembers-6.sentence-1)
[🔗](#lib:operator%3c%3c,day)
`template<class charT, class traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const day& d);
`
[7](#nonmembers-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4184)
*Effects*: Equivalent to:return os << (d.ok() ? format(*STATICALLY-WIDEN*<charT>("{:%d}"), d) : format(*STATICALLY-WIDEN*<charT>("{:%d} is not a valid day"), d));
[🔗](#lib:from_stream,day)
`template<class charT, class traits, class Alloc = allocator<charT>>
basic_istream<charT, traits>&
from_stream(basic_istream<charT, traits>& is, const charT* fmt,
day& d, basic_string<charT, traits, Alloc>* abbrev = nullptr,
minutes* offset = nullptr);
`
[8](#nonmembers-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4204)
*Effects*: Attempts to parse the input stream is into the day d using
the format flags given in the NTCTS fmt as specified in [[time.parse]](time.parse "30.13Parsing")[.](#nonmembers-8.sentence-1)
If the parse fails to decode a valid day,is.setstate(ios_base::failbit) is called andd is not modified[.](#nonmembers-8.sentence-2)
If %Z is used and successfully parsed,
that value will be assigned to *abbrev if abbrev is non-null[.](#nonmembers-8.sentence-3)
If %z (or a modified variant) is used and successfully parsed,
that value will be assigned to *offset if offset is non-null[.](#nonmembers-8.sentence-4)
[9](#nonmembers-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4218)
*Returns*: is[.](#nonmembers-9.sentence-1)
[🔗](#lib:operator%22%22d,day)
`constexpr chrono::day operator""d(unsigned long long d) noexcept;
`
[10](#nonmembers-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4229)
*Returns*: day{static_cast<unsigned>(d)}[.](#nonmembers-10.sentence-1)