35#ifndef HAS_STRING_VIEW
36# if __cplusplus >= 201703 || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
37# define HAS_STRING_VIEW 1
39# define HAS_STRING_VIEW 0
48#if !(__cplusplus >= 201402)
67# include <string_view>
73# pragma GCC diagnostic push
74# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 7)
75# pragma GCC diagnostic ignored "-Wpedantic"
79# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
86# pragma warning(disable : 4127)
97# define ONLY_C_LOCALE 0
100#if defined(_MSC_VER) && (!defined(__clang__) || (_MSC_VER < 1910))
102# ifndef _SILENCE_CXX17_UNCAUGHT_EXCEPTION_DEPRECATION_WARNING
103# define _SILENCE_CXX17_UNCAUGHT_EXCEPTION_DEPRECATION_WARNING
107# define CONSTDATA const
110# define NOEXCEPT _NOEXCEPT
113# define CONSTDATA constexpr const
114# define CONSTCD11 constexpr
115# define CONSTCD14 constexpr
116# define NOEXCEPT noexcept
119#elif defined(__SUNPRO_CC) && __SUNPRO_CC <= 0x5150
121# define CONSTDATA constexpr const
122# define CONSTCD11 constexpr
124# define NOEXCEPT noexcept
126#elif __cplusplus >= 201402
128# define CONSTDATA constexpr const
129# define CONSTCD11 constexpr
130# define CONSTCD14 constexpr
131# define NOEXCEPT noexcept
134# define CONSTDATA constexpr const
135# define CONSTCD11 constexpr
137# define NOEXCEPT noexcept
140#ifndef HAS_UNCAUGHT_EXCEPTIONS
141# if __cplusplus > 201703 || (defined(_MSVC_LANG) && _MSVC_LANG > 201703L)
142# define HAS_UNCAUGHT_EXCEPTIONS 1
144# define HAS_UNCAUGHT_EXCEPTIONS 0
149# if __cplusplus >= 201703 || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
165template <
typename R1,
typename R2>
166using ratio_multiply =
decltype(std::ratio_multiply<R1, R2>{});
168template <
typename R1,
typename R2>
169using ratio_divide =
decltype(std::ratio_divide<R1, R2>{});
178using days = std::chrono::duration
179 <int, detail::ratio_multiply<std::ratio<24>, std::chrono::hours::period>>;
181using weeks = std::chrono::duration
182 <int, detail::ratio_multiply<std::ratio<7>, days::period>>;
184using years = std::chrono::duration
185 <int, detail::ratio_multiply<std::ratio<146097, 400>, days::period>>;
187using months = std::chrono::duration
188 <int, detail::ratio_divide<years::period, std::ratio<12>>>;
192template <
class Duration>
193 using sys_time = std::chrono::time_point<std::chrono::system_clock, Duration>;
195using sys_days = sys_time<days>;
196using sys_seconds = sys_time<std::chrono::seconds>;
200template <
class Duration>
201 using local_time = std::chrono::time_point<local_t, Duration>;
203using local_seconds = local_time<std::chrono::seconds>;
204using local_days = local_time<days>;
239CONSTCD11
month_day operator/(
const day& d,
int m) NOEXCEPT;
242CONSTCD11
month_day operator/(
int m,
const day& d) NOEXCEPT;
327 explicit CONSTCD11
day(
unsigned d) NOEXCEPT;
329 CONSTCD14
day& operator++() NOEXCEPT;
330 CONSTCD14
day operator++(
int) NOEXCEPT;
331 CONSTCD14
day& operator--() NOEXCEPT;
332 CONSTCD14
day operator--(
int) NOEXCEPT;
334 CONSTCD14
day& operator+=(
const days& d) NOEXCEPT;
335 CONSTCD14
day& operator-=(
const days& d) NOEXCEPT;
337 CONSTCD11
explicit operator unsigned()
const NOEXCEPT;
338 CONSTCD11
bool ok()
const NOEXCEPT;
341CONSTCD11
bool operator==(
const day& x,
const day& y) NOEXCEPT;
342CONSTCD11
bool operator!=(
const day& x,
const day& y) NOEXCEPT;
343CONSTCD11
bool operator< (
const day& x,
const day& y) NOEXCEPT;
344CONSTCD11
bool operator> (
const day& x,
const day& y) NOEXCEPT;
345CONSTCD11
bool operator<=(
const day& x,
const day& y) NOEXCEPT;
346CONSTCD11
bool operator>=(
const day& x,
const day& y) NOEXCEPT;
348CONSTCD11
day operator+(
const day& x,
const days& y) NOEXCEPT;
349CONSTCD11
day operator+(
const days& x,
const day& y) NOEXCEPT;
350CONSTCD11
day operator-(
const day& x,
const days& y) NOEXCEPT;
351CONSTCD11 days operator-(
const day& x,
const day& y) NOEXCEPT;
353template<
class CharT,
class Traits>
354std::basic_ostream<CharT, Traits>&
355operator<<(std::basic_ostream<CharT, Traits>& os,
const day& d);
365 explicit CONSTCD11
month(
unsigned m) NOEXCEPT;
367 CONSTCD14
month& operator++() NOEXCEPT;
368 CONSTCD14
month operator++(
int) NOEXCEPT;
369 CONSTCD14
month& operator--() NOEXCEPT;
370 CONSTCD14
month operator--(
int) NOEXCEPT;
372 CONSTCD14
month& operator+=(
const months& m) NOEXCEPT;
373 CONSTCD14
month& operator-=(
const months& m) NOEXCEPT;
375 CONSTCD11
explicit operator unsigned()
const NOEXCEPT;
376 CONSTCD11
bool ok()
const NOEXCEPT;
379CONSTCD11
bool operator==(
const month& x,
const month& y) NOEXCEPT;
380CONSTCD11
bool operator!=(
const month& x,
const month& y) NOEXCEPT;
381CONSTCD11
bool operator< (
const month& x,
const month& y) NOEXCEPT;
382CONSTCD11
bool operator> (
const month& x,
const month& y) NOEXCEPT;
383CONSTCD11
bool operator<=(
const month& x,
const month& y) NOEXCEPT;
384CONSTCD11
bool operator>=(
const month& x,
const month& y) NOEXCEPT;
386CONSTCD14
month operator+(
const month& x,
const months& y) NOEXCEPT;
387CONSTCD14
month operator+(
const months& x,
const month& y) NOEXCEPT;
388CONSTCD14
month operator-(
const month& x,
const months& y) NOEXCEPT;
389CONSTCD14 months operator-(
const month& x,
const month& y) NOEXCEPT;
391template<
class CharT,
class Traits>
392std::basic_ostream<CharT, Traits>&
393operator<<(std::basic_ostream<CharT, Traits>& os,
const month& m);
403 explicit CONSTCD11
year(
int y) NOEXCEPT;
405 CONSTCD14
year& operator++() NOEXCEPT;
406 CONSTCD14
year operator++(
int) NOEXCEPT;
407 CONSTCD14
year& operator--() NOEXCEPT;
408 CONSTCD14
year operator--(
int) NOEXCEPT;
410 CONSTCD14
year& operator+=(
const years& y) NOEXCEPT;
411 CONSTCD14
year& operator-=(
const years& y) NOEXCEPT;
413 CONSTCD11
year operator-()
const NOEXCEPT;
414 CONSTCD11
year operator+()
const NOEXCEPT;
416 CONSTCD11
bool is_leap()
const NOEXCEPT;
418 CONSTCD11
explicit operator int()
const NOEXCEPT;
419 CONSTCD11
bool ok()
const NOEXCEPT;
421 static CONSTCD11
year (min)() NOEXCEPT {
return year{-32767}; }
422 static CONSTCD11
year (max)() NOEXCEPT {
return year{32767}; }
425CONSTCD11
bool operator==(
const year& x,
const year& y) NOEXCEPT;
426CONSTCD11
bool operator!=(
const year& x,
const year& y) NOEXCEPT;
427CONSTCD11
bool operator< (
const year& x,
const year& y) NOEXCEPT;
428CONSTCD11
bool operator> (
const year& x,
const year& y) NOEXCEPT;
429CONSTCD11
bool operator<=(
const year& x,
const year& y) NOEXCEPT;
430CONSTCD11
bool operator>=(
const year& x,
const year& y) NOEXCEPT;
432CONSTCD11
year operator+(
const year& x,
const years& y) NOEXCEPT;
433CONSTCD11
year operator+(
const years& x,
const year& y) NOEXCEPT;
434CONSTCD11
year operator-(
const year& x,
const years& y) NOEXCEPT;
435CONSTCD11 years operator-(
const year& x,
const year& y) NOEXCEPT;
437template<
class CharT,
class Traits>
438std::basic_ostream<CharT, Traits>&
439operator<<(std::basic_ostream<CharT, Traits>& os,
const year& y);
448 explicit CONSTCD11
weekday(
unsigned wd) NOEXCEPT;
449 CONSTCD14
weekday(
const sys_days& dp) NOEXCEPT;
450 CONSTCD14
explicit weekday(
const local_days& dp) NOEXCEPT;
452 CONSTCD14
weekday& operator++() NOEXCEPT;
453 CONSTCD14
weekday operator++(
int) NOEXCEPT;
454 CONSTCD14
weekday& operator--() NOEXCEPT;
455 CONSTCD14
weekday operator--(
int) NOEXCEPT;
457 CONSTCD14
weekday& operator+=(
const days& d) NOEXCEPT;
458 CONSTCD14
weekday& operator-=(
const days& d) NOEXCEPT;
460 CONSTCD11
bool ok()
const NOEXCEPT;
462 CONSTCD11
unsigned c_encoding()
const NOEXCEPT;
463 CONSTCD11
unsigned iso_encoding()
const NOEXCEPT;
469 static CONSTCD14
unsigned char weekday_from_days(
int z) NOEXCEPT;
471 friend CONSTCD11
bool operator==(
const weekday& x,
const weekday& y) NOEXCEPT;
472 friend CONSTCD14 days operator-(
const weekday& x,
const weekday& y) NOEXCEPT;
473 friend CONSTCD14
weekday operator+(
const weekday& x,
const days& y) NOEXCEPT;
474 template<
class CharT,
class Traits>
475 friend std::basic_ostream<CharT, Traits>&
476 operator<<(std::basic_ostream<CharT, Traits>& os,
const weekday& wd);
480CONSTCD11
bool operator==(
const weekday& x,
const weekday& y) NOEXCEPT;
481CONSTCD11
bool operator!=(
const weekday& x,
const weekday& y) NOEXCEPT;
483CONSTCD14
weekday operator+(
const weekday& x,
const days& y) NOEXCEPT;
484CONSTCD14
weekday operator+(
const days& x,
const weekday& y) NOEXCEPT;
485CONSTCD14
weekday operator-(
const weekday& x,
const days& y) NOEXCEPT;
486CONSTCD14 days operator-(
const weekday& x,
const weekday& y) NOEXCEPT;
488template<
class CharT,
class Traits>
489std::basic_ostream<CharT, Traits>&
490operator<<(std::basic_ostream<CharT, Traits>& os,
const weekday& wd);
496 unsigned char wd_ : 4;
497 unsigned char index_ : 4;
504 CONSTCD11
unsigned index()
const NOEXCEPT;
505 CONSTCD11
bool ok()
const NOEXCEPT;
511template<
class CharT,
class Traits>
512std::basic_ostream<CharT, Traits>&
513operator<<(std::basic_ostream<CharT, Traits>& os,
const weekday_indexed& wdi);
525 CONSTCD11
bool ok()
const NOEXCEPT;
531template<
class CharT,
class Traits>
532std::basic_ostream<CharT, Traits>&
533operator<<(std::basic_ostream<CharT, Traits>& os,
const weekday_last& wdl);
556 template<
class = detail::unspecified_month_disambiguator>
557 CONSTCD14
year_month& operator+=(
const months& dm) NOEXCEPT;
558 template<
class = detail::unspecified_month_disambiguator>
559 CONSTCD14
year_month& operator-=(
const months& dm) NOEXCEPT;
560 CONSTCD14
year_month& operator+=(
const years& dy) NOEXCEPT;
561 CONSTCD14
year_month& operator-=(
const years& dy) NOEXCEPT;
563 CONSTCD11
bool ok()
const NOEXCEPT;
573template<
class = detail::unspecified_month_disambiguator>
575template<
class = detail::unspecified_month_disambiguator>
577template<
class = detail::unspecified_month_disambiguator>
585template<
class CharT,
class Traits>
586std::basic_ostream<CharT, Traits>&
587operator<<(std::basic_ostream<CharT, Traits>& os,
const year_month& ym);
603 CONSTCD14
bool ok()
const NOEXCEPT;
613template<
class CharT,
class Traits>
614std::basic_ostream<CharT, Traits>&
615operator<<(std::basic_ostream<CharT, Traits>& os,
const month_day& md);
627 CONSTCD11
bool ok()
const NOEXCEPT;
637template<
class CharT,
class Traits>
638std::basic_ostream<CharT, Traits>&
639operator<<(std::basic_ostream<CharT, Traits>& os,
const month_day_last& mdl);
654 CONSTCD11
bool ok()
const NOEXCEPT;
660template<
class CharT,
class Traits>
661std::basic_ostream<CharT, Traits>&
662operator<<(std::basic_ostream<CharT, Traits>& os,
const month_weekday& mwd);
678 CONSTCD11
bool ok()
const NOEXCEPT;
686template<
class CharT,
class Traits>
687std::basic_ostream<CharT, Traits>&
707 template<
class = detail::unspecified_month_disambiguator>
709 template<
class = detail::unspecified_month_disambiguator>
718 CONSTCD14
operator sys_days()
const NOEXCEPT;
719 CONSTCD14
explicit operator local_days()
const NOEXCEPT;
720 CONSTCD14
bool ok()
const NOEXCEPT;
724 CONSTCD14 days to_days()
const NOEXCEPT;
734template<
class = detail::unspecified_month_disambiguator>
736template<
class = detail::unspecified_month_disambiguator>
738template<
class = detail::unspecified_month_disambiguator>
744template<
class CharT,
class Traits>
745std::basic_ostream<CharT, Traits>&
746operator<<(std::basic_ostream<CharT, Traits>& os,
const year_month_day& ymd);
759 template<
class = detail::unspecified_month_disambiguator>
761 template<
class = detail::unspecified_month_disambiguator>
771 CONSTCD14
operator sys_days()
const NOEXCEPT;
772 CONSTCD14
explicit operator local_days()
const NOEXCEPT;
773 CONSTCD11
bool ok()
const NOEXCEPT;
789template<
class = detail::unspecified_month_disambiguator>
794template<
class = detail::unspecified_month_disambiguator>
807template<
class = detail::unspecified_month_disambiguator>
816template<
class CharT,
class Traits>
817std::basic_ostream<CharT, Traits>&
835 template<
class = detail::unspecified_month_disambiguator>
837 template<
class = detail::unspecified_month_disambiguator>
845 CONSTCD11
unsigned index()
const NOEXCEPT;
848 CONSTCD14
operator sys_days()
const NOEXCEPT;
849 CONSTCD14
explicit operator local_days()
const NOEXCEPT;
850 CONSTCD14
bool ok()
const NOEXCEPT;
854 CONSTCD14 days to_days()
const NOEXCEPT;
862template<
class = detail::unspecified_month_disambiguator>
867template<
class = detail::unspecified_month_disambiguator>
880template<
class = detail::unspecified_month_disambiguator>
889template<
class CharT,
class Traits>
890std::basic_ostream<CharT, Traits>&
905 template<
class = detail::unspecified_month_disambiguator>
907 template<
class = detail::unspecified_month_disambiguator>
917 CONSTCD14
operator sys_days()
const NOEXCEPT;
918 CONSTCD14
explicit operator local_days()
const NOEXCEPT;
919 CONSTCD11
bool ok()
const NOEXCEPT;
922 CONSTCD14 days to_days()
const NOEXCEPT;
933template<
class = detail::unspecified_month_disambiguator>
938template<
class = detail::unspecified_month_disambiguator>
951template<
class = detail::unspecified_month_disambiguator>
960template<
class CharT,
class Traits>
961std::basic_ostream<CharT, Traits>&
964#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
965inline namespace literals
968CONSTCD11
date::day operator "" _d(
unsigned long long d) NOEXCEPT;
969CONSTCD11
date::year operator "" _y(
unsigned long long y) NOEXCEPT;
997template <
class T,
class = std::
void_t<>>
1003struct is_clock<T, std::void_t<decltype(T::now()), typename T::rep, typename T::period,
1004 typename T::duration, typename T::time_point,
1005 decltype(T::is_steady)>>
1018template<
class CharT,
class Traits = std::
char_traits<CharT>>
1022 std::basic_ios<CharT, Traits>& is_;
1024 std::ios::fmtflags flags_;
1025 std::streamsize width_;
1026 std::basic_ostream<CharT, Traits>* tie_;
1042 explicit save_istream(std::basic_ios<CharT, Traits>& is)
1045 , flags_(is.flags())
1046 , width_(is.width(0))
1047 , tie_(is.tie(
nullptr))
1050 if (tie_ !=
nullptr)
1055template<
class CharT,
class Traits = std::
char_traits<CharT>>
1062 if ((this->flags_ & std::ios::unitbuf) &&
1063#
if HAS_UNCAUGHT_EXCEPTIONS
1064 std::uncaught_exceptions() == 0 &&
1066 !std::uncaught_exception() &&
1069 this->is_.rdbuf()->pubsync();
1075 explicit save_ostream(std::basic_ios<CharT, Traits>& os)
1084 static const int digits = std::numeric_limits<T>::digits;
1085 using type =
typename std::conditional
1089 typename std::conditional
1093#ifdef __SIZEOF_INT128__
1105typename std::enable_if
1107 !std::chrono::treat_as_floating_point<T>::value,
1118typename std::enable_if
1120 std::chrono::treat_as_floating_point<T>::value,
1125 using std::numeric_limits;
1126 using I =
typename choose_trunc_type<T>::type;
1127 CONSTDATA
auto digits = numeric_limits<T>::digits;
1128 static_assert(digits < numeric_limits<I>::digits,
"");
1129 CONSTDATA
auto max = I{1} << (digits-1);
1130 CONSTDATA
auto min = -max;
1131 const auto negative = t < T{0};
1132 if (min <= t && t <= max && t != 0 && t == t)
1134 t =
static_cast<T
>(
static_cast<I
>(t));
1135 if (t == 0 && negative)
1141template <std::
intmax_t Xp, std::
intmax_t Yp>
1147template <std::
intmax_t Xp>
1150 static const std::intmax_t value = Xp;
1156 static const std::intmax_t value = 1;
1159template <
class R1,
class R2>
1165 static const std::intmax_t n1 = R1::num / gcd_n1_n2;
1166 static const std::intmax_t d1 = R1::den / gcd_d1_d2;
1167 static const std::intmax_t n2 = R2::num / gcd_n1_n2;
1168 static const std::intmax_t d2 = R2::den / gcd_d1_d2;
1169 static const std::intmax_t max = (std::numeric_limits<std::intmax_t>::max)();
1171 template <std::
intmax_t Xp, std::
intmax_t Yp,
bool overflow>
1174 static const std::intmax_t value = Xp * Yp;
1177 template <std::
intmax_t Xp, std::
intmax_t Yp>
1178 struct mul<Xp, Yp, true>
1180 static const std::intmax_t value = 1;
1184 static const bool value = (n1 <= max / d2) && (n2 <= max / d1);
1185 typedef std::ratio<mul<n1, d2, !value>::value,
1186 mul<n2, d1, !value>::value> type;
1192template <
class To,
class Rep,
class Period>
1195typename std::enable_if
1200trunc(
const std::chrono::duration<Rep, Period>& d)
1202 return To{detail::trunc(std::chrono::duration_cast<To>(d).count())};
1205template <
class To,
class Rep,
class Period>
1208typename std::enable_if
1210 !detail::no_overflow<Period, typename To::period>::value,
1213trunc(
const std::chrono::duration<Rep, Period>& d)
1215 using std::chrono::duration_cast;
1216 using std::chrono::duration;
1217 using rep =
typename std::common_type<Rep, typename To::rep>::type;
1218 return To{detail::trunc(duration_cast<To>(duration_cast<duration<rep>>(d)).count())};
1221#ifndef HAS_CHRONO_ROUNDING
1222# if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 190023918 || (_MSC_FULL_VER >= 190000000 && defined (__clang__)))
1223# define HAS_CHRONO_ROUNDING 1
1224# elif defined(__cpp_lib_chrono) && __cplusplus > 201402 && __cpp_lib_chrono >= 201510
1225# define HAS_CHRONO_ROUNDING 1
1226# elif defined(_LIBCPP_VERSION) && __cplusplus > 201402 && _LIBCPP_VERSION >= 3800
1227# define HAS_CHRONO_ROUNDING 1
1229# define HAS_CHRONO_ROUNDING 0
1233#if HAS_CHRONO_ROUNDING == 0
1236template <
class To,
class Rep,
class Period>
1239typename std::enable_if
1241 detail::no_overflow<Period, typename To::period>::value,
1244floor(
const std::chrono::duration<Rep, Period>& d)
1246 auto t = trunc<To>(d);
1252template <
class To,
class Rep,
class Period>
1255typename std::enable_if
1257 !detail::no_overflow<Period, typename To::period>::value,
1260floor(
const std::chrono::duration<Rep, Period>& d)
1262 using rep =
typename std::common_type<Rep, typename To::rep>::type;
1263 return floor<To>(floor<std::chrono::duration<rep>>(d));
1267template <
class To,
class Rep,
class Period>
1271round(
const std::chrono::duration<Rep, Period>& d)
1273 auto t0 = floor<To>(d);
1274 auto t1 = t0 + To{1};
1275 if (t1 == To{0} && t0 < To{0})
1277 auto diff0 = d - t0;
1278 auto diff1 = t1 - d;
1281 if (t0 - trunc<To>(t0/2)*2 == To{0})
1291template <
class To,
class Rep,
class Period>
1295ceil(
const std::chrono::duration<Rep, Period>& d)
1297 auto t = trunc<To>(d);
1303template <
class Rep,
class Period,
1304 class =
typename std::enable_if
1306 std::numeric_limits<Rep>::is_signed
1309std::chrono::duration<Rep, Period>
1310abs(std::chrono::duration<Rep, Period> d)
1312 return d >= d.zero() ? d : -d;
1316template <
class To,
class Clock,
class FromDuration>
1319std::chrono::time_point<Clock, To>
1320floor(
const std::chrono::time_point<Clock, FromDuration>& tp)
1322 using std::chrono::time_point;
1323 return time_point<Clock, To>{date::floor<To>(tp.time_since_epoch())};
1327template <
class To,
class Clock,
class FromDuration>
1330std::chrono::time_point<Clock, To>
1331round(
const std::chrono::time_point<Clock, FromDuration>& tp)
1333 using std::chrono::time_point;
1334 return time_point<Clock, To>{round<To>(tp.time_since_epoch())};
1338template <
class To,
class Clock,
class FromDuration>
1341std::chrono::time_point<Clock, To>
1342ceil(
const std::chrono::time_point<Clock, FromDuration>& tp)
1344 using std::chrono::time_point;
1345 return time_point<Clock, To>{ceil<To>(tp.time_since_epoch())};
1350using std::chrono::floor;
1351using std::chrono::ceil;
1352using std::chrono::round;
1353using std::chrono::abs;
1358template <
class To,
class Clock,
class FromDuration>
1361std::chrono::time_point<Clock, To>
1362trunc(
const std::chrono::time_point<Clock, FromDuration>& tp)
1364 using std::chrono::time_point;
1365 return time_point<Clock, To>{trunc<To>(tp.time_since_epoch())};
1370CONSTCD11
inline day::day(
unsigned d) NOEXCEPT : d_(
static_cast<decltype(d_)
>(d)) {}
1371CONSTCD14
inline day& day::operator++() NOEXCEPT {++d_;
return *
this;}
1372CONSTCD14
inline day day::operator++(
int) NOEXCEPT {
auto tmp(*
this); ++(*this);
return tmp;}
1373CONSTCD14
inline day& day::operator--() NOEXCEPT {--d_;
return *
this;}
1374CONSTCD14
inline day day::operator--(
int) NOEXCEPT {
auto tmp(*
this); --(*this);
return tmp;}
1375CONSTCD14
inline day& day::operator+=(
const days& d) NOEXCEPT {*
this = *
this + d;
return *
this;}
1376CONSTCD14
inline day& day::operator-=(
const days& d) NOEXCEPT {*
this = *
this - d;
return *
this;}
1377CONSTCD11
inline day::operator unsigned() const NOEXCEPT {
return d_;}
1378CONSTCD11
inline bool day::ok() const NOEXCEPT {
return 1 <= d_ && d_ <= 31;}
1383operator==(
const day& x,
const day& y) NOEXCEPT
1385 return static_cast<unsigned>(x) ==
static_cast<unsigned>(y);
1391operator!=(
const day& x,
const day& y) NOEXCEPT
1399operator<(
const day& x,
const day& y) NOEXCEPT
1401 return static_cast<unsigned>(x) <
static_cast<unsigned>(y);
1407operator>(
const day& x,
const day& y) NOEXCEPT
1415operator<=(
const day& x,
const day& y) NOEXCEPT
1423operator>=(
const day& x,
const day& y) NOEXCEPT
1431operator-(
const day& x,
const day& y) NOEXCEPT
1433 return days{
static_cast<days::rep
>(
static_cast<unsigned>(x)
1434 -
static_cast<unsigned>(y))};
1440operator+(
const day& x,
const days& y) NOEXCEPT
1442 return day{
static_cast<unsigned>(x) +
static_cast<unsigned>(y.count())};
1448operator+(
const days& x,
const day& y) NOEXCEPT
1456operator-(
const day& x,
const days& y) NOEXCEPT
1461template<
class CharT,
class Traits>
1463std::basic_ostream<CharT, Traits>&
1464operator<<(std::basic_ostream<CharT, Traits>& os,
const day& d)
1466 detail::save_ostream<CharT, Traits> _(os);
1468 os.flags(std::ios::dec | std::ios::right);
1470 os << static_cast<unsigned>(d);
1472 os <<
" is not a valid day";
1478CONSTCD11
inline month::month(
unsigned m) NOEXCEPT : m_(
static_cast<decltype(m_)
>(m)) {}
1479CONSTCD14
inline month& month::operator++() NOEXCEPT {*
this += months{1};
return *
this;}
1480CONSTCD14
inline month month::operator++(
int) NOEXCEPT {
auto tmp(*
this); ++(*this);
return tmp;}
1481CONSTCD14
inline month& month::operator--() NOEXCEPT {*
this -= months{1};
return *
this;}
1482CONSTCD14
inline month month::operator--(
int) NOEXCEPT {
auto tmp(*
this); --(*this);
return tmp;}
1487month::operator+=(
const months& m) NOEXCEPT
1496month::operator-=(
const months& m) NOEXCEPT
1502CONSTCD11
inline month::operator unsigned() const NOEXCEPT {
return m_;}
1503CONSTCD11
inline bool month::ok() const NOEXCEPT {
return 1 <= m_ && m_ <= 12;}
1508operator==(
const month& x,
const month& y) NOEXCEPT
1510 return static_cast<unsigned>(x) ==
static_cast<unsigned>(y);
1516operator!=(
const month& x,
const month& y) NOEXCEPT
1524operator<(
const month& x,
const month& y) NOEXCEPT
1526 return static_cast<unsigned>(x) <
static_cast<unsigned>(y);
1532operator>(
const month& x,
const month& y) NOEXCEPT
1540operator<=(
const month& x,
const month& y) NOEXCEPT
1548operator>=(
const month& x,
const month& y) NOEXCEPT
1556operator-(
const month& x,
const month& y) NOEXCEPT
1558 auto const d =
static_cast<unsigned>(x) -
static_cast<unsigned>(y);
1559 return months(d <= 11 ? d : d + 12);
1565operator+(
const month& x,
const months& y) NOEXCEPT
1567 auto const mu =
static_cast<long long>(
static_cast<unsigned>(x)) + y.count() - 1;
1568 auto const yr = (mu >= 0 ? mu : mu-11) / 12;
1569 return month{
static_cast<unsigned>(mu - yr * 12 + 1)};
1575operator+(
const months& x,
const month& y) NOEXCEPT
1583operator-(
const month& x,
const months& y) NOEXCEPT
1588template<
class CharT,
class Traits>
1590std::basic_ostream<CharT, Traits>&
1591operator<<(std::basic_ostream<CharT, Traits>& os,
const month& m)
1595 CharT fmt[] = {
'%',
'b', 0};
1596 os << format(os.getloc(), fmt, m);
1599 os << static_cast<unsigned>(m) <<
" is not a valid month";
1605CONSTCD11
inline year::year(
int y) NOEXCEPT : y_(
static_cast<decltype(y_)
>(y)) {}
1606CONSTCD14
inline year& year::operator++() NOEXCEPT {++y_;
return *
this;}
1607CONSTCD14
inline year year::operator++(
int) NOEXCEPT {
auto tmp(*
this); ++(*this);
return tmp;}
1608CONSTCD14
inline year& year::operator--() NOEXCEPT {--y_;
return *
this;}
1609CONSTCD14
inline year year::operator--(
int) NOEXCEPT {
auto tmp(*
this); --(*this);
return tmp;}
1610CONSTCD14
inline year& year::operator+=(
const years& y) NOEXCEPT {*
this = *
this + y;
return *
this;}
1611CONSTCD14
inline year& year::operator-=(
const years& y) NOEXCEPT {*
this = *
this - y;
return *
this;}
1612CONSTCD11
inline year year::operator-() const NOEXCEPT {
return year{-y_};}
1613CONSTCD11
inline year year::operator+() const NOEXCEPT {
return *
this;}
1618year::is_leap() const NOEXCEPT
1620 return y_ % 4 == 0 && (y_ % 100 != 0 || y_ % 400 == 0);
1623CONSTCD11
inline year::operator int() const NOEXCEPT {
return y_;}
1628year::ok() const NOEXCEPT
1630 return y_ != (std::numeric_limits<short>::min)();
1636operator==(
const year& x,
const year& y) NOEXCEPT
1638 return static_cast<int>(x) ==
static_cast<int>(y);
1644operator!=(
const year& x,
const year& y) NOEXCEPT
1652operator<(
const year& x,
const year& y) NOEXCEPT
1654 return static_cast<int>(x) <
static_cast<int>(y);
1660operator>(
const year& x,
const year& y) NOEXCEPT
1668operator<=(
const year& x,
const year& y) NOEXCEPT
1676operator>=(
const year& x,
const year& y) NOEXCEPT
1684operator-(
const year& x,
const year& y) NOEXCEPT
1686 return years{
static_cast<int>(x) -
static_cast<int>(y)};
1692operator+(
const year& x,
const years& y) NOEXCEPT
1694 return year{
static_cast<int>(x) + y.count()};
1700operator+(
const years& x,
const year& y) NOEXCEPT
1708operator-(
const year& x,
const years& y) NOEXCEPT
1710 return year{
static_cast<int>(x) - y.count()};
1713template<
class CharT,
class Traits>
1715std::basic_ostream<CharT, Traits>&
1716operator<<(std::basic_ostream<CharT, Traits>& os,
const year& y)
1718 detail::save_ostream<CharT, Traits> _(os);
1720 os.flags(std::ios::dec | std::ios::internal);
1721 os.width(4 + (y < year{0}));
1722 os.imbue(std::locale::classic());
1723 os << static_cast<int>(y);
1725 os <<
" is not a valid year";
1734weekday::weekday_from_days(
int z) NOEXCEPT
1736 auto u =
static_cast<unsigned>(z);
1737 return static_cast<unsigned char>(z >= -4 ? (u+4) % 7 : u % 7);
1742weekday::weekday(
unsigned wd) NOEXCEPT
1743 : wd_(
static_cast<decltype(wd_)
>(wd != 7 ? wd : 0))
1748weekday::weekday(
const sys_days& dp) NOEXCEPT
1749 : wd_(weekday_from_days(dp.time_since_epoch().count()))
1754weekday::weekday(
const local_days& dp) NOEXCEPT
1755 : wd_(weekday_from_days(dp.time_since_epoch().count()))
1758CONSTCD14
inline weekday& weekday::operator++() NOEXCEPT {*
this += days{1};
return *
this;}
1759CONSTCD14
inline weekday weekday::operator++(
int) NOEXCEPT {
auto tmp(*
this); ++(*this);
return tmp;}
1760CONSTCD14
inline weekday& weekday::operator--() NOEXCEPT {*
this -= days{1};
return *
this;}
1761CONSTCD14
inline weekday weekday::operator--(
int) NOEXCEPT {
auto tmp(*
this); --(*this);
return tmp;}
1766weekday::operator+=(
const days& d) NOEXCEPT
1775weekday::operator-=(
const days& d) NOEXCEPT
1781CONSTCD11
inline bool weekday::ok() const NOEXCEPT {
return wd_ <= 6;}
1785unsigned weekday::c_encoding() const NOEXCEPT
1787 return unsigned{wd_};
1792unsigned weekday::iso_encoding() const NOEXCEPT
1794 return unsigned{((wd_ == 0u) ? 7u : wd_)};
1800operator==(
const weekday& x,
const weekday& y) NOEXCEPT
1802 return x.wd_ == y.wd_;
1808operator!=(
const weekday& x,
const weekday& y) NOEXCEPT
1816operator-(
const weekday& x,
const weekday& y) NOEXCEPT
1818 auto const wdu = x.wd_ - y.wd_;
1819 auto const wk = (wdu >= 0 ? wdu : wdu-6) / 7;
1820 return days{wdu - wk * 7};
1826operator+(
const weekday& x,
const days& y) NOEXCEPT
1828 auto const wdu =
static_cast<long long>(
static_cast<unsigned>(x.wd_)) + y.count();
1829 auto const wk = (wdu >= 0 ? wdu : wdu-6) / 7;
1830 return weekday{
static_cast<unsigned>(wdu - wk * 7)};
1836operator+(
const days& x,
const weekday& y) NOEXCEPT
1844operator-(
const weekday& x,
const days& y) NOEXCEPT
1849template<
class CharT,
class Traits>
1851std::basic_ostream<CharT, Traits>&
1852operator<<(std::basic_ostream<CharT, Traits>& os,
const weekday& wd)
1856 CharT fmt[] = {
'%',
'a', 0};
1857 os << format(fmt, wd);
1860 os << static_cast<unsigned>(wd.wd_) <<
" is not a valid weekday";
1864#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
1865inline namespace literals
1871operator "" _d(
unsigned long long d) NOEXCEPT
1873 return date::day{
static_cast<unsigned>(d)};
1879operator "" _y(
unsigned long long y) NOEXCEPT
1908#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
1938weekday_indexed::weekday() const NOEXCEPT
1943CONSTCD11
inline unsigned weekday_indexed::index() const NOEXCEPT {
return index_;}
1948weekday_indexed::ok() const NOEXCEPT
1950 return weekday().ok() && 1 <= index_ && index_ <= 5;
1954# pragma GCC diagnostic push
1955# pragma GCC diagnostic ignored "-Wconversion"
1960weekday_indexed::weekday_indexed(
const date::weekday& wd,
unsigned index) NOEXCEPT
1961 : wd_(
static_cast<decltype(wd_)
>(
static_cast<unsigned>(wd.wd_)))
1962 , index_(
static_cast<decltype(index_)
>(index))
1966# pragma GCC diagnostic pop
1969template<
class CharT,
class Traits>
1971std::basic_ostream<CharT, Traits>&
1972operator<<(std::basic_ostream<CharT, Traits>& os,
const weekday_indexed& wdi)
1974 os << wdi.weekday() <<
'[' << wdi.index();
1975 if (!(1 <= wdi.index() && wdi.index() <= 5))
1976 os <<
" is not a valid index";
1984weekday::operator[](
unsigned index)
const NOEXCEPT
1986 return {*
this, index};
1992operator==(
const weekday_indexed& x,
const weekday_indexed& y) NOEXCEPT
1994 return x.weekday() == y.weekday() && x.index() == y.index();
2000operator!=(
const weekday_indexed& x,
const weekday_indexed& y) NOEXCEPT
2007CONSTCD11
inline date::weekday weekday_last::weekday() const NOEXCEPT {
return wd_;}
2008CONSTCD11
inline bool weekday_last::ok() const NOEXCEPT {
return wd_.ok();}
2009CONSTCD11
inline weekday_last::weekday_last(
const date::weekday& wd) NOEXCEPT : wd_(wd) {}
2014operator==(
const weekday_last& x,
const weekday_last& y) NOEXCEPT
2016 return x.weekday() == y.weekday();
2022operator!=(
const weekday_last& x,
const weekday_last& y) NOEXCEPT
2027template<
class CharT,
class Traits>
2029std::basic_ostream<CharT, Traits>&
2030operator<<(std::basic_ostream<CharT, Traits>& os,
const weekday_last& wdl)
2032 return os << wdl.weekday() <<
"[last]";
2038weekday::operator[](last_spec)
const NOEXCEPT
2040 return weekday_last{*
this};
2052CONSTCD11
inline year year_month::year() const NOEXCEPT {
return y_;}
2053CONSTCD11
inline month year_month::month() const NOEXCEPT {
return m_;}
2054CONSTCD11
inline bool year_month::ok() const NOEXCEPT {
return y_.ok() && m_.ok();}
2060year_month::operator+=(
const months& dm) NOEXCEPT
2070year_month::operator-=(
const months& dm) NOEXCEPT
2079year_month::operator+=(
const years& dy) NOEXCEPT
2088year_month::operator-=(
const years& dy) NOEXCEPT
2097operator==(
const year_month& x,
const year_month& y) NOEXCEPT
2099 return x.year() == y.year() && x.month() == y.month();
2105operator!=(
const year_month& x,
const year_month& y) NOEXCEPT
2113operator<(
const year_month& x,
const year_month& y) NOEXCEPT
2115 return x.year() < y.year() ? true
2116 : (x.year() > y.year() ? false
2117 : (x.month() < y.month()));
2123operator>(
const year_month& x,
const year_month& y) NOEXCEPT
2131operator<=(
const year_month& x,
const year_month& y) NOEXCEPT
2139operator>=(
const year_month& x,
const year_month& y) NOEXCEPT
2148operator+(
const year_month& ym,
const months& dm) NOEXCEPT
2150 auto dmi =
static_cast<int>(
static_cast<unsigned>(ym.month())) - 1 + dm.count();
2151 auto dy = (dmi >= 0 ? dmi : dmi-11) / 12;
2152 dmi = dmi - dy * 12 + 1;
2153 return (ym.year() + years(dy)) / month(
static_cast<unsigned>(dmi));
2160operator+(
const months& dm,
const year_month& ym) NOEXCEPT
2169operator-(
const year_month& ym,
const months& dm) NOEXCEPT
2177operator-(
const year_month& x,
const year_month& y) NOEXCEPT
2179 return (x.year() - y.year()) +
2180 months(
static_cast<unsigned>(x.month()) -
static_cast<unsigned>(y.month()));
2186operator+(
const year_month& ym,
const years& dy) NOEXCEPT
2188 return (ym.year() + dy) / ym.month();
2194operator+(
const years& dy,
const year_month& ym) NOEXCEPT
2202operator-(
const year_month& ym,
const years& dy) NOEXCEPT
2207template<
class CharT,
class Traits>
2209std::basic_ostream<CharT, Traits>&
2210operator<<(std::basic_ostream<CharT, Traits>& os,
const year_month& ym)
2212 return os << ym.year() <<
'/' << ym.month();
2224CONSTCD11
inline date::month month_day::month() const NOEXCEPT {
return m_;}
2225CONSTCD11
inline date::day month_day::day() const NOEXCEPT {
return d_;}
2230month_day::ok() const NOEXCEPT
2239 return m_.ok() &&
date::day{1} <= d_ && d_ <= d[static_cast<unsigned>(m_)-1];
2245operator==(
const month_day& x,
const month_day& y) NOEXCEPT
2247 return x.month() == y.month() && x.day() == y.day();
2253operator!=(
const month_day& x,
const month_day& y) NOEXCEPT
2261operator<(
const month_day& x,
const month_day& y) NOEXCEPT
2263 return x.month() < y.month() ? true
2264 : (x.month() > y.month() ? false
2265 : (x.day() < y.day()));
2271operator>(
const month_day& x,
const month_day& y) NOEXCEPT
2279operator<=(
const month_day& x,
const month_day& y) NOEXCEPT
2287operator>=(
const month_day& x,
const month_day& y) NOEXCEPT
2292template<
class CharT,
class Traits>
2294std::basic_ostream<CharT, Traits>&
2295operator<<(std::basic_ostream<CharT, Traits>& os,
const month_day& md)
2297 return os << md.month() <<
'/' << md.day();
2302CONSTCD11
inline month month_day_last::month() const NOEXCEPT {
return m_;}
2303CONSTCD11
inline bool month_day_last::ok() const NOEXCEPT {
return m_.ok();}
2304CONSTCD11
inline month_day_last::month_day_last(
const date::month& m) NOEXCEPT : m_(m) {}
2309operator==(
const month_day_last& x,
const month_day_last& y) NOEXCEPT
2311 return x.month() == y.month();
2317operator!=(
const month_day_last& x,
const month_day_last& y) NOEXCEPT
2325operator<(
const month_day_last& x,
const month_day_last& y) NOEXCEPT
2327 return x.month() < y.month();
2333operator>(
const month_day_last& x,
const month_day_last& y) NOEXCEPT
2341operator<=(
const month_day_last& x,
const month_day_last& y) NOEXCEPT
2349operator>=(
const month_day_last& x,
const month_day_last& y) NOEXCEPT
2354template<
class CharT,
class Traits>
2356std::basic_ostream<CharT, Traits>&
2357operator<<(std::basic_ostream<CharT, Traits>& os,
const month_day_last& mdl)
2359 return os << mdl.month() <<
"/last";
2372CONSTCD11
inline month month_weekday::month() const NOEXCEPT {
return m_;}
2377month_weekday::weekday_indexed() const NOEXCEPT
2385month_weekday::ok() const NOEXCEPT
2387 return m_.ok() && wdi_.ok();
2393operator==(
const month_weekday& x,
const month_weekday& y) NOEXCEPT
2395 return x.month() == y.month() && x.weekday_indexed() == y.weekday_indexed();
2401operator!=(
const month_weekday& x,
const month_weekday& y) NOEXCEPT
2406template<
class CharT,
class Traits>
2408std::basic_ostream<CharT, Traits>&
2409operator<<(std::basic_ostream<CharT, Traits>& os,
const month_weekday& mwd)
2411 return os << mwd.month() <<
'/' << mwd.weekday_indexed();
2418month_weekday_last::month_weekday_last(
const date::month& m,
2424CONSTCD11
inline month month_weekday_last::month() const NOEXCEPT {
return m_;}
2429month_weekday_last::weekday_last() const NOEXCEPT
2437month_weekday_last::ok() const NOEXCEPT
2439 return m_.ok() && wdl_.ok();
2445operator==(
const month_weekday_last& x,
const month_weekday_last& y) NOEXCEPT
2447 return x.month() == y.month() && x.weekday_last() == y.weekday_last();
2453operator!=(
const month_weekday_last& x,
const month_weekday_last& y) NOEXCEPT
2458template<
class CharT,
class Traits>
2460std::basic_ostream<CharT, Traits>&
2461operator<<(std::basic_ostream<CharT, Traits>& os,
const month_weekday_last& mwdl)
2463 return os << mwdl.month() <<
'/' << mwdl.weekday_last();
2470year_month_day_last::year_month_day_last(
const date::year& y,
2480year_month_day_last::operator+=(
const months& m) NOEXCEPT
2490year_month_day_last::operator-=(
const months& m) NOEXCEPT
2499year_month_day_last::operator+=(
const years& y) NOEXCEPT
2508year_month_day_last::operator-=(
const years& y) NOEXCEPT
2514CONSTCD11
inline year year_month_day_last::year() const NOEXCEPT {
return y_;}
2515CONSTCD11
inline month year_month_day_last::month() const NOEXCEPT {
return mdl_.month();}
2520year_month_day_last::month_day_last() const NOEXCEPT
2528year_month_day_last::day() const NOEXCEPT
2537 return (month() != February || !y_.is_leap()) && mdl_.ok() ?
2538 d[
static_cast<unsigned>(month()) - 1] :
date::day{29};
2543year_month_day_last::operator sys_days() const NOEXCEPT
2545 return sys_days(year()/month()/day());
2550year_month_day_last::operator local_days() const NOEXCEPT
2552 return local_days(year()/month()/day());
2558year_month_day_last::ok() const NOEXCEPT
2560 return y_.ok() && mdl_.ok();
2566operator==(
const year_month_day_last& x,
const year_month_day_last& y) NOEXCEPT
2568 return x.year() == y.year() && x.month_day_last() == y.month_day_last();
2574operator!=(
const year_month_day_last& x,
const year_month_day_last& y) NOEXCEPT
2582operator<(
const year_month_day_last& x,
const year_month_day_last& y) NOEXCEPT
2584 return x.year() < y.year() ? true
2585 : (x.year() > y.year() ? false
2586 : (x.month_day_last() < y.month_day_last()));
2592operator>(
const year_month_day_last& x,
const year_month_day_last& y) NOEXCEPT
2600operator<=(
const year_month_day_last& x,
const year_month_day_last& y) NOEXCEPT
2608operator>=(
const year_month_day_last& x,
const year_month_day_last& y) NOEXCEPT
2613template<
class CharT,
class Traits>
2615std::basic_ostream<CharT, Traits>&
2616operator<<(std::basic_ostream<CharT, Traits>& os,
const year_month_day_last& ymdl)
2618 return os << ymdl.year() <<
'/' << ymdl.month_day_last();
2625operator+(
const year_month_day_last& ymdl,
const months& dm) NOEXCEPT
2627 return (ymdl.year() / ymdl.month() + dm) / last;
2634operator+(
const months& dm,
const year_month_day_last& ymdl) NOEXCEPT
2643operator-(
const year_month_day_last& ymdl,
const months& dm) NOEXCEPT
2645 return ymdl + (-dm);
2651operator+(
const year_month_day_last& ymdl,
const years& dy) NOEXCEPT
2653 return {ymdl.year()+dy, ymdl.month_day_last()};
2659operator+(
const years& dy,
const year_month_day_last& ymdl) NOEXCEPT
2667operator-(
const year_month_day_last& ymdl,
const years& dy) NOEXCEPT
2669 return ymdl + (-dy);
2685year_month_day::year_month_day(
const year_month_day_last& ymdl) NOEXCEPT
2693year_month_day::year_month_day(sys_days dp) NOEXCEPT
2694 : year_month_day(from_days(dp.time_since_epoch()))
2699year_month_day::year_month_day(local_days dp) NOEXCEPT
2700 : year_month_day(from_days(dp.time_since_epoch()))
2703CONSTCD11
inline year year_month_day::year() const NOEXCEPT {
return y_;}
2704CONSTCD11
inline month year_month_day::month() const NOEXCEPT {
return m_;}
2705CONSTCD11
inline day year_month_day::day() const NOEXCEPT {
return d_;}
2711year_month_day::operator+=(
const months& m) NOEXCEPT
2721year_month_day::operator-=(
const months& m) NOEXCEPT
2730year_month_day::operator+=(
const years& y) NOEXCEPT
2739year_month_day::operator-=(
const years& y) NOEXCEPT
2748year_month_day::to_days() const NOEXCEPT
2750 static_assert(std::numeric_limits<unsigned>::digits >= 18,
2751 "This algorithm has not been ported to a 16 bit unsigned integer");
2752 static_assert(std::numeric_limits<int>::digits >= 20,
2753 "This algorithm has not been ported to a 16 bit signed integer");
2754 auto const y =
static_cast<int>(y_) - (m_ <= February);
2755 auto const m =
static_cast<unsigned>(m_);
2756 auto const d =
static_cast<unsigned>(d_);
2757 auto const era = (y >= 0 ? y : y-399) / 400;
2758 auto const yoe =
static_cast<unsigned>(y - era * 400);
2759 auto const doy = (153*(m > 2 ? m-3 : m+9) + 2)/5 + d-1;
2760 auto const doe = yoe * 365 + yoe/4 - yoe/100 + doy;
2761 return days{era * 146097 +
static_cast<int>(doe) - 719468};
2766year_month_day::operator sys_days() const NOEXCEPT
2768 return sys_days{to_days()};
2773year_month_day::operator local_days() const NOEXCEPT
2775 return local_days{to_days()};
2781year_month_day::ok() const NOEXCEPT
2783 if (!(y_.ok() && m_.ok()))
2785 return date::day{1} <= d_ && d_ <= (y_ / m_ / last).day();
2791operator==(
const year_month_day& x,
const year_month_day& y) NOEXCEPT
2793 return x.year() == y.year() && x.month() == y.month() && x.day() == y.day();
2799operator!=(
const year_month_day& x,
const year_month_day& y) NOEXCEPT
2807operator<(
const year_month_day& x,
const year_month_day& y) NOEXCEPT
2809 return x.year() < y.year() ? true
2810 : (x.year() > y.year() ? false
2811 : (x.month() < y.month() ? true
2812 : (x.month() > y.month() ? false
2813 : (x.day() < y.day()))));
2819operator>(
const year_month_day& x,
const year_month_day& y) NOEXCEPT
2827operator<=(
const year_month_day& x,
const year_month_day& y) NOEXCEPT
2835operator>=(
const year_month_day& x,
const year_month_day& y) NOEXCEPT
2840template<
class CharT,
class Traits>
2842std::basic_ostream<CharT, Traits>&
2843operator<<(std::basic_ostream<CharT, Traits>& os,
const year_month_day& ymd)
2845 detail::save_ostream<CharT, Traits> _(os);
2847 os.flags(std::ios::dec | std::ios::right);
2848 os.imbue(std::locale::classic());
2849 os << ymd.year() <<
'-';
2851 os << static_cast<unsigned>(ymd.month()) <<
'-';
2854 os <<
" is not a valid date";
2861year_month_day::from_days(days dp) NOEXCEPT
2863 static_assert(std::numeric_limits<unsigned>::digits >= 18,
2864 "This algorithm has not been ported to a 16 bit unsigned integer");
2865 static_assert(std::numeric_limits<int>::digits >= 20,
2866 "This algorithm has not been ported to a 16 bit signed integer");
2867 auto const z = dp.count() + 719468;
2868 auto const era = (z >= 0 ? z : z - 146096) / 146097;
2869 auto const doe =
static_cast<unsigned>(z - era * 146097);
2870 auto const yoe = (doe - doe/1460 + doe/36524 - doe/146096) / 365;
2871 auto const y =
static_cast<days::rep
>(yoe) + era * 400;
2872 auto const doy = doe - (365*yoe + yoe/4 - yoe/100);
2873 auto const mp = (5*doy + 2)/153;
2874 auto const d = doy - (153*mp+2)/5 + 1;
2875 auto const m = mp < 10 ? mp+3 : mp-9;
2883operator+(
const year_month_day& ymd,
const months& dm) NOEXCEPT
2885 return (ymd.year() / ymd.month() + dm) / ymd.day();
2892operator+(
const months& dm,
const year_month_day& ymd) NOEXCEPT
2901operator-(
const year_month_day& ymd,
const months& dm) NOEXCEPT
2909operator+(
const year_month_day& ymd,
const years& dy) NOEXCEPT
2911 return (ymd.year() + dy) / ymd.month() / ymd.day();
2917operator+(
const years& dy,
const year_month_day& ymd) NOEXCEPT
2925operator-(
const year_month_day& ymd,
const years& dy) NOEXCEPT
2944year_month_weekday::year_month_weekday(
const sys_days& dp) NOEXCEPT
2945 : year_month_weekday(from_days(dp.time_since_epoch()))
2950year_month_weekday::year_month_weekday(
const local_days& dp) NOEXCEPT
2951 : year_month_weekday(from_days(dp.time_since_epoch()))
2958year_month_weekday::operator+=(
const months& m) NOEXCEPT
2968year_month_weekday::operator-=(
const months& m) NOEXCEPT
2977year_month_weekday::operator+=(
const years& y) NOEXCEPT
2986year_month_weekday::operator-=(
const years& y) NOEXCEPT
2992CONSTCD11
inline year year_month_weekday::year() const NOEXCEPT {
return y_;}
2993CONSTCD11
inline month year_month_weekday::month() const NOEXCEPT {
return m_;}
2998year_month_weekday::weekday() const NOEXCEPT
3000 return wdi_.weekday();
3006year_month_weekday::index() const NOEXCEPT
3008 return wdi_.index();
3014year_month_weekday::weekday_indexed() const NOEXCEPT
3021year_month_weekday::operator sys_days() const NOEXCEPT
3023 return sys_days{to_days()};
3028year_month_weekday::operator local_days() const NOEXCEPT
3030 return local_days{to_days()};
3036year_month_weekday::ok() const NOEXCEPT
3038 if (!y_.ok() || !m_.ok() || !wdi_.weekday().ok() || wdi_.index() < 1)
3040 if (wdi_.index() <= 4)
3042 auto d2 = wdi_.weekday() -
date::weekday(
static_cast<sys_days
>(y_/m_/1)) +
3043 days((wdi_.index()-1)*7 + 1);
3044 return static_cast<unsigned>(d2.count()) <=
static_cast<unsigned>((y_/m_/last).day());
3050year_month_weekday::from_days(days d) NOEXCEPT
3054 auto const ymd = year_month_day(dp);
3055 return {ymd.year(), ymd.month(), wd[(
static_cast<unsigned>(ymd.day())-1)/7+1]};
3061year_month_weekday::to_days() const NOEXCEPT
3063 auto d = sys_days(y_/m_/1);
3064 return (d + (wdi_.weekday() -
date::weekday(d) + days{(wdi_.index()-1)*7})
3065 ).time_since_epoch();
3071operator==(
const year_month_weekday& x,
const year_month_weekday& y) NOEXCEPT
3073 return x.year() == y.year() && x.month() == y.month() &&
3074 x.weekday_indexed() == y.weekday_indexed();
3080operator!=(
const year_month_weekday& x,
const year_month_weekday& y) NOEXCEPT
3085template<
class CharT,
class Traits>
3087std::basic_ostream<CharT, Traits>&
3088operator<<(std::basic_ostream<CharT, Traits>& os,
const year_month_weekday& ymwdi)
3090 return os << ymwdi.year() <<
'/' << ymwdi.month()
3091 <<
'/' << ymwdi.weekday_indexed();
3098operator+(
const year_month_weekday& ymwd,
const months& dm) NOEXCEPT
3100 return (ymwd.year() / ymwd.month() + dm) / ymwd.weekday_indexed();
3107operator+(
const months& dm,
const year_month_weekday& ymwd) NOEXCEPT
3116operator-(
const year_month_weekday& ymwd,
const months& dm) NOEXCEPT
3118 return ymwd + (-dm);
3124operator+(
const year_month_weekday& ymwd,
const years& dy) NOEXCEPT
3126 return {ymwd.year()+dy, ymwd.month(), ymwd.weekday_indexed()};
3132operator+(
const years& dy,
const year_month_weekday& ymwd) NOEXCEPT
3140operator-(
const year_month_weekday& ymwd,
const years& dy) NOEXCEPT
3142 return ymwd + (-dy);
3149year_month_weekday_last::year_month_weekday_last(
const date::year& y,
3160year_month_weekday_last&
3161year_month_weekday_last::operator+=(
const months& m) NOEXCEPT
3170year_month_weekday_last&
3171year_month_weekday_last::operator-=(
const months& m) NOEXCEPT
3179year_month_weekday_last&
3180year_month_weekday_last::operator+=(
const years& y) NOEXCEPT
3188year_month_weekday_last&
3189year_month_weekday_last::operator-=(
const years& y) NOEXCEPT
3195CONSTCD11
inline year year_month_weekday_last::year() const NOEXCEPT {
return y_;}
3196CONSTCD11
inline month year_month_weekday_last::month() const NOEXCEPT {
return m_;}
3201year_month_weekday_last::weekday() const NOEXCEPT
3203 return wdl_.weekday();
3209year_month_weekday_last::weekday_last() const NOEXCEPT
3216year_month_weekday_last::operator sys_days() const NOEXCEPT
3218 return sys_days{to_days()};
3223year_month_weekday_last::operator local_days() const NOEXCEPT
3225 return local_days{to_days()};
3231year_month_weekday_last::ok() const NOEXCEPT
3233 return y_.ok() && m_.ok() && wdl_.ok();
3239year_month_weekday_last::to_days() const NOEXCEPT
3241 auto const d = sys_days(y_/m_/last);
3242 return (d - (
date::weekday{d} - wdl_.weekday())).time_since_epoch();
3248operator==(
const year_month_weekday_last& x,
const year_month_weekday_last& y) NOEXCEPT
3250 return x.year() == y.year() && x.month() == y.month() &&
3251 x.weekday_last() == y.weekday_last();
3257operator!=(
const year_month_weekday_last& x,
const year_month_weekday_last& y) NOEXCEPT
3262template<
class CharT,
class Traits>
3264std::basic_ostream<CharT, Traits>&
3265operator<<(std::basic_ostream<CharT, Traits>& os,
const year_month_weekday_last& ymwdl)
3267 return os << ymwdl.year() <<
'/' << ymwdl.month() <<
'/' << ymwdl.weekday_last();
3273year_month_weekday_last
3274operator+(
const year_month_weekday_last& ymwdl,
const months& dm) NOEXCEPT
3276 return (ymwdl.year() / ymwdl.month() + dm) / ymwdl.weekday_last();
3282year_month_weekday_last
3283operator+(
const months& dm,
const year_month_weekday_last& ymwdl) NOEXCEPT
3291year_month_weekday_last
3292operator-(
const year_month_weekday_last& ymwdl,
const months& dm) NOEXCEPT
3294 return ymwdl + (-dm);
3299year_month_weekday_last
3300operator+(
const year_month_weekday_last& ymwdl,
const years& dy) NOEXCEPT
3302 return {ymwdl.year()+dy, ymwdl.month(), ymwdl.weekday_last()};
3307year_month_weekday_last
3308operator+(
const years& dy,
const year_month_weekday_last& ymwdl) NOEXCEPT
3315year_month_weekday_last
3316operator-(
const year_month_weekday_last& ymwdl,
const years& dy) NOEXCEPT
3318 return ymwdl + (-dy);
3326operator/(
const year& y,
const month& m) NOEXCEPT
3334operator/(
const year& y,
int m) NOEXCEPT
3336 return y / month(
static_cast<unsigned>(m));
3344operator/(
const month& m,
const day& d) NOEXCEPT
3352operator/(
const day& d,
const month& m) NOEXCEPT
3360operator/(
const month& m,
int d) NOEXCEPT
3362 return m / day(
static_cast<unsigned>(d));
3368operator/(
int m,
const day& d) NOEXCEPT
3370 return month(
static_cast<unsigned>(m)) / d;
3373CONSTCD11
inline month_day operator/(
const day& d,
int m) NOEXCEPT {
return m / d;}
3380operator/(
const month& m, last_spec) NOEXCEPT
3382 return month_day_last{m};
3388operator/(last_spec,
const month& m) NOEXCEPT
3396operator/(
int m, last_spec) NOEXCEPT
3398 return month(
static_cast<unsigned>(m))/last;
3404operator/(last_spec,
int m) NOEXCEPT
3414operator/(
const month& m,
const weekday_indexed& wdi) NOEXCEPT
3422operator/(
const weekday_indexed& wdi,
const month& m) NOEXCEPT
3430operator/(
int m,
const weekday_indexed& wdi) NOEXCEPT
3432 return month(
static_cast<unsigned>(m)) / wdi;
3438operator/(
const weekday_indexed& wdi,
int m) NOEXCEPT
3448operator/(
const month& m,
const weekday_last& wdl) NOEXCEPT
3456operator/(
const weekday_last& wdl,
const month& m) NOEXCEPT
3464operator/(
int m,
const weekday_last& wdl) NOEXCEPT
3466 return month(
static_cast<unsigned>(m)) / wdl;
3472operator/(
const weekday_last& wdl,
int m) NOEXCEPT
3482operator/(
const year_month& ym,
const day& d) NOEXCEPT
3484 return {ym.year(), ym.month(), d};
3490operator/(
const year_month& ym,
int d) NOEXCEPT
3492 return ym / day(
static_cast<unsigned>(d));
3498operator/(
const year& y,
const month_day& md) NOEXCEPT
3500 return y / md.month() / md.day();
3506operator/(
int y,
const month_day& md) NOEXCEPT
3508 return year(y) / md;
3514operator/(
const month_day& md,
const year& y) NOEXCEPT
3522operator/(
const month_day& md,
int y) NOEXCEPT
3524 return year(y) / md;
3532operator/(
const year_month& ym, last_spec) NOEXCEPT
3534 return {ym.year(), month_day_last{ym.month()}};
3540operator/(
const year& y,
const month_day_last& mdl) NOEXCEPT
3548operator/(
int y,
const month_day_last& mdl) NOEXCEPT
3550 return year(y) / mdl;
3556operator/(
const month_day_last& mdl,
const year& y) NOEXCEPT
3564operator/(
const month_day_last& mdl,
int y) NOEXCEPT
3566 return year(y) / mdl;
3574operator/(
const year_month& ym,
const weekday_indexed& wdi) NOEXCEPT
3576 return {ym.year(), ym.month(), wdi};
3582operator/(
const year& y,
const month_weekday& mwd) NOEXCEPT
3584 return {y, mwd.month(), mwd.weekday_indexed()};
3590operator/(
int y,
const month_weekday& mwd) NOEXCEPT
3592 return year(y) / mwd;
3598operator/(
const month_weekday& mwd,
const year& y) NOEXCEPT
3606operator/(
const month_weekday& mwd,
int y) NOEXCEPT
3608 return year(y) / mwd;
3615year_month_weekday_last
3616operator/(
const year_month& ym,
const weekday_last& wdl) NOEXCEPT
3618 return {ym.year(), ym.month(), wdl};
3623year_month_weekday_last
3624operator/(
const year& y,
const month_weekday_last& mwdl) NOEXCEPT
3626 return {y, mwdl.month(), mwdl.weekday_last()};
3631year_month_weekday_last
3632operator/(
int y,
const month_weekday_last& mwdl) NOEXCEPT
3634 return year(y) / mwdl;
3639year_month_weekday_last
3640operator/(
const month_weekday_last& mwdl,
const year& y) NOEXCEPT
3647year_month_weekday_last
3648operator/(
const month_weekday_last& mwdl,
int y) NOEXCEPT
3650 return year(y) / mwdl;
3653template <
class Duration>
3656template <
class CharT,
class Traits,
class Duration>
3657std::basic_ostream<CharT, Traits>&
3658to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
3659 const fields<Duration>& fds,
const std::string* abbrev =
nullptr,
3660 const std::chrono::seconds* offset_sec =
nullptr);
3662template <
class CharT,
class Traits,
class Duration,
class Alloc>
3663std::basic_istream<CharT, Traits>&
3664from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt,
3665 fields<Duration>& fds, std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
3666 std::chrono::minutes* offset =
nullptr);
3684template <std::uint64_t n, std::uint64_t d = 10,
unsigned w = 0,
3685 bool should_continue = !(n < 2) && d != 0 && (w < 19)>
3691template <std::u
int64_t n, std::u
int64_t d,
unsigned w>
3694 static CONSTDATA
unsigned value = 0;
3697template <
unsigned exp>
3701 static CONSTDATA std::uint64_t h =
static_pow10<exp/2>::value;
3703 static CONSTDATA std::uint64_t value = h * h * (exp % 2 ? 10 : 1);
3709 static CONSTDATA std::uint64_t value = 1;
3712template <
class Duration>
3715 using CT =
typename std::common_type<Duration, std::chrono::seconds>::type;
3716 using rep =
typename CT::rep;
3720 using precision = std::chrono::duration<rep,
3721 std::ratio<1, static_pow10<width>::value>>;
3724 std::chrono::seconds s_;
3734 : s_(std::chrono::duration_cast<std::chrono::seconds>(d))
3735 , sub_s_(std::chrono::duration_cast<precision>(d - s_))
3738 CONSTCD14 std::chrono::seconds& seconds() NOEXCEPT {
return s_;}
3739 CONSTCD11 std::chrono::seconds seconds()
const NOEXCEPT {
return s_;}
3740 CONSTCD11 precision subseconds()
const NOEXCEPT {
return sub_s_;}
3742 CONSTCD14 precision to_duration()
const NOEXCEPT
3747 CONSTCD11
bool in_conventional_range()
const NOEXCEPT
3749 return sub_s_ < std::chrono::seconds{1} && s_ < std::chrono::minutes{1};
3752 template <
class CharT,
class Traits>
3754 std::basic_ostream<CharT, Traits>&
3757 return x.print(os, std::chrono::treat_as_floating_point<rep>{});
3760 template <
class CharT,
class Traits>
3761 std::basic_ostream<CharT, Traits>&
3762 print(std::basic_ostream<CharT, Traits>& os, std::true_type)
const
3765 std::chrono::duration<rep> d = s_ + sub_s_;
3766 if (d < std::chrono::seconds{10})
3768 os << std::fixed << d.count();
3772 template <
class CharT,
class Traits>
3773 std::basic_ostream<CharT, Traits>&
3774 print(std::basic_ostream<CharT, Traits>& os, std::false_type)
const
3778 os.flags(std::ios::dec | std::ios::right);
3784 os << std::use_facet<std::numpunct<CharT>>(os.getloc()).decimal_point();
3789 os.imbue(std::locale::classic());
3791 os << sub_s_.count();
3797template <
class Rep,
class Period>
3800typename std::enable_if
3802 std::numeric_limits<Rep>::is_signed,
3803 std::chrono::duration<Rep, Period>
3805abs(std::chrono::duration<Rep, Period> d)
3807 return d >= d.zero() ? +d : -d;
3810template <
class Rep,
class Period>
3813typename std::enable_if
3815 !std::numeric_limits<Rep>::is_signed,
3816 std::chrono::duration<Rep, Period>
3818abs(std::chrono::duration<Rep, Period> d)
3825template <
class Duration>
3829 std::chrono::seconds>::type>;
3831 std::chrono::hours h_;
3832 std::chrono::minutes m_;
3837 static unsigned CONSTDATA fractional_width = dfs::width;
3838 using precision =
typename dfs::precision;
3844 CONSTCD11
explicit hh_mm_ss(Duration d) NOEXCEPT
3845 : h_(std::chrono::duration_cast<std::chrono::hours>(detail::abs(d)))
3846 , m_(std::chrono::duration_cast<std::chrono::minutes>(detail::abs(d)) - h_)
3847 , s_(detail::abs(d) - h_ - m_)
3848 , neg_(d < Duration::zero())
3851 CONSTCD11 std::chrono::hours hours()
const NOEXCEPT {
return h_;}
3852 CONSTCD11 std::chrono::minutes minutes()
const NOEXCEPT {
return m_;}
3853 CONSTCD11 std::chrono::seconds seconds()
const NOEXCEPT {
return s_.seconds();}
3854 CONSTCD14 std::chrono::seconds&
3856 CONSTCD11 precision subseconds()
const NOEXCEPT {
return s_.subseconds();}
3857 CONSTCD11
bool is_negative()
const NOEXCEPT {
return neg_;}
3859 CONSTCD11
explicit operator precision()
const NOEXCEPT {
return to_duration();}
3860 CONSTCD11 precision to_duration()
const NOEXCEPT
3861 {
return (s_.to_duration() + m_ + h_) * (1-2*neg_);}
3863 CONSTCD11
bool in_conventional_range()
const NOEXCEPT
3865 return !neg_ && h_ < days{1} && m_ < std::chrono::hours{1} &&
3866 s_.in_conventional_range();
3871 template <
class charT,
class traits>
3873 std::basic_ostream<charT, traits>&
3874 operator<<(std::basic_ostream<charT, traits>& os,
hh_mm_ss const& tod)
3876 if (tod.is_negative())
3878 if (tod.h_ < std::chrono::hours{10})
3880 os << tod.h_.count() <<
':';
3881 if (tod.m_ < std::chrono::minutes{10})
3883 os << tod.m_.count() <<
':' << tod.s_;
3887 template <
class CharT,
class Traits,
class Duration2>
3889 std::basic_ostream<CharT, Traits>&
3890 date::to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
3892 const std::chrono::seconds* offset_sec);
3894 template <
class CharT,
class Traits,
class Duration2,
class Alloc>
3896 std::basic_istream<CharT, Traits>&
3897 date::from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt,
3899 std::basic_string<CharT, Traits, Alloc>* abbrev, std::chrono::minutes* offset);
3905is_am(std::chrono::hours
const& h) NOEXCEPT
3907 using std::chrono::hours;
3908 return hours{0} <= h && h < hours{12};
3914is_pm(std::chrono::hours
const& h) NOEXCEPT
3916 using std::chrono::hours;
3917 return hours{12} <= h && h < hours{24};
3923make12(std::chrono::hours h) NOEXCEPT
3925 using std::chrono::hours;
3942make24(std::chrono::hours h,
bool is_pm) NOEXCEPT
3944 using std::chrono::hours;
3950 else if (h == hours{12})
3955template <
class Duration>
3956using time_of_day = hh_mm_ss<Duration>;
3958template <
class Rep,
class Period,
3959 class =
typename std::enable_if
3960 <!std::chrono::treat_as_floating_point<Rep>::value>::type>
3963hh_mm_ss<std::chrono::duration<Rep, Period>>
3964make_time(
const std::chrono::duration<Rep, Period>& d)
3966 return hh_mm_ss<std::chrono::duration<Rep, Period>>(d);
3969template <
class CharT,
class Traits,
class Duration>
3971typename std::enable_if
3973 !std::chrono::treat_as_floating_point<typename Duration::rep>::value &&
3974 std::ratio_less<typename Duration::period, days::period>::value
3975 , std::basic_ostream<CharT, Traits>&
3977operator<<(std::basic_ostream<CharT, Traits>& os,
const sys_time<Duration>& tp)
3979 auto const dp = date::floor<days>(tp);
3980 return os << year_month_day(dp) <<
' ' << make_time(tp-dp);
3983template <
class CharT,
class Traits>
3985std::basic_ostream<CharT, Traits>&
3986operator<<(std::basic_ostream<CharT, Traits>& os,
const sys_days& dp)
3988 return os << year_month_day(dp);
3991template <
class CharT,
class Traits,
class Duration>
3993std::basic_ostream<CharT, Traits>&
3994operator<<(std::basic_ostream<CharT, Traits>& os,
const local_time<Duration>& ut)
3996 return (os << sys_time<Duration>{ut.time_since_epoch()});
4002template <
class CharT, std::
size_t N>
4005template <
class CharT1,
class CharT2, std::
size_t N1, std::
size_t N2>
4008string_literal<
typename std::conditional<
sizeof(CharT2) <=
sizeof(CharT1), CharT1, CharT2>::type,
4012template <
class CharT, std::
size_t N>
4022 using const_iterator =
const CharT*;
4024 string_literal(string_literal
const&) =
default;
4025 string_literal& operator=(string_literal
const&) =
delete;
4027 template <std::size_t N1 = 2,
4028 class =
typename std::enable_if<N1 == N>::type>
4029 CONSTCD11 string_literal(CharT c) NOEXCEPT
4034 template <std::size_t N1 = 3,
4035 class =
typename std::enable_if<N1 == N>::type>
4036 CONSTCD11 string_literal(CharT c1, CharT c2) NOEXCEPT
4041 template <std::size_t N1 = 4,
4042 class =
typename std::enable_if<N1 == N>::type>
4043 CONSTCD11 string_literal(CharT c1, CharT c2, CharT c3) NOEXCEPT
4048 CONSTCD14 string_literal(
const CharT(&a)[N]) NOEXCEPT
4051 for (std::size_t i = 0; i < N; ++i)
4055 template <
class U = CharT,
4056 class =
typename std::enable_if<(1 <
sizeof(U))>::type>
4057 CONSTCD14 string_literal(
const char(&a)[N]) NOEXCEPT
4060 for (std::size_t i = 0; i < N; ++i)
4064 template <
class CharT2,
4065 class =
typename std::enable_if<!std::is_same<CharT2, CharT>::value>::type>
4066 CONSTCD14 string_literal(string_literal<CharT2, N>
const& a) NOEXCEPT
4069 for (std::size_t i = 0; i < N; ++i)
4073 CONSTCD11
const CharT* data() const NOEXCEPT {
return p_;}
4074 CONSTCD11 std::size_t size() const NOEXCEPT {
return N-1;}
4076 CONSTCD11 const_iterator begin() const NOEXCEPT {
return p_;}
4077 CONSTCD11 const_iterator end() const NOEXCEPT {
return p_ + N-1;}
4079 CONSTCD11 CharT
const& operator[](std::size_t n)
const NOEXCEPT
4084 template <
class Traits>
4086 std::basic_ostream<CharT, Traits>&
4087 operator<<(std::basic_ostream<CharT, Traits>& os,
const string_literal& s)
4092 template <
class CharT1,
class CharT2, std::
size_t N1, std::
size_t N2>
4095 string_literal<
typename std::conditional<
sizeof(CharT2) <=
sizeof(CharT1), CharT1, CharT2>::type,
4097 operator+(
const string_literal<CharT1, N1>& x,
const string_literal<CharT2, N2>& y) NOEXCEPT;
4100template <
class CharT>
4103string_literal<CharT, 3>
4104operator+(
const string_literal<CharT, 2>& x,
const string_literal<CharT, 2>& y) NOEXCEPT
4106 return string_literal<CharT, 3>(x[0], y[0]);
4109template <
class CharT>
4112string_literal<CharT, 4>
4113operator+(
const string_literal<CharT, 3>& x,
const string_literal<CharT, 2>& y) NOEXCEPT
4115 return string_literal<CharT, 4>(x[0], x[1], y[0]);
4118template <
class CharT1,
class CharT2, std::
size_t N1, std::
size_t N2>
4121string_literal<
typename std::conditional<
sizeof(CharT2) <=
sizeof(CharT1), CharT1, CharT2>::type,
4123operator+(
const string_literal<CharT1, N1>& x,
const string_literal<CharT2, N2>& y) NOEXCEPT
4125 using CT =
typename std::conditional<
sizeof(CharT2) <=
sizeof(CharT1), CharT1, CharT2>::type;
4127 string_literal<CT, N1 + N2 - 1> r;
4129 for (; i < N1-1; ++i)
4130 r.p_[i] = CT(x.p_[i]);
4131 for (std::size_t j = 0; j < N2; ++j, ++i)
4132 r.p_[i] = CT(y.p_[j]);
4138template <
class CharT,
class Traits,
class Alloc, std::
size_t N>
4140std::basic_string<CharT, Traits, Alloc>
4141operator+(std::basic_string<CharT, Traits, Alloc> x,
const string_literal<CharT, N>& y)
4143 x.append(y.data(), y.size());
4147#if __cplusplus >= 201402 && (!defined(__EDG_VERSION__) || __EDG_VERSION__ > 411) \
4148 && (!defined(__SUNPRO_CC) || __SUNPRO_CC > 0x5150)
4150template <
class CharT,
4151 class = std::enable_if_t<std::is_same<CharT, char>::value ||
4152 std::is_same<CharT, wchar_t>::value ||
4153 std::is_same<CharT, char16_t>::value ||
4154 std::is_same<CharT, char32_t>::value>>
4157string_literal<CharT, 2>
4158msl(CharT c) NOEXCEPT
4160 return string_literal<CharT, 2>{c};
4166to_string_len(std::intmax_t i)
4177template <std::
intmax_t N>
4183 string_literal<char, to_string_len(N)+1>
4187 return msl(
char(N % 10 +
'0'));
4190template <std::
intmax_t N>
4196 string_literal<char, to_string_len(N)+1>
4200 return msl<N/10>() + msl(
char(N % 10 +
'0'));
4203template <
class CharT, std::
intmax_t N, std::
intmax_t D>
4208 std::ratio<N, D>::type::den != 1,
4209 string_literal<CharT, to_string_len(std::ratio<N, D>::type::num) +
4210 to_string_len(std::ratio<N, D>::type::den) + 4>
4212msl(std::ratio<N, D>) NOEXCEPT
4214 using R =
typename std::ratio<N, D>::type;
4215 return msl(CharT{
'['}) + msl<R::num>() + msl(CharT{
'/'}) +
4216 msl<R::den>() + msl(CharT{
']'});
4219template <
class CharT, std::
intmax_t N, std::
intmax_t D>
4224 std::ratio<N, D>::type::den == 1,
4225 string_literal<CharT, to_string_len(std::ratio<N, D>::type::num) + 3>
4227msl(std::ratio<N, D>) NOEXCEPT
4229 using R =
typename std::ratio<N, D>::type;
4230 return msl(CharT{
'['}) + msl<R::num>() + msl(CharT{
']'});
4238to_string(std::uint64_t x)
4240 return std::to_string(x);
4243template <
class CharT>
4245std::basic_string<CharT>
4246to_string(std::uint64_t x)
4248 auto y = std::to_string(x);
4249 return std::basic_string<CharT>(y.begin(), y.end());
4252template <
class CharT, std::
intmax_t N, std::
intmax_t D>
4254typename std::enable_if
4256 std::ratio<N, D>::type::den != 1,
4257 std::basic_string<CharT>
4259msl(std::ratio<N, D>)
4261 using R =
typename std::ratio<N, D>::type;
4262 return std::basic_string<CharT>(1,
'[') + to_string<CharT>(R::num) + CharT{
'/'} +
4263 to_string<CharT>(R::den) + CharT{
']'};
4266template <
class CharT, std::
intmax_t N, std::
intmax_t D>
4268typename std::enable_if
4270 std::ratio<N, D>::type::den == 1,
4271 std::basic_string<CharT>
4273msl(std::ratio<N, D>)
4275 using R =
typename std::ratio<N, D>::type;
4276 return std::basic_string<CharT>(1,
'[') + to_string<CharT>(R::num) + CharT{
']'};
4281template <
class CharT>
4284string_literal<CharT, 2>
4285msl(std::atto) NOEXCEPT
4287 return string_literal<CharT, 2>{
'a'};
4290template <
class CharT>
4293string_literal<CharT, 2>
4294msl(std::femto) NOEXCEPT
4296 return string_literal<CharT, 2>{
'f'};
4299template <
class CharT>
4302string_literal<CharT, 2>
4303msl(std::pico) NOEXCEPT
4305 return string_literal<CharT, 2>{
'p'};
4308template <
class CharT>
4311string_literal<CharT, 2>
4312msl(std::nano) NOEXCEPT
4314 return string_literal<CharT, 2>{
'n'};
4317template <
class CharT>
4320typename std::enable_if
4322 std::is_same<CharT, char>::value,
4323 string_literal<char, 3>
4325msl(std::micro) NOEXCEPT
4327 return string_literal<char, 3>{
'\xC2',
'\xB5'};
4330template <
class CharT>
4333typename std::enable_if
4335 !std::is_same<CharT, char>::value,
4336 string_literal<CharT, 2>
4338msl(std::micro) NOEXCEPT
4340 return string_literal<CharT, 2>{CharT{
static_cast<unsigned char>(
'\xB5')}};
4343template <
class CharT>
4346string_literal<CharT, 2>
4347msl(std::milli) NOEXCEPT
4349 return string_literal<CharT, 2>{
'm'};
4352template <
class CharT>
4355string_literal<CharT, 2>
4356msl(std::centi) NOEXCEPT
4358 return string_literal<CharT, 2>{
'c'};
4361template <
class CharT>
4364string_literal<CharT, 3>
4365msl(std::deca) NOEXCEPT
4367 return string_literal<CharT, 3>{
'd',
'a'};
4370template <
class CharT>
4373string_literal<CharT, 2>
4374msl(std::deci) NOEXCEPT
4376 return string_literal<CharT, 2>{
'd'};
4379template <
class CharT>
4382string_literal<CharT, 2>
4383msl(std::hecto) NOEXCEPT
4385 return string_literal<CharT, 2>{
'h'};
4388template <
class CharT>
4391string_literal<CharT, 2>
4392msl(std::kilo) NOEXCEPT
4394 return string_literal<CharT, 2>{
'k'};
4397template <
class CharT>
4400string_literal<CharT, 2>
4401msl(std::mega) NOEXCEPT
4403 return string_literal<CharT, 2>{
'M'};
4406template <
class CharT>
4409string_literal<CharT, 2>
4410msl(std::giga) NOEXCEPT
4412 return string_literal<CharT, 2>{
'G'};
4415template <
class CharT>
4418string_literal<CharT, 2>
4419msl(std::tera) NOEXCEPT
4421 return string_literal<CharT, 2>{
'T'};
4424template <
class CharT>
4427string_literal<CharT, 2>
4428msl(std::peta) NOEXCEPT
4430 return string_literal<CharT, 2>{
'P'};
4433template <
class CharT>
4436string_literal<CharT, 2>
4437msl(std::exa) NOEXCEPT
4439 return string_literal<CharT, 2>{
'E'};
4442template <
class CharT,
class Period>
4447 ->
decltype(msl<CharT>(p) + string_literal<CharT, 2>{
's'})
4449 return msl<CharT>(p) + string_literal<CharT, 2>{
's'};
4452template <
class CharT>
4455string_literal<CharT, 2>
4456get_units(std::ratio<1>)
4458 return string_literal<CharT, 2>{
's'};
4461template <
class CharT>
4464string_literal<CharT, 2>
4465get_units(std::ratio<3600>)
4467 return string_literal<CharT, 2>{
'h'};
4470template <
class CharT>
4473string_literal<CharT, 4>
4474get_units(std::ratio<60>)
4476 return string_literal<CharT, 4>{
'm',
'i',
'n'};
4479template <
class CharT>
4482string_literal<CharT, 2>
4483get_units(std::ratio<86400>)
4485 return string_literal<CharT, 2>{
'd'};
4488template <
class CharT,
class Traits = std::
char_traits<CharT>>
4492struct make_string<char>
4494 template <
class Rep>
4499 return std::to_string(n);
4503template <
class Traits>
4504struct make_string<char, Traits>
4506 template <
class Rep>
4508 std::basic_string<char, Traits>
4511 auto s = std::to_string(n);
4512 return std::basic_string<char, Traits>(s.begin(), s.end());
4517struct make_string<wchar_t>
4519 template <
class Rep>
4524 return std::to_wstring(n);
4528template <
class Traits>
4529struct make_string<wchar_t, Traits>
4531 template <
class Rep>
4533 std::basic_string<wchar_t, Traits>
4536 auto s = std::to_wstring(n);
4537 return std::basic_string<wchar_t, Traits>(s.begin(), s.end());
4545CONSTDATA year nanyear{-32768};
4547template <
class Duration>
4553 bool has_tod =
false;
4578template <
class CharT,
class Traits,
class Duration>
4580extract_weekday(std::basic_ostream<CharT, Traits>& os,
const fields<Duration>& fds)
4582 if (!fds.ymd.ok() && !fds.wd.ok())
4585 os.setstate(std::ios::failbit);
4591 wd = weekday{sys_days(fds.ymd)};
4592 if (fds.wd.ok() && wd != fds.wd)
4595 os.setstate(std::ios::failbit);
4601 return static_cast<unsigned>((wd - Sunday).count());
4604template <
class CharT,
class Traits,
class Duration>
4606extract_month(std::basic_ostream<CharT, Traits>& os,
const fields<Duration>& fds)
4608 if (!fds.ymd.month().ok())
4611 os.setstate(std::ios::failbit);
4614 return static_cast<unsigned>(fds.ymd.month());
4625std::pair<const std::string*, const std::string*>
4628 static const std::string nm[] =
4645 return std::make_pair(nm, nm+
sizeof(nm)/
sizeof(nm[0]));
4649std::pair<const std::string*, const std::string*>
4652 static const std::string nm[] =
4679 return std::make_pair(nm, nm+
sizeof(nm)/
sizeof(nm[0]));
4683std::pair<const std::string*, const std::string*>
4686 static const std::string nm[] =
4691 return std::make_pair(nm, nm+
sizeof(nm)/
sizeof(nm[0]));
4694template <
class CharT,
class Traits,
class FwdIter>
4696scan_keyword(std::basic_istream<CharT, Traits>& is, FwdIter kb, FwdIter ke)
4698 size_t nkw =
static_cast<size_t>(std::distance(kb, ke));
4699 const unsigned char doesnt_match =
'\0';
4700 const unsigned char might_match =
'\1';
4701 const unsigned char does_match =
'\2';
4702 unsigned char statbuf[100];
4703 unsigned char* status = statbuf;
4704 std::unique_ptr<
unsigned char, void(*)(
void*)> stat_hold(0, free);
4705 if (nkw >
sizeof(statbuf))
4707 status = (
unsigned char*)std::malloc(nkw);
4708 if (status ==
nullptr)
4709 throw std::bad_alloc();
4710 stat_hold.reset(status);
4712 size_t n_might_match = nkw;
4713 size_t n_does_match = 0;
4715 unsigned char* st = status;
4716 for (
auto ky = kb; ky != ke; ++ky, ++st)
4728 for (
size_t indx = 0; is && n_might_match > 0; ++indx)
4731 auto ic = is.peek();
4734 is.setstate(std::ios::eofbit);
4737 auto c =
static_cast<char>(toupper(ic));
4738 bool consume =
false;
4746 for (
auto ky = kb; ky != ke; ++ky, ++st)
4748 if (*st == might_match)
4750 if (c ==
static_cast<char>(toupper((*ky)[indx])))
4753 if (ky->size() == indx+1)
4774 if (n_might_match + n_does_match > 1)
4777 for (
auto ky = kb; ky != ke; ++ky, ++st)
4779 if (*st == does_match && ky->size() != indx+1)
4790 for (st = status; kb != ke; ++kb, ++st)
4791 if (*st == does_match)
4794 is.setstate(std::ios::failbit);
4802template <
class CharT,
class Traits,
class Duration>
4803std::basic_ostream<CharT, Traits>&
4804to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
4805 const fields<Duration>& fds,
const std::string* abbrev,
4806 const std::chrono::seconds* offset_sec)
4809 using detail::weekday_names;
4810 using detail::month_names;
4811 using detail::ampm_names;
4813 using detail::save_ostream;
4814 using detail::get_units;
4815 using detail::extract_weekday;
4816 using detail::extract_month;
4818 using std::chrono::duration_cast;
4819 using std::chrono::seconds;
4820 using std::chrono::minutes;
4821 using std::chrono::hours;
4824 os.flags(std::ios::skipws | std::ios::dec);
4827 bool insert_negative = fds.has_tod && fds.tod.to_duration() < Duration::zero();
4829 auto& facet = std::use_facet<std::time_put<CharT>>(os.getloc());
4831 const CharT* command =
nullptr;
4832 CharT modified = CharT{};
4841 if (modified == CharT{})
4843 tm.tm_wday =
static_cast<int>(extract_weekday(os, fds));
4847 const CharT f[] = {
'%', *fmt};
4848 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
4850 os << weekday_names().first[tm.tm_wday+7*(*fmt ==
'a')];
4855 os << CharT{
'%'} << modified << *fmt;
4868 if (modified == CharT{})
4870 tm.tm_mon =
static_cast<int>(extract_month(os, fds)) - 1;
4872 const CharT f[] = {
'%', *fmt};
4873 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
4875 os << month_names().first[tm.tm_mon+12*(*fmt !=
'B')];
4880 os << CharT{
'%'} << modified << *fmt;
4892 if (modified == CharT{
'O'})
4893 os << CharT{
'%'} << modified << *fmt;
4897 os.setstate(std::ios::failbit);
4898 if (*fmt ==
'c' && !fds.has_tod)
4899 os.setstate(std::ios::failbit);
4902 auto const& ymd = fds.ymd;
4903 auto ld = local_days(ymd);
4906 tm.tm_sec =
static_cast<int>(fds.tod.seconds().count());
4907 tm.tm_min =
static_cast<int>(fds.tod.minutes().count());
4908 tm.tm_hour =
static_cast<int>(fds.tod.hours().count());
4910 tm.tm_mday =
static_cast<int>(
static_cast<unsigned>(ymd.day()));
4911 tm.tm_mon =
static_cast<int>(extract_month(os, fds) - 1);
4912 tm.tm_year =
static_cast<int>(ymd.year()) - 1900;
4913 tm.tm_wday =
static_cast<int>(extract_weekday(os, fds));
4916 tm.tm_yday =
static_cast<int>((ld - local_days(ymd.year()/1/1)).count());
4918 auto fe = std::begin(f) + 1;
4919 if (modified == CharT{
'E'})
4922 facet.put(os, os, os.fill(), &tm, std::begin(f), fe);
4926 auto wd =
static_cast<int>(extract_weekday(os, fds));
4927 os << weekday_names().first[
static_cast<unsigned>(wd)+7]
4929 os << month_names().first[extract_month(os, fds)-1+12] <<
' ';
4930 auto d =
static_cast<int>(
static_cast<unsigned>(fds.ymd.day()));
4934 << make_time(duration_cast<seconds>(fds.tod.to_duration()))
4935 <<
' ' << fds.ymd.year();
4940 auto const& ymd = fds.ymd;
4941 save_ostream<CharT, Traits> _(os);
4943 os.flags(std::ios::dec | std::ios::right);
4945 os << static_cast<unsigned>(ymd.month()) << CharT{
'/'};
4947 os << static_cast<unsigned>(ymd.day()) << CharT{
'/'};
4949 os << static_cast<int>(ymd.year()) % 100;
4962 if (modified == CharT{
'O'})
4963 os << CharT{
'%'} << modified << *fmt;
4966 if (!fds.ymd.year().ok())
4967 os.setstate(std::ios::failbit);
4968 auto y =
static_cast<int>(fds.ymd.year());
4970 if (modified == CharT{})
4973 save_ostream<CharT, Traits> _(os);
4975 os.flags(std::ios::dec | std::ios::right);
4989 else if (modified == CharT{
'E'})
4991 tm.tm_year = y - 1900;
4992 CharT f[3] = {
'%',
'E',
'C'};
4993 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5007 if (modified == CharT{
'E'})
5008 os << CharT{
'%'} << modified << *fmt;
5011 if (!fds.ymd.day().ok())
5012 os.setstate(std::ios::failbit);
5013 auto d =
static_cast<int>(
static_cast<unsigned>(fds.ymd.day()));
5015 if (modified == CharT{})
5018 save_ostream<CharT, Traits> _(os);
5019 if (*fmt == CharT{
'd'})
5023 os.flags(std::ios::dec | std::ios::right);
5028 else if (modified == CharT{
'O'})
5031 CharT f[3] = {
'%',
'O', *fmt};
5032 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5045 if (modified == CharT{})
5048 os.setstate(std::ios::failbit);
5049 auto const& ymd = fds.ymd;
5050 save_ostream<CharT, Traits> _(os);
5052 os.flags(std::ios::dec | std::ios::right);
5054 os << static_cast<unsigned>(ymd.month()) << CharT{
'/'};
5056 os << static_cast<unsigned>(ymd.day()) << CharT{
'/'};
5058 os << static_cast<int>(ymd.year()) % 100;
5062 os << CharT{
'%'} << modified << *fmt;
5073 if (modified == CharT{})
5076 os.setstate(std::ios::failbit);
5077 auto const& ymd = fds.ymd;
5078 save_ostream<CharT, Traits> _(os);
5079 os.imbue(std::locale::classic());
5081 os.flags(std::ios::dec | std::ios::right);
5083 os << static_cast<int>(ymd.year()) << CharT{
'-'};
5085 os << static_cast<unsigned>(ymd.month()) << CharT{
'-'};
5087 os << static_cast<unsigned>(ymd.day());
5091 os << CharT{
'%'} << modified << *fmt;
5103 if (modified == CharT{})
5106 os.setstate(std::ios::failbit);
5107 auto ld = local_days(fds.ymd);
5108 auto y = year_month_day{ld + days{3}}.year();
5109 auto start = local_days((y-years{1})/December/Thursday[last]) +
5113 if (*fmt == CharT{
'G'})
5117 save_ostream<CharT, Traits> _(os);
5119 os.flags(std::ios::dec | std::ios::right);
5121 os << std::abs(static_cast<int>(y)) % 100;
5126 os << CharT{
'%'} << modified << *fmt;
5138 if (modified == CharT{
'E'})
5139 os << CharT{
'%'} << modified << *fmt;
5143 os.setstate(std::ios::failbit);
5144 if (insert_negative)
5147 insert_negative =
false;
5151 if (modified == CharT{})
5154 auto h = *fmt == CharT{
'I'} ? date::make12(hms.hours()) : hms.hours();
5160 else if (modified == CharT{
'O'})
5162 const CharT f[] = {
'%', modified, *fmt};
5163 tm.tm_hour =
static_cast<int>(hms.hours().count());
5164 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5177 if (modified == CharT{})
5179 if (fds.ymd.ok() || fds.has_tod)
5184 auto ld = local_days(fds.ymd);
5185 auto y = fds.ymd.year();
5186 doy = ld - local_days(y/January/1) + days{1};
5190 doy = duration_cast<days>(fds.tod.to_duration());
5192 save_ostream<CharT, Traits> _(os);
5194 os.flags(std::ios::dec | std::ios::right);
5200 os.setstate(std::ios::failbit);
5205 os << CharT{
'%'} << modified << *fmt;
5216 if (modified == CharT{
'E'})
5217 os << CharT{
'%'} << modified << *fmt;
5220 if (!fds.ymd.month().ok())
5221 os.setstate(std::ios::failbit);
5222 auto m =
static_cast<unsigned>(fds.ymd.month());
5224 if (modified == CharT{})
5232 else if (modified == CharT{
'O'})
5234 const CharT f[] = {
'%', modified, *fmt};
5235 tm.tm_mon =
static_cast<int>(m-1);
5236 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5249 if (modified == CharT{
'E'})
5250 os << CharT{
'%'} << modified << *fmt;
5254 os.setstate(std::ios::failbit);
5255 if (insert_negative)
5258 insert_negative =
false;
5261 if (modified == CharT{})
5264 if (fds.tod.minutes() < minutes{10})
5266 os << fds.tod.minutes().count();
5269 else if (modified == CharT{
'O'})
5271 const CharT f[] = {
'%', modified, *fmt};
5272 tm.tm_min =
static_cast<int>(fds.tod.minutes().count());
5273 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5286 if (modified == CharT{})
5290 os << CharT{
'%'} << modified << *fmt;
5301 if (modified == CharT{})
5304 os.setstate(std::ios::failbit);
5306 const CharT f[] = {
'%', *fmt};
5307 tm.tm_hour =
static_cast<int>(fds.tod.hours().count());
5308 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5310 if (date::is_am(fds.tod.hours()))
5311 os << ampm_names().first[0];
5313 os << ampm_names().first[1];
5318 os << CharT{
'%'} << modified << *fmt;
5330 if (modified == CharT{})
5333 os.setstate(std::ios::failbit);
5334 auto d = fds.tod.to_duration();
5336 os << get_units<CharT>(
typename decltype(d)::period::type{});
5342 os << CharT{
'%'} << modified << *fmt;
5353 if (modified == CharT{})
5356 os.setstate(std::ios::failbit);
5358 const CharT f[] = {
'%', *fmt};
5359 tm.tm_hour =
static_cast<int>(fds.tod.hours().count());
5360 tm.tm_min =
static_cast<int>(fds.tod.minutes().count());
5361 tm.tm_sec =
static_cast<int>(fds.tod.seconds().count());
5362 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5364 hh_mm_ss<seconds> tod(duration_cast<seconds>(fds.tod.to_duration()));
5365 save_ostream<CharT, Traits> _(os);
5368 os << date::make12(tod.hours()).count() << CharT{
':'};
5370 os << tod.minutes().count() << CharT{
':'};
5372 os << tod.seconds().count() << CharT{
' '};
5373 if (date::is_am(tod.hours()))
5374 os << ampm_names().first[0];
5376 os << ampm_names().first[1];
5381 os << CharT{
'%'} << modified << *fmt;
5392 if (modified == CharT{})
5395 os.setstate(std::ios::failbit);
5396 if (fds.tod.hours() < hours{10})
5398 os << fds.tod.hours().count() << CharT{
':'};
5399 if (fds.tod.minutes() < minutes{10})
5401 os << fds.tod.minutes().count();
5405 os << CharT{
'%'} << modified << *fmt;
5416 if (modified == CharT{
'E'})
5417 os << CharT{
'%'} << modified << *fmt;
5421 os.setstate(std::ios::failbit);
5422 if (insert_negative)
5425 insert_negative =
false;
5428 if (modified == CharT{})
5434 else if (modified == CharT{
'O'})
5436 const CharT f[] = {
'%', modified, *fmt};
5437 tm.tm_sec =
static_cast<int>(fds.tod.s_.seconds().count());
5438 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5451 if (modified == CharT{})
5455 os << CharT{
'%'} << modified << *fmt;
5466 if (modified == CharT{})
5469 os.setstate(std::ios::failbit);
5474 os << CharT{
'%'} << modified << *fmt;
5485 if (modified == CharT{
'E'})
5486 os << CharT{
'%'} << modified << *fmt;
5489 auto wd = extract_weekday(os, fds);
5491 if (modified == CharT{})
5494 os << (wd != 0 ? wd : 7u);
5497 else if (modified == CharT{
'O'})
5499 const CharT f[] = {
'%', modified, *fmt};
5500 tm.tm_wday =
static_cast<int>(wd);
5501 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5514 if (modified == CharT{
'E'})
5515 os << CharT{
'%'} << modified << *fmt;
5518 auto const& ymd = fds.ymd;
5520 os.setstate(std::ios::failbit);
5521 auto ld = local_days(ymd);
5523 if (modified == CharT{})
5526 auto st = local_days(Sunday[1]/January/ymd.year());
5528 os << CharT{
'0'} << CharT{
'0'};
5531 auto wn = duration_cast<weeks>(ld - st).count() + 1;
5538 else if (modified == CharT{
'O'})
5540 const CharT f[] = {
'%', modified, *fmt};
5541 tm.tm_year =
static_cast<int>(ymd.year()) - 1900;
5542 tm.tm_wday =
static_cast<int>(extract_weekday(os, fds));
5545 tm.tm_yday =
static_cast<int>((ld - local_days(ymd.year()/1/1)).count());
5546 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5559 if (modified == CharT{
'E'})
5560 os << CharT{
'%'} << modified << *fmt;
5564 os.setstate(std::ios::failbit);
5565 auto ld = local_days(fds.ymd);
5567 if (modified == CharT{})
5570 auto y = year_month_day{ld + days{3}}.year();
5571 auto st = local_days((y-years{1})/12/Thursday[last]) +
5576 st = local_days((y - years{1})/12/Thursday[last]) +
5579 auto wn = duration_cast<weeks>(ld - st).count() + 1;
5585 else if (modified == CharT{
'O'})
5587 const CharT f[] = {
'%', modified, *fmt};
5588 auto const& ymd = fds.ymd;
5589 tm.tm_year =
static_cast<int>(ymd.year()) - 1900;
5590 tm.tm_wday =
static_cast<int>(extract_weekday(os, fds));
5593 tm.tm_yday =
static_cast<int>((ld - local_days(ymd.year()/1/1)).count());
5594 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5607 auto wd = extract_weekday(os, fds);
5611 if (modified == CharT{})
5613 if (modified != CharT{
'E'})
5619 else if (modified == CharT{
'O'})
5621 const CharT f[] = {
'%', modified, *fmt};
5622 tm.tm_wday =
static_cast<int>(wd);
5623 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5628 os << CharT{
'%'} << modified << *fmt;
5639 if (modified == CharT{
'E'})
5640 os << CharT{
'%'} << modified << *fmt;
5643 auto const& ymd = fds.ymd;
5645 os.setstate(std::ios::failbit);
5646 auto ld = local_days(ymd);
5648 if (modified == CharT{})
5651 auto st = local_days(Monday[1]/January/ymd.year());
5653 os << CharT{
'0'} << CharT{
'0'};
5656 auto wn = duration_cast<weeks>(ld - st).count() + 1;
5663 else if (modified == CharT{
'O'})
5665 const CharT f[] = {
'%', modified, *fmt};
5666 tm.tm_year =
static_cast<int>(ymd.year()) - 1900;
5667 tm.tm_wday =
static_cast<int>(extract_weekday(os, fds));
5670 tm.tm_yday =
static_cast<int>((ld - local_days(ymd.year()/1/1)).count());
5671 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5684 if (modified == CharT{
'O'})
5685 os << CharT{
'%'} << modified << *fmt;
5689 os.setstate(std::ios::failbit);
5692 tm.tm_sec =
static_cast<int>(fds.tod.seconds().count());
5693 tm.tm_min =
static_cast<int>(fds.tod.minutes().count());
5694 tm.tm_hour =
static_cast<int>(fds.tod.hours().count());
5696 auto fe = std::begin(f) + 1;
5697 if (modified == CharT{
'E'})
5700 facet.put(os, os, os.fill(), &tm, std::begin(f), fe);
5714 if (!fds.ymd.year().ok())
5715 os.setstate(std::ios::failbit);
5716 auto y =
static_cast<int>(fds.ymd.year());
5718 if (modified == CharT{})
5721 y = std::abs(y) % 100;
5729 const CharT f[] = {
'%', modified, *fmt};
5730 tm.tm_year = y - 1900;
5731 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5743 if (modified == CharT{
'O'})
5744 os << CharT{
'%'} << modified << *fmt;
5747 if (!fds.ymd.year().ok())
5748 os.setstate(std::ios::failbit);
5749 auto y = fds.ymd.year();
5751 if (modified == CharT{})
5754 save_ostream<CharT, Traits> _(os);
5755 os.imbue(std::locale::classic());
5759 else if (modified == CharT{
'E'})
5761 const CharT f[] = {
'%', modified, *fmt};
5762 tm.tm_year =
static_cast<int>(y) - 1900;
5763 facet.put(os, os, os.fill(), &tm, std::begin(f), std::end(f));
5776 if (offset_sec ==
nullptr)
5779 os.setstate(ios::failbit);
5782 auto m = duration_cast<minutes>(*offset_sec);
5783 auto neg = m < minutes{0};
5785 auto h = duration_cast<hours>(m);
5794 if (modified != CharT{})
5796 if (m < minutes{10})
5808 if (modified == CharT{})
5810 if (abbrev ==
nullptr)
5813 os.setstate(ios::failbit);
5816 for (
auto c : *abbrev)
5821 os << CharT{
'%'} << modified << *fmt;
5833 if (modified == CharT{})
5839 os << CharT{
'%'} << modified << *fmt;
5850 if (modified == CharT{})
5857 os << CharT{
'%'} << modified << CharT{
'%'};
5871 if (modified != CharT{})
5882 if (modified != CharT{})
5887template <
class CharT,
class Traits>
5889std::basic_ostream<CharT, Traits>&
5890to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
const year& y)
5892 using CT = std::chrono::seconds;
5893 fields<CT> fds{y/0/0};
5894 return to_stream(os, fmt, fds);
5897template <
class CharT,
class Traits>
5899std::basic_ostream<CharT, Traits>&
5900to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
const month& m)
5902 using CT = std::chrono::seconds;
5903 fields<CT> fds{m/0/nanyear};
5904 return to_stream(os, fmt, fds);
5907template <
class CharT,
class Traits>
5909std::basic_ostream<CharT, Traits>&
5910to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
const day& d)
5912 using CT = std::chrono::seconds;
5913 fields<CT> fds{d/0/nanyear};
5914 return to_stream(os, fmt, fds);
5917template <
class CharT,
class Traits>
5919std::basic_ostream<CharT, Traits>&
5920to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
const weekday& wd)
5922 using CT = std::chrono::seconds;
5924 return to_stream(os, fmt, fds);
5927template <
class CharT,
class Traits>
5929std::basic_ostream<CharT, Traits>&
5930to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
const year_month& ym)
5932 using CT = std::chrono::seconds;
5933 fields<CT> fds{ym/0};
5934 return to_stream(os, fmt, fds);
5937template <
class CharT,
class Traits>
5939std::basic_ostream<CharT, Traits>&
5940to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
const month_day& md)
5942 using CT = std::chrono::seconds;
5943 fields<CT> fds{md/nanyear};
5944 return to_stream(os, fmt, fds);
5947template <
class CharT,
class Traits>
5949std::basic_ostream<CharT, Traits>&
5950to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
5951 const year_month_day& ymd)
5953 using CT = std::chrono::seconds;
5954 fields<CT> fds{ymd};
5955 return to_stream(os, fmt, fds);
5958template <
class CharT,
class Traits,
class Rep,
class Period>
5960std::basic_ostream<CharT, Traits>&
5961to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
5962 const std::chrono::duration<Rep, Period>& d)
5964 using Duration = std::chrono::duration<Rep, Period>;
5965 using CT =
typename std::common_type<Duration, std::chrono::seconds>::type;
5966 fields<CT> fds{hh_mm_ss<CT>{d}};
5967 return to_stream(os, fmt, fds);
5970template <
class CharT,
class Traits,
class Duration>
5971std::basic_ostream<CharT, Traits>&
5972to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
5973 const local_time<Duration>& tp,
const std::string* abbrev =
nullptr,
5974 const std::chrono::seconds* offset_sec =
nullptr)
5976 using CT =
typename std::common_type<Duration, std::chrono::seconds>::type;
5977 auto ld = floor<days>(tp);
5978 fields<CT> fds{year_month_day{ld}, hh_mm_ss<CT>{tp-local_seconds{ld}}};
5979 return to_stream(os, fmt, fds, abbrev, offset_sec);
5982template <
class CharT,
class Traits,
class Duration>
5983std::basic_ostream<CharT, Traits>&
5984to_stream(std::basic_ostream<CharT, Traits>& os,
const CharT* fmt,
5985 const sys_time<Duration>& tp)
5987 using std::chrono::seconds;
5988 using CT =
typename std::common_type<Duration, seconds>::type;
5989 const std::string abbrev(
"UTC");
5990 CONSTDATA seconds offset{0};
5991 auto sd = floor<days>(tp);
5992 fields<CT> fds{year_month_day{sd}, hh_mm_ss<CT>{tp-sys_seconds{sd}}};
5993 return to_stream(os, fmt, fds, &abbrev, &offset);
5998template <
class CharT,
class Streamable>
6000format(
const std::locale& loc,
const CharT* fmt,
const Streamable& tp)
6001 ->
decltype(to_stream(std::declval<std::basic_ostream<CharT>&>(), fmt, tp),
6002 std::basic_string<CharT>{})
6004 std::basic_ostringstream<CharT> os;
6005 os.exceptions(std::ios::failbit | std::ios::badbit);
6007 to_stream(os, fmt, tp);
6011template <
class CharT,
class Streamable>
6013format(
const CharT* fmt,
const Streamable& tp)
6014 ->
decltype(to_stream(std::declval<std::basic_ostream<CharT>&>(), fmt, tp),
6015 std::basic_string<CharT>{})
6017 std::basic_ostringstream<CharT> os;
6018 os.exceptions(std::ios::failbit | std::ios::badbit);
6019 to_stream(os, fmt, tp);
6023template <
class CharT,
class Traits,
class Alloc,
class Streamable>
6025format(
const std::locale& loc,
const std::basic_string<CharT, Traits, Alloc>& fmt,
6026 const Streamable& tp)
6027 ->
decltype(to_stream(std::declval<std::basic_ostream<CharT, Traits>&>(), fmt.c_str(), tp),
6028 std::basic_string<CharT, Traits, Alloc>{})
6030 std::basic_ostringstream<CharT, Traits, Alloc> os;
6031 os.exceptions(std::ios::failbit | std::ios::badbit);
6033 to_stream(os, fmt.c_str(), tp);
6037template <
class CharT,
class Traits,
class Alloc,
class Streamable>
6039format(
const std::basic_string<CharT, Traits, Alloc>& fmt,
const Streamable& tp)
6040 ->
decltype(to_stream(std::declval<std::basic_ostream<CharT, Traits>&>(), fmt.c_str(), tp),
6041 std::basic_string<CharT, Traits, Alloc>{})
6043 std::basic_ostringstream<CharT, Traits, Alloc> os;
6044 os.exceptions(std::ios::failbit | std::ios::badbit);
6045 to_stream(os, fmt.c_str(), tp);
6054template <
class CharT,
class Traits>
6056read_char(std::basic_istream<CharT, Traits>& is, CharT fmt, std::ios::iostate& err)
6059 if (Traits::eq_int_type(ic, Traits::eof()) ||
6060 !Traits::eq(Traits::to_char_type(ic), fmt))
6062 err |= std::ios::failbit;
6063 is.setstate(std::ios::failbit);
6069template <
class CharT,
class Traits>
6071read_unsigned(std::basic_istream<CharT, Traits>& is,
unsigned m = 1,
unsigned M = 10)
6077 auto ic = is.peek();
6078 if (Traits::eq_int_type(ic, Traits::eof()))
6080 auto c =
static_cast<char>(Traits::to_char_type(ic));
6081 if (!(
'0' <= c && c <=
'9'))
6085 x = 10*x +
static_cast<unsigned>(c -
'0');
6090 is.setstate(std::ios::failbit);
6094template <
class CharT,
class Traits>
6096read_signed(std::basic_istream<CharT, Traits>& is,
unsigned m = 1,
unsigned M = 10)
6098 auto ic = is.peek();
6099 if (!Traits::eq_int_type(ic, Traits::eof()))
6101 auto c =
static_cast<char>(Traits::to_char_type(ic));
6102 if ((
'0' <= c && c <=
'9') || c ==
'-' || c ==
'+')
6104 if (c ==
'-' || c ==
'+')
6106 auto x =
static_cast<int>(read_unsigned(is, (std::max)(m, 1u), M));
6116 is.setstate(std::ios::failbit);
6120template <
class CharT,
class Traits>
6122read_long_double(std::basic_istream<CharT, Traits>& is,
unsigned m = 1,
unsigned M = 10)
6125 auto decimal_point = Traits::to_int_type(
6126 std::use_facet<std::numpunct<CharT>>(is.getloc()).decimal_point());
6130 auto ic = is.peek();
6131 if (Traits::eq_int_type(ic, Traits::eof()))
6133 if (Traits::eq_int_type(ic, decimal_point))
6136 decimal_point = Traits::eof();
6141 auto c =
static_cast<char>(Traits::to_char_type(ic));
6142 if (!(
'0' <= c && c <=
'9'))
6152 is.setstate(std::ios::failbit);
6155 return std::stold(buf);
6179template <
class CharT,
class Traits>
6181read(std::basic_istream<CharT, Traits>&)
6185template <
class CharT,
class Traits,
class ...Args>
6187read(std::basic_istream<CharT, Traits>& is, CharT a0, Args&& ...args);
6189template <
class CharT,
class Traits,
class ...Args>
6191read(std::basic_istream<CharT, Traits>& is, rs a0, Args&& ...args);
6193template <
class CharT,
class Traits,
class ...Args>
6195read(std::basic_istream<CharT, Traits>& is, ru a0, Args&& ...args);
6197template <
class CharT,
class Traits,
class ...Args>
6199read(std::basic_istream<CharT, Traits>& is,
int a0, Args&& ...args);
6201template <
class CharT,
class Traits,
class ...Args>
6203read(std::basic_istream<CharT, Traits>& is, rld a0, Args&& ...args);
6205template <
class CharT,
class Traits,
class ...Args>
6207read(std::basic_istream<CharT, Traits>& is, CharT a0, Args&& ...args)
6212 auto ic = is.peek();
6213 if (Traits::eq_int_type(ic, Traits::eof()))
6215 is.setstate(std::ios::failbit | std::ios::eofbit);
6218 if (!Traits::eq(Traits::to_char_type(ic), a0))
6220 is.setstate(std::ios::failbit);
6225 read(is, std::forward<Args>(args)...);
6228template <
class CharT,
class Traits,
class ...Args>
6230read(std::basic_istream<CharT, Traits>& is, rs a0, Args&& ...args)
6232 auto x = read_signed(is, a0.m, a0.M);
6236 read(is, std::forward<Args>(args)...);
6239template <
class CharT,
class Traits,
class ...Args>
6241read(std::basic_istream<CharT, Traits>& is, ru a0, Args&& ...args)
6243 auto x = read_unsigned(is, a0.m, a0.M);
6246 a0.i =
static_cast<int>(x);
6247 read(is, std::forward<Args>(args)...);
6250template <
class CharT,
class Traits,
class ...Args>
6252read(std::basic_istream<CharT, Traits>& is,
int a0, Args&& ...args)
6256 auto u =
static_cast<unsigned>(a0);
6257 CharT buf[std::numeric_limits<unsigned>::digits10+2u] = {};
6261 *e++ =
static_cast<CharT
>(CharT(u % 10) + CharT{
'0'});
6264 std::reverse(buf, e);
6265 for (
auto p = buf; p != e && is.rdstate() == std::ios::goodbit; ++p)
6268 if (is.rdstate() == std::ios::goodbit)
6269 read(is, std::forward<Args>(args)...);
6272template <
class CharT,
class Traits,
class ...Args>
6274read(std::basic_istream<CharT, Traits>& is, rld a0, Args&& ...args)
6276 auto x = read_long_double(is, a0.m, a0.M);
6280 read(is, std::forward<Args>(args)...);
6283template <
class T,
class CharT,
class Traits>
6286checked_set(T& value, T from, T not_a_value, std::basic_ios<CharT, Traits>& is)
6290 if (value == not_a_value)
6291 value = std::move(from);
6292 else if (value != from)
6293 is.setstate(std::ios::failbit);
6299template <
class CharT,
class Traits,
class Duration,
class Alloc = std::allocator<CharT>>
6300std::basic_istream<CharT, Traits>&
6301from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt,
6302 fields<Duration>& fds, std::basic_string<CharT, Traits, Alloc>* abbrev,
6303 std::chrono::minutes* offset)
6305 using std::numeric_limits;
6307 using std::chrono::duration;
6308 using std::chrono::duration_cast;
6309 using std::chrono::seconds;
6310 using std::chrono::minutes;
6311 using std::chrono::hours;
6312 typename std::basic_istream<CharT, Traits>::sentry ok{is,
true};
6317 is.flags(std::ios::skipws | std::ios::dec);
6320 auto& f = std::use_facet<std::time_get<CharT>>(is.getloc());
6323 const CharT* command =
nullptr;
6324 auto modified = CharT{};
6327 CONSTDATA
int not_a_year = (numeric_limits<int>::min)();
6328 CONSTDATA
int not_a_2digit_year = 100;
6329 CONSTDATA
int not_a_century = not_a_year / 100;
6330 CONSTDATA
int not_a_month = 0;
6331 CONSTDATA
int not_a_day = 0;
6332 CONSTDATA
int not_a_hour = (numeric_limits<int>::min)();
6333 CONSTDATA
int not_a_hour_12_value = 0;
6334 CONSTDATA
int not_a_minute = not_a_hour;
6335 CONSTDATA Duration not_a_second = (Duration::min)();
6336 CONSTDATA
int not_a_doy = -1;
6337 CONSTDATA
int not_a_weekday = 8;
6338 CONSTDATA
int not_a_week_num = 100;
6339 CONSTDATA
int not_a_ampm = -1;
6340 CONSTDATA minutes not_a_offset = (minutes::min)();
6343 int y = not_a_2digit_year;
6344 int g = not_a_2digit_year;
6346 int C = not_a_century;
6347 int m = not_a_month;
6350 int wd = not_a_weekday;
6352 int I = not_a_hour_12_value;
6354 int M = not_a_minute;
6355 Duration s = not_a_second;
6356 int U = not_a_week_num;
6357 int V = not_a_week_num;
6358 int W = not_a_week_num;
6359 std::basic_string<CharT, Traits, Alloc> temp_abbrev;
6360 minutes temp_offset = not_a_offset;
6366 using detail::checked_set;
6367 for (; *fmt != CharT{} && !is.fail(); ++fmt)
6377 int trial_wd = not_a_weekday;
6378 if (*fmt ==
'a' || *fmt ==
'A')
6380 if (modified == CharT{})
6383 ios::iostate err = ios::goodbit;
6384 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6387 trial_wd = tm.tm_wday;
6389 auto nm = detail::weekday_names();
6390 auto i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6396 read(is, CharT{
'%'}, width, modified, *fmt);
6401 if (modified == CharT{})
6403 if (modified != CharT{
'E'})
6406 read(is, ru{trial_wd, 1, width == -1 ?
6407 1u :
static_cast<unsigned>(width)});
6412 if (!(1 <= trial_wd && trial_wd <= 7))
6414 trial_wd = not_a_weekday;
6415 is.setstate(ios::failbit);
6417 else if (trial_wd == 7)
6422 if (!(0 <= trial_wd && trial_wd <= 6))
6424 trial_wd = not_a_weekday;
6425 is.setstate(ios::failbit);
6431 else if (modified == CharT{
'O'})
6433 ios::iostate err = ios::goodbit;
6434 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6437 trial_wd = tm.tm_wday;
6441 read(is, CharT{
'%'}, width, modified, *fmt);
6443 if (trial_wd != not_a_weekday)
6444 checked_set(wd, trial_wd, not_a_weekday, is);
6457 if (modified == CharT{})
6459 int ttm = not_a_month;
6461 ios::iostate err = ios::goodbit;
6462 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6463 if ((err & ios::failbit) == 0)
6464 ttm = tm.tm_mon + 1;
6467 auto nm = detail::month_names();
6468 auto i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6472 checked_set(m, ttm, not_a_month, is);
6475 read(is, CharT{
'%'}, width, modified, *fmt);
6486 if (modified != CharT{
'O'})
6489 ios::iostate err = ios::goodbit;
6490 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6491 if ((err & ios::failbit) == 0)
6493 checked_set(Y, tm.tm_year + 1900, not_a_year, is);
6494 checked_set(m, tm.tm_mon + 1, not_a_month, is);
6495 checked_set(d, tm.tm_mday, not_a_day, is);
6496 checked_set(H, tm.tm_hour, not_a_hour, is);
6497 checked_set(M, tm.tm_min, not_a_minute, is);
6498 checked_set(s, duration_cast<Duration>(seconds{tm.tm_sec}),
6504 auto nm = detail::weekday_names();
6505 auto i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6506 checked_set(wd,
static_cast<int>(i % 7), not_a_weekday, is);
6508 nm = detail::month_names();
6509 i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6510 checked_set(m,
static_cast<int>(i % 12 + 1), not_a_month, is);
6513 read(is, rs{td, 1, 2});
6514 checked_set(d, td, not_a_day, is);
6516 using dfs = detail::decimal_format_seconds<Duration>;
6517 CONSTDATA
auto w = Duration::period::den == 1 ? 2 : 3 + dfs::width;
6521 read(is, ru{tH, 1, 2}, CharT{
':'}, ru{tM, 1, 2},
6522 CharT{
':'}, rld{S, 1, w});
6523 checked_set(H, tH, not_a_hour, is);
6524 checked_set(M, tM, not_a_minute, is);
6525 checked_set(s, round<Duration>(duration<long double>{S}),
6528 int tY = not_a_year;
6529 read(is, rs{tY, 1, 4u});
6530 checked_set(Y, tY, not_a_year, is);
6534 read(is, CharT{
'%'}, width, modified, *fmt);
6545 if (modified != CharT{
'O'})
6548 ios::iostate err = ios::goodbit;
6549 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6550 if ((err & ios::failbit) == 0)
6552 checked_set(Y, tm.tm_year + 1900, not_a_year, is);
6553 checked_set(m, tm.tm_mon + 1, not_a_month, is);
6554 checked_set(d, tm.tm_mday, not_a_day, is);
6559 int ty = not_a_2digit_year;
6560 int tm = not_a_month;
6562 read(is, ru{tm, 1, 2}, CharT{
'/'}, ru{td, 1, 2}, CharT{
'/'},
6564 checked_set(y, ty, not_a_2digit_year, is);
6565 checked_set(m, tm, not_a_month, is);
6566 checked_set(d, td, not_a_day, is);
6570 read(is, CharT{
'%'}, width, modified, *fmt);
6581 if (modified != CharT{
'O'})
6584 ios::iostate err = ios::goodbit;
6585 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6586 if ((err & ios::failbit) == 0)
6588 checked_set(H, tm.tm_hour, not_a_hour, is);
6589 checked_set(M, tm.tm_min, not_a_minute, is);
6590 checked_set(s, duration_cast<Duration>(seconds{tm.tm_sec}),
6596 using dfs = detail::decimal_format_seconds<Duration>;
6597 CONSTDATA
auto w = Duration::period::den == 1 ? 2 : 3 + dfs::width;
6598 int tH = not_a_hour;
6599 int tM = not_a_minute;
6601 read(is, ru{tH, 1, 2}, CharT{
':'}, ru{tM, 1, 2},
6602 CharT{
':'}, rld{S, 1, w});
6603 checked_set(H, tH, not_a_hour, is);
6604 checked_set(M, tM, not_a_minute, is);
6605 checked_set(s, round<Duration>(duration<long double>{S}),
6610 read(is, CharT{
'%'}, width, modified, *fmt);
6621 int tC = not_a_century;
6623 if (modified == CharT{})
6626 read(is, rs{tC, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6631 ios::iostate err = ios::goodbit;
6632 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6633 if ((err & ios::failbit) == 0)
6635 auto tY = tm.tm_year + 1900;
6636 tC = (tY >= 0 ? tY : tY-99) / 100;
6641 checked_set(C, tC, not_a_century, is);
6652 if (modified == CharT{})
6654 int tn = not_a_month;
6656 int ty = not_a_2digit_year;
6657 read(is, ru{tn, 1, 2}, CharT{
'\0'}, CharT{
'/'}, CharT{
'\0'},
6658 ru{td, 1, 2}, CharT{
'\0'}, CharT{
'/'}, CharT{
'\0'},
6660 checked_set(y, ty, not_a_2digit_year, is);
6661 checked_set(m, tn, not_a_month, is);
6662 checked_set(d, td, not_a_day, is);
6665 read(is, CharT{
'%'}, width, modified, *fmt);
6676 if (modified == CharT{})
6678 int tY = not_a_year;
6679 int tn = not_a_month;
6681 read(is, rs{tY, 1, width == -1 ? 4u :
static_cast<unsigned>(width)},
6682 CharT{
'-'}, ru{tn, 1, 2}, CharT{
'-'}, ru{td, 1, 2});
6683 checked_set(Y, tY, not_a_year, is);
6684 checked_set(m, tn, not_a_month, is);
6685 checked_set(d, td, not_a_day, is);
6688 read(is, CharT{
'%'}, width, modified, *fmt);
6701 if (modified == CharT{})
6703 if (modified != CharT{
'E'})
6707 read(is, rs{td, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6708 checked_set(d, td, not_a_day, is);
6711 else if (modified == CharT{
'O'})
6713 ios::iostate err = ios::goodbit;
6714 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6718 if ((err & ios::failbit) == 0)
6719 checked_set(d, tm.tm_mday, not_a_day, is);
6724 read(is, CharT{
'%'}, width, modified, *fmt);
6736 if (modified == CharT{})
6738 if (modified != CharT{
'E'})
6741 int tH = not_a_hour;
6742 read(is, ru{tH, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6743 checked_set(H, tH, not_a_hour, is);
6746 else if (modified == CharT{
'O'})
6748 ios::iostate err = ios::goodbit;
6749 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6750 if ((err & ios::failbit) == 0)
6751 checked_set(H, tm.tm_hour, not_a_hour, is);
6756 read(is, CharT{
'%'}, width, modified, *fmt);
6767 if (modified == CharT{})
6769 int tI = not_a_hour_12_value;
6771 read(is, rs{tI, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6772 if (!(1 <= tI && tI <= 12))
6773 is.setstate(ios::failbit);
6774 checked_set(I, tI, not_a_hour_12_value, is);
6777 read(is, CharT{
'%'}, width, modified, *fmt);
6788 if (modified == CharT{})
6791 read(is, ru{tj, 1, width == -1 ? 3u :
static_cast<unsigned>(width)});
6792 checked_set(j, tj, not_a_doy, is);
6795 read(is, CharT{
'%'}, width, modified, *fmt);
6807 if (modified == CharT{})
6809 if (modified != CharT{
'E'})
6812 int tM = not_a_minute;
6813 read(is, ru{tM, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6814 checked_set(M, tM, not_a_minute, is);
6817 else if (modified == CharT{
'O'})
6819 ios::iostate err = ios::goodbit;
6820 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6821 if ((err & ios::failbit) == 0)
6822 checked_set(M, tm.tm_min, not_a_minute, is);
6827 read(is, CharT{
'%'}, width, modified, *fmt);
6839 if (modified == CharT{})
6841 if (modified != CharT{
'E'})
6844 int tn = not_a_month;
6845 read(is, rs{tn, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
6846 checked_set(m, tn, not_a_month, is);
6849 else if (modified == CharT{
'O'})
6851 ios::iostate err = ios::goodbit;
6852 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6853 if ((err & ios::failbit) == 0)
6854 checked_set(m, tm.tm_mon + 1, not_a_month, is);
6859 read(is, CharT{
'%'}, width, modified, *fmt);
6871 if (modified == CharT{})
6875 auto ic = is.peek();
6876 if (Traits::eq_int_type(ic, Traits::eof()))
6878 ios::iostate err = ios::eofbit;
6880 err |= ios::failbit;
6888 else if (*fmt ==
'n')
6889 is.setstate(ios::failbit);
6892 read(is, CharT{
'%'}, width, modified, *fmt);
6903 if (modified == CharT{})
6905 int tp = not_a_ampm;
6909 ios::iostate err = ios::goodbit;
6910 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6912 if (tm.tm_hour == 1)
6914 else if (tm.tm_hour == 13)
6919 auto nm = detail::ampm_names();
6920 auto i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6923 checked_set(p, tp, not_a_ampm, is);
6926 read(is, CharT{
'%'}, width, modified, *fmt);
6938 if (modified == CharT{})
6941 ios::iostate err = ios::goodbit;
6942 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
6943 if ((err & ios::failbit) == 0)
6945 checked_set(H, tm.tm_hour, not_a_hour, is);
6946 checked_set(M, tm.tm_min, not_a_hour, is);
6947 checked_set(s, duration_cast<Duration>(seconds{tm.tm_sec}),
6953 using dfs = detail::decimal_format_seconds<Duration>;
6954 CONSTDATA
auto w = Duration::period::den == 1 ? 2 : 3 + dfs::width;
6956 int tI = not_a_hour_12_value;
6957 int tM = not_a_minute;
6958 read(is, ru{tI, 1, 2}, CharT{
':'}, ru{tM, 1, 2},
6959 CharT{
':'}, rld{S, 1, w});
6960 checked_set(I, tI, not_a_hour_12_value, is);
6961 checked_set(M, tM, not_a_minute, is);
6962 checked_set(s, round<Duration>(duration<long double>{S}),
6965 auto nm = detail::ampm_names();
6966 auto i = detail::scan_keyword(is, nm.first, nm.second) - nm.first;
6967 checked_set(p,
static_cast<int>(i), not_a_ampm, is);
6971 read(is, CharT{
'%'}, width, modified, *fmt);
6982 if (modified == CharT{})
6984 int tH = not_a_hour;
6985 int tM = not_a_minute;
6986 read(is, ru{tH, 1, 2}, CharT{
'\0'}, CharT{
':'}, CharT{
'\0'},
6987 ru{tM, 1, 2}, CharT{
'\0'});
6988 checked_set(H, tH, not_a_hour, is);
6989 checked_set(M, tM, not_a_minute, is);
6992 read(is, CharT{
'%'}, width, modified, *fmt);
7004 if (modified == CharT{})
7006 if (modified != CharT{
'E'})
7009 using dfs = detail::decimal_format_seconds<Duration>;
7010 CONSTDATA
auto w = Duration::period::den == 1 ? 2 : 3 + dfs::width;
7012 read(is, rld{S, 1, width == -1 ? w :
static_cast<unsigned>(width)});
7013 checked_set(s, round<Duration>(duration<long double>{S}),
7017 else if (modified == CharT{
'O'})
7019 ios::iostate err = ios::goodbit;
7020 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
7021 if ((err & ios::failbit) == 0)
7022 checked_set(s, duration_cast<Duration>(seconds{tm.tm_sec}),
7028 read(is, CharT{
'%'}, width, modified, *fmt);
7039 if (modified == CharT{})
7041 using dfs = detail::decimal_format_seconds<Duration>;
7042 CONSTDATA
auto w = Duration::period::den == 1 ? 2 : 3 + dfs::width;
7043 int tH = not_a_hour;
7044 int tM = not_a_minute;
7046 read(is, ru{tH, 1, 2}, CharT{
':'}, ru{tM, 1, 2},
7047 CharT{
':'}, rld{S, 1, w});
7048 checked_set(H, tH, not_a_hour, is);
7049 checked_set(M, tM, not_a_minute, is);
7050 checked_set(s, round<Duration>(duration<long double>{S}),
7054 read(is, CharT{
'%'}, width, modified, *fmt);
7066 if (modified == CharT{})
7068 if (modified != CharT{
'O'})
7071 int tY = not_a_year;
7072 read(is, rs{tY, 1, width == -1 ? 4u :
static_cast<unsigned>(width)});
7073 checked_set(Y, tY, not_a_year, is);
7076 else if (modified == CharT{
'E'})
7078 ios::iostate err = ios::goodbit;
7079 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
7080 if ((err & ios::failbit) == 0)
7081 checked_set(Y, tm.tm_year + 1900, not_a_year, is);
7086 read(is, CharT{
'%'}, width, modified, *fmt);
7098 if (modified == CharT{})
7101 int ty = not_a_2digit_year;
7102 read(is, ru{ty, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
7103 checked_set(y, ty, not_a_2digit_year, is);
7108 ios::iostate err = ios::goodbit;
7109 f.get(is,
nullptr, is, err, &tm, command, fmt+1);
7110 if ((err & ios::failbit) == 0)
7111 checked_set(Y, tm.tm_year + 1900, not_a_year, is);
7125 if (modified == CharT{})
7127 int tg = not_a_2digit_year;
7128 read(is, ru{tg, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
7129 checked_set(g, tg, not_a_2digit_year, is);
7132 read(is, CharT{
'%'}, width, modified, *fmt);
7143 if (modified == CharT{})
7145 int tG = not_a_year;
7146 read(is, rs{tG, 1, width == -1 ? 4u :
static_cast<unsigned>(width)});
7147 checked_set(G, tG, not_a_year, is);
7150 read(is, CharT{
'%'}, width, modified, *fmt);
7161 if (modified == CharT{})
7163 int tU = not_a_week_num;
7164 read(is, ru{tU, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
7165 checked_set(U, tU, not_a_week_num, is);
7168 read(is, CharT{
'%'}, width, modified, *fmt);
7179 if (modified == CharT{})
7181 int tV = not_a_week_num;
7182 read(is, ru{tV, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
7183 checked_set(V, tV, not_a_week_num, is);
7186 read(is, CharT{
'%'}, width, modified, *fmt);
7197 if (modified == CharT{})
7199 int tW = not_a_week_num;
7200 read(is, ru{tW, 1, width == -1 ? 2u :
static_cast<unsigned>(width)});
7201 checked_set(W, tW, not_a_week_num, is);
7204 read(is, CharT{
'%'}, width, modified, *fmt);
7216 if (modified == CharT{})
7222 read(is, CharT{
'%'}, width, modified, *fmt);
7234 if (modified == CharT{})
7237 read(is, CharT{
'%'}, width, modified, *fmt);
7249 minutes toff = not_a_offset;
7251 auto ic = is.peek();
7252 if (!Traits::eq_int_type(ic, Traits::eof()))
7254 auto c =
static_cast<char>(Traits::to_char_type(ic));
7258 if (modified == CharT{})
7260 read(is, rs{tH, 2, 2});
7262 toff = hours{std::abs(tH)};
7266 if (!Traits::eq_int_type(ic, Traits::eof()))
7268 auto c =
static_cast<char>(Traits::to_char_type(ic));
7269 if (
'0' <= c && c <=
'9')
7271 read(is, ru{tM, 2, 2});
7273 toff += minutes{tM};
7280 read(is, rs{tH, 1, 2});
7282 toff = hours{std::abs(tH)};
7286 if (!Traits::eq_int_type(ic, Traits::eof()))
7288 auto c =
static_cast<char>(Traits::to_char_type(ic));
7292 read(is, ru{tM, 2, 2});
7294 toff += minutes{tM};
7301 checked_set(temp_offset, toff, not_a_offset, is);
7312 if (modified == CharT{})
7314 std::basic_string<CharT, Traits, Alloc> buf;
7315 while (is.rdstate() == std::ios::goodbit)
7317 auto i = is.rdbuf()->sgetc();
7318 if (Traits::eq_int_type(i, Traits::eof()))
7320 is.setstate(ios::eofbit);
7323 auto wc = Traits::to_char_type(i);
7324 auto c =
static_cast<char>(wc);
7326 if (!(CharT{1} < wc && wc < CharT{127}) || !(isalnum(c) ||
7327 c ==
'_' || c ==
'/' || c ==
'-' || c ==
'+'))
7330 is.rdbuf()->sbumpc();
7333 is.setstate(ios::failbit);
7334 checked_set(temp_abbrev, buf, {}, is);
7337 read(is, CharT{
'%'}, width, modified, *fmt);
7348 if (width == -1 && modified == CharT{} &&
'0' <= *fmt && *fmt <=
'9')
7350 width =
static_cast<char>(*fmt) -
'0';
7351 while (
'0' <= fmt[1] && fmt[1] <=
'9')
7352 width = 10*width +
static_cast<char>(*++fmt) -
'0';
7356 if (modified == CharT{})
7357 read(is, CharT{
'%'}, width, *fmt);
7359 read(is, CharT{
'%'}, width, modified, *fmt);
7367 if (isspace(
static_cast<unsigned char>(*fmt)))
7380 if (is.rdstate() == ios::goodbit && command)
7382 if (modified == CharT{})
7383 read(is, CharT{
'%'}, width);
7385 read(is, CharT{
'%'}, width, modified);
7389 if (y != not_a_2digit_year)
7392 if (!(0 <= y && y <= 99))
7394 if (C == not_a_century)
7396 if (Y == not_a_year)
7405 C = (Y >= 0 ? Y : Y-100) / 100;
7412 tY = 100*(C+1) - (y == 0 ? 100 : y);
7413 if (Y != not_a_year && Y != tY)
7417 if (g != not_a_2digit_year)
7420 if (!(0 <= g && g <= 99))
7422 if (C == not_a_century)
7424 if (G == not_a_year)
7433 C = (G >= 0 ? G : G-100) / 100;
7440 tG = 100*(C+1) - (g == 0 ? 100 : g);
7441 if (G != not_a_year && G != tG)
7445 if (Y <
static_cast<int>((year::min)()) || Y >
static_cast<int>((year::max)()))
7447 bool computed =
false;
7448 if (G != not_a_year && V != not_a_week_num && wd != not_a_weekday)
7450 year_month_day ymd_trial = sys_days(year{G-1}/December/Thursday[last]) +
7451 (Monday-Thursday) + weeks{V-1} +
7452 (weekday{
static_cast<unsigned>(wd)}-Monday);
7453 if (Y == not_a_year)
7454 Y =
static_cast<int>(ymd_trial.year());
7455 else if (year{Y} != ymd_trial.year())
7457 if (m == not_a_month)
7458 m =
static_cast<int>(
static_cast<unsigned>(ymd_trial.month()));
7459 else if (month(
static_cast<unsigned>(m)) != ymd_trial.month())
7462 d =
static_cast<int>(
static_cast<unsigned>(ymd_trial.day()));
7463 else if (day(
static_cast<unsigned>(d)) != ymd_trial.day())
7467 if (Y != not_a_year && U != not_a_week_num && wd != not_a_weekday)
7469 year_month_day ymd_trial = sys_days(year{Y}/January/Sunday[1]) +
7471 (weekday{
static_cast<unsigned>(wd)} - Sunday);
7472 if (Y == not_a_year)
7473 Y =
static_cast<int>(ymd_trial.year());
7474 else if (year{Y} != ymd_trial.year())
7476 if (m == not_a_month)
7477 m =
static_cast<int>(
static_cast<unsigned>(ymd_trial.month()));
7478 else if (month(
static_cast<unsigned>(m)) != ymd_trial.month())
7481 d =
static_cast<int>(
static_cast<unsigned>(ymd_trial.day()));
7482 else if (day(
static_cast<unsigned>(d)) != ymd_trial.day())
7486 if (Y != not_a_year && W != not_a_week_num && wd != not_a_weekday)
7488 year_month_day ymd_trial = sys_days(year{Y}/January/Monday[1]) +
7490 (weekday{
static_cast<unsigned>(wd)} - Monday);
7491 if (Y == not_a_year)
7492 Y =
static_cast<int>(ymd_trial.year());
7493 else if (year{Y} != ymd_trial.year())
7495 if (m == not_a_month)
7496 m =
static_cast<int>(
static_cast<unsigned>(ymd_trial.month()));
7497 else if (month(
static_cast<unsigned>(m)) != ymd_trial.month())
7500 d =
static_cast<int>(
static_cast<unsigned>(ymd_trial.day()));
7501 else if (day(
static_cast<unsigned>(d)) != ymd_trial.day())
7505 if (j != not_a_doy && Y != not_a_year)
7507 auto ymd_trial = year_month_day{local_days(year{Y}/1/1) + days{j-1}};
7509 m =
static_cast<int>(
static_cast<unsigned>(ymd_trial.month()));
7510 else if (month(
static_cast<unsigned>(m)) != ymd_trial.month())
7513 d =
static_cast<int>(
static_cast<unsigned>(ymd_trial.day()));
7514 else if (day(
static_cast<unsigned>(d)) != ymd_trial.day())
7518 auto ymd = year{Y}/m/d;
7521 if (wd == not_a_weekday)
7522 wd =
static_cast<int>((weekday(sys_days(ymd)) - Sunday).count());
7523 else if (wd !=
static_cast<int>((weekday(sys_days(ymd)) - Sunday).count()))
7527 if (G != not_a_year || V != not_a_week_num)
7530 auto G_trial = year_month_day{sd + days{3}}.year();
7531 auto start = sys_days((G_trial - years{1})/December/Thursday[last]) +
7532 (Monday - Thursday);
7536 if (V != not_a_week_num)
7537 start = sys_days((G_trial - years{1})/December/Thursday[last])
7538 + (Monday - Thursday);
7540 if (G != not_a_year && G !=
static_cast<int>(G_trial))
7542 if (V != not_a_week_num)
7544 auto V_trial = duration_cast<weeks>(sd - start).count() + 1;
7549 if (U != not_a_week_num)
7551 auto start = sys_days(Sunday[1]/January/ymd.year());
7552 auto U_trial = floor<weeks>(sys_days(ymd) - start).count() + 1;
7556 if (W != not_a_week_num)
7558 auto start = sys_days(Monday[1]/January/ymd.year());
7559 auto W_trial = floor<weeks>(sys_days(ymd) - start).count() + 1;
7566 if (I != not_a_hour_12_value)
7568 if (!(1 <= I && I <= 12))
7570 if (p != not_a_ampm)
7578 if (H == not_a_hour)
7586 if (H != not_a_hour)
7590 if (H != 0 && H != 12)
7593 else if (!(I == H || I == H+12))
7600 if (H != not_a_hour)
7603 fds.tod = hh_mm_ss<Duration>{hours{H}};
7605 if (M != not_a_minute)
7608 fds.tod.m_ = minutes{M};
7610 if (s != not_a_second)
7613 fds.tod.s_ = detail::decimal_format_seconds<Duration>{s};
7618 fds.tod.h_ += hours{days{j}};
7620 if (wd != not_a_weekday)
7621 fds.wd = weekday{
static_cast<unsigned>(wd)};
7622 if (abbrev !=
nullptr)
7623 *abbrev = std::move(temp_abbrev);
7624 if (offset !=
nullptr && temp_offset != not_a_offset)
7625 *offset = temp_offset;
7630 is.setstate(ios::failbit);
7634template <
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7635std::basic_istream<CharT, Traits>&
7636from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt, year& y,
7637 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7638 std::chrono::minutes* offset =
nullptr)
7640 using CT = std::chrono::seconds;
7642 from_stream(is, fmt, fds, abbrev, offset);
7643 if (!fds.ymd.year().ok())
7644 is.setstate(std::ios::failbit);
7650template <
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7651std::basic_istream<CharT, Traits>&
7652from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt, month& m,
7653 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7654 std::chrono::minutes* offset =
nullptr)
7656 using CT = std::chrono::seconds;
7658 from_stream(is, fmt, fds, abbrev, offset);
7659 if (!fds.ymd.month().ok())
7660 is.setstate(std::ios::failbit);
7662 m = fds.ymd.month();
7666template <
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7667std::basic_istream<CharT, Traits>&
7668from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt, day& d,
7669 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7670 std::chrono::minutes* offset =
nullptr)
7672 using CT = std::chrono::seconds;
7674 from_stream(is, fmt, fds, abbrev, offset);
7675 if (!fds.ymd.day().ok())
7676 is.setstate(std::ios::failbit);
7682template <
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7683std::basic_istream<CharT, Traits>&
7684from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt, weekday& wd,
7685 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7686 std::chrono::minutes* offset =
nullptr)
7688 using CT = std::chrono::seconds;
7690 from_stream(is, fmt, fds, abbrev, offset);
7692 is.setstate(std::ios::failbit);
7698template <
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7699std::basic_istream<CharT, Traits>&
7700from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt, year_month& ym,
7701 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7702 std::chrono::minutes* offset =
nullptr)
7704 using CT = std::chrono::seconds;
7706 from_stream(is, fmt, fds, abbrev, offset);
7707 if (!fds.ymd.month().ok())
7708 is.setstate(std::ios::failbit);
7710 ym = fds.ymd.year()/fds.ymd.month();
7714template <
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7715std::basic_istream<CharT, Traits>&
7716from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt, month_day& md,
7717 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7718 std::chrono::minutes* offset =
nullptr)
7720 using CT = std::chrono::seconds;
7722 from_stream(is, fmt, fds, abbrev, offset);
7723 if (!fds.ymd.month().ok() || !fds.ymd.day().ok())
7724 is.setstate(std::ios::failbit);
7726 md = fds.ymd.month()/fds.ymd.day();
7730template <
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7731std::basic_istream<CharT, Traits>&
7732from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt,
7733 year_month_day& ymd, std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7734 std::chrono::minutes* offset =
nullptr)
7736 using CT = std::chrono::seconds;
7738 from_stream(is, fmt, fds, abbrev, offset);
7740 is.setstate(std::ios::failbit);
7746template <
class Duration,
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7747std::basic_istream<CharT, Traits>&
7748from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt,
7749 sys_time<Duration>& tp, std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7750 std::chrono::minutes* offset =
nullptr)
7752 using CT =
typename std::common_type<Duration, std::chrono::seconds>::type;
7753 std::chrono::minutes offset_local{};
7754 auto offptr = offset ? offset : &offset_local;
7757 from_stream(is, fmt, fds, abbrev, offptr);
7758 if (!fds.ymd.ok() || !fds.tod.in_conventional_range())
7759 is.setstate(std::ios::failbit);
7761 tp = round<Duration>(sys_days(fds.ymd) - *offptr + fds.tod.to_duration());
7765template <
class Duration,
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7766std::basic_istream<CharT, Traits>&
7767from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt,
7768 local_time<Duration>& tp, std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7769 std::chrono::minutes* offset =
nullptr)
7771 using CT =
typename std::common_type<Duration, std::chrono::seconds>::type;
7774 from_stream(is, fmt, fds, abbrev, offset);
7775 if (!fds.ymd.ok() || !fds.tod.in_conventional_range())
7776 is.setstate(std::ios::failbit);
7778 tp = round<Duration>(local_seconds{local_days(fds.ymd)} + fds.tod.to_duration());
7782template <
class Rep,
class Period,
class CharT,
class Traits,
class Alloc = std::allocator<CharT>>
7783std::basic_istream<CharT, Traits>&
7784from_stream(std::basic_istream<CharT, Traits>& is,
const CharT* fmt,
7785 std::chrono::duration<Rep, Period>& d,
7786 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7787 std::chrono::minutes* offset =
nullptr)
7789 using Duration = std::chrono::duration<Rep, Period>;
7790 using CT =
typename std::common_type<Duration, std::chrono::seconds>::type;
7792 from_stream(is, fmt, fds, abbrev, offset);
7794 is.setstate(std::ios::failbit);
7796 d = std::chrono::duration_cast<Duration>(fds.tod.to_duration());
7800template <
class Parsable,
class CharT,
class Traits = std::
char_traits<CharT>,
7801 class Alloc = std::allocator<CharT>>
7804 const std::basic_string<CharT, Traits, Alloc> format_;
7806 std::basic_string<CharT, Traits, Alloc>* abbrev_;
7807 std::chrono::minutes* offset_;
7810 parse_manip(std::basic_string<CharT, Traits, Alloc> format, Parsable& tp,
7811 std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
7812 std::chrono::minutes* offset =
nullptr)
7813 : format_(std::move(format))
7821template <
class Parsable,
class CharT,
class Traits,
class Alloc>
7822std::basic_istream<CharT, Traits>&
7823operator>>(std::basic_istream<CharT, Traits>& is,
7826 return from_stream(is, x.format_.c_str(), x.tp_, x.abbrev_, x.offset_);
7829template <
class Parsable,
class CharT,
class Traits,
class Alloc>
7832parse(
const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp)
7833 ->
decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
7834 format.c_str(), tp),
7835 parse_manip<Parsable, CharT, Traits, Alloc>{format, tp})
7837 return {format, tp};
7840template <
class Parsable,
class CharT,
class Traits,
class Alloc>
7843parse(
const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp,
7844 std::basic_string<CharT, Traits, Alloc>& abbrev)
7845 ->
decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
7846 format.c_str(), tp, &abbrev),
7847 parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, &abbrev})
7849 return {format, tp, &abbrev};
7852template <
class Parsable,
class CharT,
class Traits,
class Alloc>
7855parse(
const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp,
7856 std::chrono::minutes& offset)
7857 ->
decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
7859 std::declval<std::basic_string<CharT, Traits, Alloc>*>(),
7861 parse_manip<Parsable, CharT, Traits, Alloc>{format, tp,
nullptr, &offset})
7863 return {format, tp,
nullptr, &offset};
7866template <
class Parsable,
class CharT,
class Traits,
class Alloc>
7869parse(
const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp,
7870 std::basic_string<CharT, Traits, Alloc>& abbrev, std::chrono::minutes& offset)
7871 ->
decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
7872 format.c_str(), tp, &abbrev, &offset),
7873 parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, &abbrev, &offset})
7875 return {format, tp, &abbrev, &offset};
7880template <
class Parsable,
class CharT>
7883parse(
const CharT* format, Parsable& tp)
7884 ->
decltype(from_stream(std::declval<std::basic_istream<CharT>&>(), format, tp),
7885 parse_manip<Parsable, CharT>{format, tp})
7887 return {format, tp};
7890template <
class Parsable,
class CharT,
class Traits,
class Alloc>
7893parse(
const CharT* format, Parsable& tp, std::basic_string<CharT, Traits, Alloc>& abbrev)
7894 ->
decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(), format,
7896 parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, &abbrev})
7898 return {format, tp, &abbrev};
7901template <
class Parsable,
class CharT>
7904parse(
const CharT* format, Parsable& tp, std::chrono::minutes& offset)
7905 ->
decltype(from_stream(std::declval<std::basic_istream<CharT>&>(), format,
7906 tp, std::declval<std::basic_string<CharT>*>(), &offset),
7907 parse_manip<Parsable, CharT>{format, tp,
nullptr, &offset})
7909 return {format, tp,
nullptr, &offset};
7912template <
class Parsable,
class CharT,
class Traits,
class Alloc>
7915parse(
const CharT* format, Parsable& tp,
7916 std::basic_string<CharT, Traits, Alloc>& abbrev, std::chrono::minutes& offset)
7917 ->
decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(), format,
7918 tp, &abbrev, &offset),
7919 parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, &abbrev, &offset})
7921 return {format, tp, &abbrev, &offset};
7926template <
class CharT,
class Traits,
class Rep,
class Period>
7928std::basic_ostream<CharT, Traits>&
7929operator<<(std::basic_ostream<CharT, Traits>& os,
7930 const std::chrono::duration<Rep, Period>& d)
7932 return os << detail::make_string<CharT, Traits>::from(d.count()) +
7933 detail::get_units<CharT>(
typename Period::type{});
7939# pragma warning(pop)
7943# pragma GCC diagnostic pop
bool operator==(const DataObjectReference &ldor, const DataObjectReference &rdor)
Title is not part of the real identifier of a dataobject. This is just a hint.
Definition: DataObjectReference.h:231