[time.cal.wd]

# 30 Time library [[time]](./#time)

## 30.8 The civil calendar [[time.cal]](time.cal#wd)

### 30.8.6 Class weekday [time.cal.wd]

#### [30.8.6.1](#overview) Overview [[time.cal.wd.overview]](time.cal.wd.overview)

namespace std::chrono {class weekday {unsigned char wd_; // *exposition only*public: weekday() = default; constexpr explicit weekday(unsigned wd) noexcept; constexpr weekday(const sys_days& dp) noexcept; constexpr explicit weekday(const local_days& dp) noexcept; constexpr weekday& operator++() noexcept; constexpr weekday operator++(int) noexcept; constexpr weekday& operator--() noexcept; constexpr weekday operator--(int) noexcept; constexpr weekday& operator+=(const days& d) noexcept; constexpr weekday& operator-=(const days& d) noexcept; constexpr unsigned c_encoding() const noexcept; constexpr unsigned iso_encoding() const noexcept; constexpr bool ok() const noexcept; constexpr weekday_indexed operator[](unsigned index) const noexcept; constexpr weekday_last operator[](last_spec) const noexcept; };}

[1](#overview-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4925)

weekday represents a day of the week in the civil calendar[.](#overview-1.sentence-1)

It normally holds values in the range 0 to 6,
corresponding to Sunday through Saturday, but
it 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 weekday's unspecified internal storage[.](#overview-1.sentence-3)

weekday meets the [*Cpp17EqualityComparable*](utility.arg.requirements#:Cpp17EqualityComparable "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [28](utility.arg.requirements#tab:cpp17.equalitycomparable "Table 28: Cpp17EqualityComparable requirements")) requirements[.](#overview-1.sentence-4)

[*Note [1](#overview-note-1)*:

weekday is not[*Cpp17LessThanComparable*](utility.arg.requirements#:Cpp17LessThanComparable "16.4.4.2 Template argument requirements [utility.arg.requirements]") because there is no universal consensus on which day is the first day of the week[.](#overview-1.sentence-5)

weekday's arithmetic operations treat the days of the week as a circular range,
with no beginning and no end[.](#overview-1.sentence-6)

â *end note*]

[2](#overview-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4941)

weekday is a trivially copyable and standard-layout class type[.](#overview-2.sentence-1)

#### [30.8.6.2](#members) Member functions [[time.cal.wd.members]](time.cal.wd.members)

[ð](#lib:weekday,constructor)

`constexpr explicit weekday(unsigned wd) noexcept;
`

[1](#members-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4952)

*Effects*: Initializes wd_ with wd == 7 ? 0 : wd[.](#members-1.sentence-1)

The value held is unspecified if wd is not in the range [0, 255][.](#members-1.sentence-2)

[ð](#lib:weekday,constructor_)

`constexpr weekday(const sys_days& dp) noexcept;
`

[2](#members-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4964)

*Effects*: Computes what day of the week corresponds to the sys_days dp,
and initializes that day of the week in wd_[.](#members-2.sentence-1)

[3](#members-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4969)

[*Example [1](#members-example-1)*:

If dp represents 1970-01-01,
the constructed weekday represents Thursday
by storing 4 in wd_[.](#members-3.sentence-1)

â *end example*]

[ð](#lib:weekday,constructor__)

`constexpr explicit weekday(const local_days& dp) noexcept;
`

[4](#members-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4983)

*Effects*: Computes what day of the week corresponds to the local_days dp,
and initializes that day of the week in wd_[.](#members-4.sentence-1)

[5](#members-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L4988)

*Postconditions*: The value is identical to that constructed fromsys_days{dp.time_since_epoch()}[.](#members-5.sentence-1)

[ð](#lib:operator++,weekday)

`constexpr weekday& operator++() noexcept;
`

[6](#members-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5000)

*Effects*: *this += days{1}[.](#members-6.sentence-1)

[7](#members-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5004)

*Returns*: *this[.](#members-7.sentence-1)

[ð](#lib:operator++,weekday_)

`constexpr weekday operator++(int) noexcept;
`

[8](#members-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5015)

*Effects*: ++(*this)[.](#members-8.sentence-1)

[9](#members-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5019)

*Returns*: A copy of *this as it existed on entry to this member function[.](#members-9.sentence-1)

[ð](#lib:operator--,weekday)

`constexpr weekday& operator--() noexcept;
`

[10](#members-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5030)

*Effects*: *this -= days{1}[.](#members-10.sentence-1)

[11](#members-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5034)

*Returns*: *this[.](#members-11.sentence-1)

[ð](#lib:operator--,weekday_)

`constexpr weekday operator--(int) noexcept;
`

[12](#members-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5045)

*Effects*: --(*this)[.](#members-12.sentence-1)

[13](#members-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5049)

*Returns*: A copy of *this as it existed on entry to this member function[.](#members-13.sentence-1)

[ð](#lib:operator+=,weekday)

`constexpr weekday& operator+=(const days& d) noexcept;
`

[14](#members-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5060)

*Effects*: *this = *this + d[.](#members-14.sentence-1)

[15](#members-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5064)

*Returns*: *this[.](#members-15.sentence-1)

[ð](#lib:operator-=,weekday)

`constexpr weekday& operator-=(const days& d) noexcept;
`

[16](#members-16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5075)

*Effects*: *this = *this - d[.](#members-16.sentence-1)

[17](#members-17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5079)

*Returns*: *this[.](#members-17.sentence-1)

[ð](#lib:c_encoding,weekday)

`constexpr unsigned c_encoding() const noexcept;
`

[18](#members-18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5090)

*Returns*: wd_[.](#members-18.sentence-1)

[ð](#lib:iso_encoding,weekday)

`constexpr unsigned iso_encoding() const noexcept;
`

[19](#members-19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5101)

*Returns*: wd_ == 0u ? 7u : wd_[.](#members-19.sentence-1)

[ð](#lib:ok,weekday)

`constexpr bool ok() const noexcept;
`

[20](#members-20)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5112)

*Returns*: wd_ <= 6[.](#members-20.sentence-1)

[ð](#lib:operator%5b%5d,weekday)

`constexpr weekday_indexed operator[](unsigned index) const noexcept;
`

[21](#members-21)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5123)

*Returns*: {*this, index}[.](#members-21.sentence-1)

[ð](#lib:operator%5b%5d,weekday_)

`constexpr weekday_last operator[](last_spec) const noexcept;
`

[22](#members-22)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5134)

*Returns*: weekday_last{*this}[.](#members-22.sentence-1)

#### [30.8.6.3](#nonmembers) Non-member functions [[time.cal.wd.nonmembers]](time.cal.wd.nonmembers)

[ð](#lib:operator==,weekday)

`constexpr bool operator==(const weekday& x, const weekday& y) noexcept;
`

[1](#nonmembers-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5147)

*Returns*: x.wd_ == y.wd_[.](#nonmembers-1.sentence-1)

[ð](#lib:operator+,weekday)

`constexpr weekday operator+(const weekday& x, const days& y) noexcept;
`

[2](#nonmembers-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5158)

*Returns*: weekday{modulo(static_cast<long long>(x.wd_) + y.count(), 7)} where modulo(n, 7) computes the remainder of n divided by 7 using Euclidean division[.](#nonmembers-2.sentence-1)

[*Note [1](#nonmembers-note-1)*:

Given a divisor of 7, Euclidean division truncates towards negative infinity and
always produces a remainder in the range of [0, 6][.](#nonmembers-2.sentence-2)

Assuming no overflow in the signed summation,
this operation results in a weekday holding a value in the range [0, 6] even if !x.ok()[.](#nonmembers-2.sentence-3)

â *end note*]

[*Example [1](#nonmembers-example-1)*:

Monday + days{6} == Sunday[.](#nonmembers-2.sentence-4)

â *end example*]

[ð](#lib:operator+,weekday_)

`constexpr weekday operator+(const days& x, const weekday& y) noexcept;
`

[3](#nonmembers-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5181)

*Returns*: y + x[.](#nonmembers-3.sentence-1)

[ð](#lib:operator-,weekday)

`constexpr weekday operator-(const weekday& x, const days& y) noexcept;
`

[4](#nonmembers-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5192)

*Returns*: x + -y[.](#nonmembers-4.sentence-1)

[ð](#lib:operator-,weekday_)

`constexpr days operator-(const weekday& x, const weekday& y) noexcept;
`

[5](#nonmembers-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5203)

*Returns*: If x.ok() == true and y.ok() == true,
returns a value d in the range [days{0}, days{6}]
satisfying y + d == x[.](#nonmembers-5.sentence-1)

Otherwise the value returned is unspecified[.](#nonmembers-5.sentence-2)

[*Example [2](#nonmembers-example-2)*:

Sunday - Monday == days{6}[.](#nonmembers-5.sentence-3)

â *end example*]

[ð](#lib:operator%3c%3c,weekday)

`template<class charT, class traits>
  basic_ostream<charT, traits>&
    operator<<(basic_ostream<charT, traits>& os, const weekday& wd);
`

[6](#nonmembers-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5224)

*Effects*: Equivalent to:return os << (wd.ok() ? format(os.getloc(), *STATICALLY-WIDEN*<charT>("{:L%a}"), wd) : format(os.getloc(), *STATICALLY-WIDEN*<charT>("{} is not a valid weekday"), static_cast<unsigned>(wd.wd_)));

[ð](#lib:from_stream,weekday)

`template<class charT, class traits, class Alloc = allocator<charT>>
  basic_istream<charT, traits>&
    from_stream(basic_istream<charT, traits>& is, const charT* fmt,
                weekday& wd, basic_string<charT, traits, Alloc>* abbrev = nullptr,
                minutes* offset = nullptr);
`

[7](#nonmembers-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5245)

*Effects*: Attempts to parse the input stream is into the weekday wd using
the format flags given in the NTCTS fmt as specified in [[time.parse]](time.parse "30.13 Parsing")[.](#nonmembers-7.sentence-1)

If the parse fails to decode a valid weekday,is.setstate(ios_base​::​failbit) is called andwd is not modified[.](#nonmembers-7.sentence-2)

If %Z is used and successfully parsed,
that value will be assigned to *abbrev if abbrev is non-null[.](#nonmembers-7.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-7.sentence-4)

[8](#nonmembers-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L5259)

*Returns*: is[.](#nonmembers-8.sentence-1)
