From 4e7e76b98125e162e5f0b9e3961668b635122b56 Mon Sep 17 00:00:00 2001 From: NeroBurner Date: Sat, 19 Jan 2019 20:46:21 +0100 Subject: [PATCH] add c_encoding and iso_encoding weekday functions (#380) - c_encoding satisfies ctime wday encoding: days since Sunday, range [0,6] - iso_encoding satisfies ISO 8601 weekday: a digit d from 1 through 7, beginning with Monday and ending with Sunday --- include/date/date.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/date/date.h b/include/date/date.h index 4bc5b9f..968f0ba 100644 --- a/include/date/date.h +++ b/include/date/date.h @@ -429,6 +429,9 @@ public: CONSTCD11 bool ok() const NOEXCEPT; + CONSTCD11 unsigned c_encoding() const NOEXCEPT; + CONSTCD11 unsigned iso_encoding() const NOEXCEPT; + CONSTCD11 weekday_indexed operator[](unsigned index) const NOEXCEPT; CONSTCD11 weekday_last operator[](last_spec) const NOEXCEPT; @@ -1763,6 +1766,20 @@ weekday::operator-=(const days& d) NOEXCEPT CONSTCD11 inline bool weekday::ok() const NOEXCEPT {return wd_ <= 6;} +CONSTCD11 +inline +unsigned weekday::c_encoding() const NOEXCEPT +{ + return unsigned{wd_}; +} + +CONSTCD11 +inline +unsigned weekday::iso_encoding() const NOEXCEPT +{ + return unsigned{((wd_ == 0u) ? 7u : wd_)}; +} + CONSTCD11 inline bool