2 //===---------------------------- chrono ----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_CHRONO
12 #define _LIBCPP_CHRONO
22 template <class ToDuration, class Rep, class Period>
25 duration_cast(const duration<Rep, Period>& fd);
27 template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {};
29 template <class Rep> inline constexpr bool treat_as_floating_point_v
30 = treat_as_floating_point<Rep>::value; // C++17
33 struct duration_values
36 static constexpr Rep zero(); // noexcept in C++20
37 static constexpr Rep max(); // noexcept in C++20
38 static constexpr Rep min(); // noexcept in C++20
43 template <class Rep, class Period = ratio<1>>
46 static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration");
47 static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio");
48 static_assert(Period::num > 0, "duration period must be positive");
51 typedef typename _Period::type period;
53 constexpr duration() = default;
55 constexpr explicit duration(const Rep2& r,
58 is_convertible<Rep2, rep>::value &&
59 (treat_as_floating_point<rep>::value ||
60 !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value)
64 template <class Rep2, class Period2>
65 constexpr duration(const duration<Rep2, Period2>& d,
68 treat_as_floating_point<rep>::value ||
69 ratio_divide<Period2, period>::type::den == 1
74 constexpr rep count() const;
78 constexpr common_type<duration>::type operator+() const;
79 constexpr common_type<duration>::type operator-() const;
80 constexpr duration& operator++(); // constexpr in C++17
81 constexpr duration operator++(int); // constexpr in C++17
82 constexpr duration& operator--(); // constexpr in C++17
83 constexpr duration operator--(int); // constexpr in C++17
85 constexpr duration& operator+=(const duration& d); // constexpr in C++17
86 constexpr duration& operator-=(const duration& d); // constexpr in C++17
88 duration& operator*=(const rep& rhs); // constexpr in C++17
89 duration& operator/=(const rep& rhs); // constexpr in C++17
90 duration& operator%=(const rep& rhs); // constexpr in C++17
91 duration& operator%=(const duration& rhs); // constexpr in C++17
95 static constexpr duration zero(); // noexcept in C++20
96 static constexpr duration min(); // noexcept in C++20
97 static constexpr duration max(); // noexcept in C++20
100 typedef duration<long long, nano> nanoseconds;
101 typedef duration<long long, micro> microseconds;
102 typedef duration<long long, milli> milliseconds;
103 typedef duration<long long > seconds;
104 typedef duration< long, ratio< 60> > minutes;
105 typedef duration< long, ratio<3600> > hours;
107 template <class Clock, class Duration = typename Clock::duration>
112 typedef Duration duration;
113 typedef typename duration::rep rep;
114 typedef typename duration::period period;
116 duration d_; // exposition only
119 time_point(); // has value "epoch" // constexpr in C++14
120 explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14
123 template <class Duration2>
124 time_point(const time_point<clock, Duration2>& t); // constexpr in C++14
128 duration time_since_epoch() const; // constexpr in C++14
132 time_point& operator+=(const duration& d); // constexpr in C++17
133 time_point& operator-=(const duration& d); // constexpr in C++17
137 static constexpr time_point min(); // noexcept in C++20
138 static constexpr time_point max(); // noexcept in C++20
143 // common_type traits
144 template <class Rep1, class Period1, class Rep2, class Period2>
145 struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>;
147 template <class Clock, class Duration1, class Duration2>
148 struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>;
153 template<class T> struct is_clock; // C++20
154 template<class T> inline constexpr bool is_clock_v = is_clock<T>::value; // C++20
157 // duration arithmetic
158 template <class Rep1, class Period1, class Rep2, class Period2>
160 typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
161 operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
162 template <class Rep1, class Period1, class Rep2, class Period2>
164 typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
165 operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
166 template <class Rep1, class Period, class Rep2>
168 duration<typename common_type<Rep1, Rep2>::type, Period>
169 operator*(const duration<Rep1, Period>& d, const Rep2& s);
170 template <class Rep1, class Period, class Rep2>
172 duration<typename common_type<Rep1, Rep2>::type, Period>
173 operator*(const Rep1& s, const duration<Rep2, Period>& d);
174 template <class Rep1, class Period, class Rep2>
176 duration<typename common_type<Rep1, Rep2>::type, Period>
177 operator/(const duration<Rep1, Period>& d, const Rep2& s);
178 template <class Rep1, class Period1, class Rep2, class Period2>
180 typename common_type<Rep1, Rep2>::type
181 operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
183 // duration comparisons
184 template <class Rep1, class Period1, class Rep2, class Period2>
186 bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
187 template <class Rep1, class Period1, class Rep2, class Period2>
189 bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
190 template <class Rep1, class Period1, class Rep2, class Period2>
192 bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
193 template <class Rep1, class Period1, class Rep2, class Period2>
195 bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
196 template <class Rep1, class Period1, class Rep2, class Period2>
198 bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
199 template <class Rep1, class Period1, class Rep2, class Period2>
201 bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
204 template <class ToDuration, class Rep, class Period>
205 ToDuration duration_cast(const duration<Rep, Period>& d);
207 template <class ToDuration, class Rep, class Period>
208 constexpr ToDuration floor(const duration<Rep, Period>& d); // C++17
209 template <class ToDuration, class Rep, class Period>
210 constexpr ToDuration ceil(const duration<Rep, Period>& d); // C++17
211 template <class ToDuration, class Rep, class Period>
212 constexpr ToDuration round(const duration<Rep, Period>& d); // C++17
214 // duration I/O is elsewhere
216 // time_point arithmetic (all constexpr in C++14)
217 template <class Clock, class Duration1, class Rep2, class Period2>
218 time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
219 operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
220 template <class Rep1, class Period1, class Clock, class Duration2>
221 time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
222 operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
223 template <class Clock, class Duration1, class Rep2, class Period2>
224 time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
225 operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
226 template <class Clock, class Duration1, class Duration2>
227 typename common_type<Duration1, Duration2>::type
228 operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
230 // time_point comparisons (all constexpr in C++14)
231 template <class Clock, class Duration1, class Duration2>
232 bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
233 template <class Clock, class Duration1, class Duration2>
234 bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
235 template <class Clock, class Duration1, class Duration2>
236 bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
237 template <class Clock, class Duration1, class Duration2>
238 bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
239 template <class Clock, class Duration1, class Duration2>
240 bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
241 template <class Clock, class Duration1, class Duration2>
242 bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
244 // time_point_cast (constexpr in C++14)
246 template <class ToDuration, class Clock, class Duration>
247 time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
249 template <class ToDuration, class Clock, class Duration>
250 constexpr time_point<Clock, ToDuration>
251 floor(const time_point<Clock, Duration>& tp); // C++17
253 template <class ToDuration, class Clock, class Duration>
254 constexpr time_point<Clock, ToDuration>
255 ceil(const time_point<Clock, Duration>& tp); // C++17
257 template <class ToDuration, class Clock, class Duration>
258 constexpr time_point<Clock, ToDuration>
259 round(const time_point<Clock, Duration>& tp); // C++17
261 template <class Rep, class Period>
262 constexpr duration<Rep, Period> abs(duration<Rep, Period> d); // C++17
269 typedef microseconds duration;
270 typedef duration::rep rep;
271 typedef duration::period period;
272 typedef chrono::time_point<system_clock> time_point;
273 static const bool is_steady = false; // constexpr in C++14
275 static time_point now() noexcept;
276 static time_t to_time_t (const time_point& __t) noexcept;
277 static time_point from_time_t(time_t __t) noexcept;
280 template <class Duration>
281 using sys_time = time_point<system_clock, Duration>; // C++20
282 using sys_seconds = sys_time<seconds>; // C++20
283 using sys_days = sys_time<days>; // C++20
285 class utc_clock; // C++20
287 template <class Duration>
288 using utc_time = time_point<utc_clock, Duration>; // C++20
289 using utc_seconds = utc_time<seconds>; // C++20
291 class tai_clock; // C++20
293 template <class Duration>
294 using tai_time = time_point<tai_clock, Duration>; // C++20
295 using tai_seconds = tai_time<seconds>; // C++20
297 class file_clock; // C++20
299 template<class Duration>
300 using file_time = time_point<file_clock, Duration>; // C++20
305 typedef nanoseconds duration;
306 typedef duration::rep rep;
307 typedef duration::period period;
308 typedef chrono::time_point<steady_clock, duration> time_point;
309 static const bool is_steady = true; // constexpr in C++14
311 static time_point now() noexcept;
314 typedef steady_clock high_resolution_clock;
316 // 25.7.8, local time // C++20
318 template<class Duration>
319 using local_time = time_point<local_t, Duration>;
320 using local_seconds = local_time<seconds>;
321 using local_days = local_time<days>;
323 // 25.7.9, time_point conversions template<class DestClock, class SourceClock> // C++20
324 struct clock_time_conversion;
326 template<class DestClock, class SourceClock, class Duration>
327 auto clock_cast(const time_point<SourceClock, Duration>& t);
329 // 25.8.2, class last_spec // C++20
332 // 25.8.3, class day // C++20
335 constexpr bool operator==(const day& x, const day& y) noexcept;
336 constexpr bool operator!=(const day& x, const day& y) noexcept;
337 constexpr bool operator< (const day& x, const day& y) noexcept;
338 constexpr bool operator> (const day& x, const day& y) noexcept;
339 constexpr bool operator<=(const day& x, const day& y) noexcept;
340 constexpr bool operator>=(const day& x, const day& y) noexcept;
341 constexpr day operator+(const day& x, const days& y) noexcept;
342 constexpr day operator+(const days& x, const day& y) noexcept;
343 constexpr day operator-(const day& x, const days& y) noexcept;
344 constexpr days operator-(const day& x, const day& y) noexcept;
346 // 25.8.4, class month // C++20
348 constexpr bool operator==(const month& x, const month& y) noexcept;
349 constexpr bool operator!=(const month& x, const month& y) noexcept;
350 constexpr bool operator< (const month& x, const month& y) noexcept;
351 constexpr bool operator> (const month& x, const month& y) noexcept;
352 constexpr bool operator<=(const month& x, const month& y) noexcept;
353 constexpr bool operator>=(const month& x, const month& y) noexcept;
354 constexpr month operator+(const month& x, const months& y) noexcept;
355 constexpr month operator+(const months& x, const month& y) noexcept;
356 constexpr month operator-(const month& x, const months& y) noexcept;
357 constexpr months operator-(const month& x, const month& y) noexcept;
359 // 25.8.5, class year // C++20
361 constexpr bool operator==(const year& x, const year& y) noexcept;
362 constexpr bool operator!=(const year& x, const year& y) noexcept;
363 constexpr bool operator< (const year& x, const year& y) noexcept;
364 constexpr bool operator> (const year& x, const year& y) noexcept;
365 constexpr bool operator<=(const year& x, const year& y) noexcept;
366 constexpr bool operator>=(const year& x, const year& y) noexcept;
367 constexpr year operator+(const year& x, const years& y) noexcept;
368 constexpr year operator+(const years& x, const year& y) noexcept;
369 constexpr year operator-(const year& x, const years& y) noexcept;
370 constexpr years operator-(const year& x, const year& y) noexcept;
372 // 25.8.6, class weekday // C++20
375 constexpr bool operator==(const weekday& x, const weekday& y) noexcept;
376 constexpr bool operator!=(const weekday& x, const weekday& y) noexcept;
377 constexpr weekday operator+(const weekday& x, const days& y) noexcept;
378 constexpr weekday operator+(const days& x, const weekday& y) noexcept;
379 constexpr weekday operator-(const weekday& x, const days& y) noexcept;
380 constexpr days operator-(const weekday& x, const weekday& y) noexcept;
382 // 25.8.7, class weekday_indexed // C++20
384 class weekday_indexed;
385 constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept;
386 constexpr bool operator!=(const weekday_indexed& x, const weekday_indexed& y) noexcept;
388 // 25.8.8, class weekday_last // C++20
391 constexpr bool operator==(const weekday_last& x, const weekday_last& y) noexcept;
392 constexpr bool operator!=(const weekday_last& x, const weekday_last& y) noexcept;
394 // 25.8.9, class month_day // C++20
397 constexpr bool operator==(const month_day& x, const month_day& y) noexcept;
398 constexpr bool operator!=(const month_day& x, const month_day& y) noexcept;
399 constexpr bool operator< (const month_day& x, const month_day& y) noexcept;
400 constexpr bool operator> (const month_day& x, const month_day& y) noexcept;
401 constexpr bool operator<=(const month_day& x, const month_day& y) noexcept;
402 constexpr bool operator>=(const month_day& x, const month_day& y) noexcept;
405 // 25.8.10, class month_day_last // C++20
406 class month_day_last;
408 constexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept;
409 constexpr bool operator!=(const month_day_last& x, const month_day_last& y) noexcept;
410 constexpr bool operator< (const month_day_last& x, const month_day_last& y) noexcept;
411 constexpr bool operator> (const month_day_last& x, const month_day_last& y) noexcept;
412 constexpr bool operator<=(const month_day_last& x, const month_day_last& y) noexcept;
413 constexpr bool operator>=(const month_day_last& x, const month_day_last& y) noexcept;
415 // 25.8.11, class month_weekday // C++20
418 constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept;
419 constexpr bool operator!=(const month_weekday& x, const month_weekday& y) noexcept;
421 // 25.8.12, class month_weekday_last // C++20
422 class month_weekday_last;
424 constexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept;
425 constexpr bool operator!=(const month_weekday_last& x, const month_weekday_last& y) noexcept;
428 // 25.8.13, class year_month // C++20
431 constexpr bool operator==(const year_month& x, const year_month& y) noexcept;
432 constexpr bool operator!=(const year_month& x, const year_month& y) noexcept;
433 constexpr bool operator< (const year_month& x, const year_month& y) noexcept;
434 constexpr bool operator> (const year_month& x, const year_month& y) noexcept;
435 constexpr bool operator<=(const year_month& x, const year_month& y) noexcept;
436 constexpr bool operator>=(const year_month& x, const year_month& y) noexcept;
438 constexpr year_month operator+(const year_month& ym, const months& dm) noexcept;
439 constexpr year_month operator+(const months& dm, const year_month& ym) noexcept;
440 constexpr year_month operator-(const year_month& ym, const months& dm) noexcept;
441 constexpr months operator-(const year_month& x, const year_month& y) noexcept;
442 constexpr year_month operator+(const year_month& ym, const years& dy) noexcept;
443 constexpr year_month operator+(const years& dy, const year_month& ym) noexcept;
444 constexpr year_month operator-(const year_month& ym, const years& dy) noexcept;
446 // 25.8.14, class year_month_day class // C++20
449 constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept;
450 constexpr bool operator!=(const year_month_day& x, const year_month_day& y) noexcept;
451 constexpr bool operator< (const year_month_day& x, const year_month_day& y) noexcept;
452 constexpr bool operator> (const year_month_day& x, const year_month_day& y) noexcept;
453 constexpr bool operator<=(const year_month_day& x, const year_month_day& y) noexcept;
454 constexpr bool operator>=(const year_month_day& x, const year_month_day& y) noexcept;
456 constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept;
457 constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept;
458 constexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept;
459 constexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept;
460 constexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept;
461 constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept;
464 // 25.8.15, class year_month_day_last // C++20
465 class year_month_day_last;
467 constexpr bool operator==(const year_month_day_last& x,
468 const year_month_day_last& y) noexcept;
469 constexpr bool operator!=(const year_month_day_last& x,
470 const year_month_day_last& y) noexcept;
471 constexpr bool operator< (const year_month_day_last& x,
472 const year_month_day_last& y) noexcept;
473 constexpr bool operator> (const year_month_day_last& x,
474 const year_month_day_last& y) noexcept;
475 constexpr bool operator<=(const year_month_day_last& x,
476 const year_month_day_last& y) noexcept;
477 constexpr bool operator>=(const year_month_day_last& x,
478 const year_month_day_last& y) noexcept;
480 constexpr year_month_day_last
481 operator+(const year_month_day_last& ymdl, const months& dm) noexcept;
482 constexpr year_month_day_last
483 operator+(const months& dm, const year_month_day_last& ymdl) noexcept;
484 constexpr year_month_day_last
485 operator+(const year_month_day_last& ymdl, const years& dy) noexcept;
486 constexpr year_month_day_last
487 operator+(const years& dy, const year_month_day_last& ymdl) noexcept;
488 constexpr year_month_day_last
489 operator-(const year_month_day_last& ymdl, const months& dm) noexcept;
490 constexpr year_month_day_last
491 operator-(const year_month_day_last& ymdl, const years& dy) noexcept;
493 // 25.8.16, class year_month_weekday // C++20
494 class year_month_weekday;
496 constexpr bool operator==(const year_month_weekday& x,
497 const year_month_weekday& y) noexcept;
498 constexpr bool operator!=(const year_month_weekday& x,
499 const year_month_weekday& y) noexcept;
501 constexpr year_month_weekday
502 operator+(const year_month_weekday& ymwd, const months& dm) noexcept;
503 constexpr year_month_weekday
504 operator+(const months& dm, const year_month_weekday& ymwd) noexcept;
505 constexpr year_month_weekday
506 operator+(const year_month_weekday& ymwd, const years& dy) noexcept;
507 constexpr year_month_weekday
508 operator+(const years& dy, const year_month_weekday& ymwd) noexcept;
509 constexpr year_month_weekday
510 operator-(const year_month_weekday& ymwd, const months& dm) noexcept;
511 constexpr year_month_weekday
512 operator-(const year_month_weekday& ymwd, const years& dy) noexcept;
514 // 25.8.17, class year_month_weekday_last // C++20
515 class year_month_weekday_last;
517 constexpr bool operator==(const year_month_weekday_last& x,
518 const year_month_weekday_last& y) noexcept;
519 constexpr bool operator!=(const year_month_weekday_last& x,
520 const year_month_weekday_last& y) noexcept;
521 constexpr year_month_weekday_last
522 operator+(const year_month_weekday_last& ymwdl, const months& dm) noexcept;
523 constexpr year_month_weekday_last
524 operator+(const months& dm, const year_month_weekday_last& ymwdl) noexcept;
525 constexpr year_month_weekday_last
526 operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept;
527 constexpr year_month_weekday_last
528 operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept;
529 constexpr year_month_weekday_last
530 operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept;
531 constexpr year_month_weekday_last
532 operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept;
534 // 25.8.18, civil calendar conventional syntax operators // C++20
536 operator/(const year& y, const month& m) noexcept;
538 operator/(const year& y, int m) noexcept;
540 operator/(const month& m, const day& d) noexcept;
542 operator/(const month& m, int d) noexcept;
544 operator/(int m, const day& d) noexcept;
546 operator/(const day& d, const month& m) noexcept;
548 operator/(const day& d, int m) noexcept;
549 constexpr month_day_last
550 operator/(const month& m, last_spec) noexcept;
551 constexpr month_day_last
552 operator/(int m, last_spec) noexcept;
553 constexpr month_day_last
554 operator/(last_spec, const month& m) noexcept;
555 constexpr month_day_last
556 operator/(last_spec, int m) noexcept;
557 constexpr month_weekday
558 operator/(const month& m, const weekday_indexed& wdi) noexcept;
559 constexpr month_weekday
560 operator/(int m, const weekday_indexed& wdi) noexcept;
561 constexpr month_weekday
562 operator/(const weekday_indexed& wdi, const month& m) noexcept;
563 constexpr month_weekday
564 operator/(const weekday_indexed& wdi, int m) noexcept;
565 constexpr month_weekday_last
566 operator/(const month& m, const weekday_last& wdl) noexcept;
567 constexpr month_weekday_last
568 operator/(int m, const weekday_last& wdl) noexcept;
569 constexpr month_weekday_last
570 operator/(const weekday_last& wdl, const month& m) noexcept;
571 constexpr month_weekday_last
572 operator/(const weekday_last& wdl, int m) noexcept;
573 constexpr year_month_day
574 operator/(const year_month& ym, const day& d) noexcept;
575 constexpr year_month_day
576 operator/(const year_month& ym, int d) noexcept;
577 constexpr year_month_day
578 operator/(const year& y, const month_day& md) noexcept;
579 constexpr year_month_day
580 operator/(int y, const month_day& md) noexcept;
581 constexpr year_month_day
582 operator/(const month_day& md, const year& y) noexcept;
583 constexpr year_month_day
584 operator/(const month_day& md, int y) noexcept;
585 constexpr year_month_day_last
586 operator/(const year_month& ym, last_spec) noexcept;
587 constexpr year_month_day_last
588 operator/(const year& y, const month_day_last& mdl) noexcept;
589 constexpr year_month_day_last
590 operator/(int y, const month_day_last& mdl) noexcept;
591 constexpr year_month_day_last
592 operator/(const month_day_last& mdl, const year& y) noexcept;
593 constexpr year_month_day_last
594 operator/(const month_day_last& mdl, int y) noexcept;
595 constexpr year_month_weekday
596 operator/(const year_month& ym, const weekday_indexed& wdi) noexcept;
597 constexpr year_month_weekday
598 operator/(const year& y, const month_weekday& mwd) noexcept;
599 constexpr year_month_weekday
600 operator/(int y, const month_weekday& mwd) noexcept;
601 constexpr year_month_weekday
602 operator/(const month_weekday& mwd, const year& y) noexcept;
603 constexpr year_month_weekday
604 operator/(const month_weekday& mwd, int y) noexcept;
605 constexpr year_month_weekday_last
606 operator/(const year_month& ym, const weekday_last& wdl) noexcept;
607 constexpr year_month_weekday_last
608 operator/(const year& y, const month_weekday_last& mwdl) noexcept;
609 constexpr year_month_weekday_last
610 operator/(int y, const month_weekday_last& mwdl) noexcept;
611 constexpr year_month_weekday_last
612 operator/(const month_weekday_last& mwdl, const year& y) noexcept;
613 constexpr year_month_weekday_last
614 operator/(const month_weekday_last& mwdl, int y) noexcept;
616 // 25.9, class template time_of_day // C++20
617 template<class Duration> class time_of_day;
619 template<> class time_of_day<hours>;
620 template<> class time_of_day<minutes>;
621 template<> class time_of_day<seconds>;
622 template<class Rep, class Period> class time_of_day<duration<Rep, Period>>;
624 // 25.10.2, time zone database // C++20
628 // 25.10.2.3, time zone database access // C++20
629 const tzdb& get_tzdb();
630 tzdb_list& get_tzdb_list();
631 const time_zone* locate_zone(string_view tz_name);
632 const time_zone* current_zone();
634 // 25.10.2.4, remote time zone database support // C++20
635 const tzdb& reload_tzdb();
636 string remote_version();
638 // 25.10.3, exception classes // C++20
639 class nonexistent_local_time;
640 class ambiguous_local_time;
642 // 25.10.4, information classes // C++20
646 // 25.10.5, class time_zone // C++20
647 enum class choose {earliest, latest};
649 bool operator==(const time_zone& x, const time_zone& y) noexcept;
650 bool operator!=(const time_zone& x, const time_zone& y) noexcept;
651 bool operator<(const time_zone& x, const time_zone& y) noexcept;
652 bool operator>(const time_zone& x, const time_zone& y) noexcept;
653 bool operator<=(const time_zone& x, const time_zone& y) noexcept;
654 bool operator>=(const time_zone& x, const time_zone& y) noexcept;
656 // 25.10.6, class template zoned_traits // C++20
657 template<class T> struct zoned_traits;
659 // 25.10.7, class template zoned_time // C++20
660 template<class Duration, class TimeZonePtr = const time_zone*> class zoned_time;
661 using zoned_seconds = zoned_time<seconds>;
663 template<class Duration1, class Duration2, class TimeZonePtr>
664 bool operator==(const zoned_time<Duration1, TimeZonePtr>& x,
665 const zoned_time<Duration2, TimeZonePtr>& y);
666 template<class Duration1, class Duration2, class TimeZonePtr>
667 bool operator!=(const zoned_time<Duration1, TimeZonePtr>& x,
668 const zoned_time<Duration2, TimeZonePtr>& y);
670 // 25.10.8, leap second support // C++20
673 bool operator==(const leap& x, const leap& y);
674 bool operator!=(const leap& x, const leap& y);
675 bool operator< (const leap& x, const leap& y);
676 bool operator> (const leap& x, const leap& y);
677 bool operator<=(const leap& x, const leap& y);
678 bool operator>=(const leap& x, const leap& y);
679 template<class Duration>
680 bool operator==(const leap& x, const sys_time<Duration>& y);
681 template<class Duration>
682 bool operator==(const sys_time<Duration>& x, const leap& y);
683 template<class Duration>
684 bool operator!=(const leap& x, const sys_time<Duration>& y);
685 template<class Duration>
686 bool operator!=(const sys_time<Duration>& x, const leap& y);
687 template<class Duration>
688 bool operator< (const leap& x, const sys_time<Duration>& y);
689 template<class Duration>
690 bool operator< (const sys_time<Duration>& x, const leap& y);
691 template<class Duration>
692 bool operator> (const leap& x, const sys_time<Duration>& y);
693 template<class Duration>
694 bool operator> (const sys_time<Duration>& x, const leap& y);
695 template<class Duration>
696 bool operator<=(const leap& x, const sys_time<Duration>& y);
697 template<class Duration>
698 bool operator<=(const sys_time<Duration>& x, const leap& y);
699 template<class Duration>
700 bool operator>=(const leap& x, const sys_time<Duration>& y);
701 template<class Duration>
702 bool operator>=(const sys_time<Duration>& x, const leap& y);
704 // 25.10.9, class link // C++20
706 bool operator==(const link& x, const link& y);
707 bool operator!=(const link& x, const link& y);
708 bool operator< (const link& x, const link& y);
709 bool operator> (const link& x, const link& y);
710 bool operator<=(const link& x, const link& y);
711 bool operator>=(const link& x, const link& y);
713 // 25.11, formatting // C++20
714 template<class charT, class Streamable>
716 format(const charT* fmt, const Streamable& s);
718 template<class charT, class Streamable>
720 format(const locale& loc, const charT* fmt, const Streamable& s);
722 template<class charT, class traits, class Alloc, class Streamable>
723 basic_string<charT, traits, Alloc>
724 format(const basic_string<charT, traits, Alloc>& fmt, const Streamable& s);
726 template<class charT, class traits, class Alloc, class Streamable>
727 basic_string<charT, traits, Alloc>
728 format(const locale& loc, const basic_string<charT, traits, Alloc>& fmt,
729 const Streamable& s);
731 // 25.12, parsing // C++20
732 template<class charT, class traits, class Alloc, class Parsable>
734 parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp);
736 template<class charT, class traits, class Alloc, class Parsable>
738 parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
739 basic_string<charT, traits, Alloc>& abbrev);
741 template<class charT, class traits, class Alloc, class Parsable>
743 parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
746 template<class charT, class traits, class Alloc, class Parsable>
748 parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
749 basic_string<charT, traits, Alloc>& abbrev, minutes& offset);
751 // calendrical constants
752 inline constexpr last_spec last{}; // C++20
753 inline constexpr chrono::weekday Sunday{0}; // C++20
754 inline constexpr chrono::weekday Monday{1}; // C++20
755 inline constexpr chrono::weekday Tuesday{2}; // C++20
756 inline constexpr chrono::weekday Wednesday{3}; // C++20
757 inline constexpr chrono::weekday Thursday{4}; // C++20
758 inline constexpr chrono::weekday Friday{5}; // C++20
759 inline constexpr chrono::weekday Saturday{6}; // C++20
761 inline constexpr chrono::month January{1}; // C++20
762 inline constexpr chrono::month February{2}; // C++20
763 inline constexpr chrono::month March{3}; // C++20
764 inline constexpr chrono::month April{4}; // C++20
765 inline constexpr chrono::month May{5}; // C++20
766 inline constexpr chrono::month June{6}; // C++20
767 inline constexpr chrono::month July{7}; // C++20
768 inline constexpr chrono::month August{8}; // C++20
769 inline constexpr chrono::month September{9}; // C++20
770 inline constexpr chrono::month October{10}; // C++20
771 inline constexpr chrono::month November{11}; // C++20
772 inline constexpr chrono::month December{12}; // C++20
775 inline namespace literals {
776 inline namespace chrono_literals {
777 constexpr chrono::hours operator ""h(unsigned long long); // C++14
778 constexpr chrono::duration<unspecified , ratio<3600,1>> operator ""h(long double); // C++14
779 constexpr chrono::minutes operator ""min(unsigned long long); // C++14
780 constexpr chrono::duration<unspecified , ratio<60,1>> operator ""min(long double); // C++14
781 constexpr chrono::seconds operator ""s(unsigned long long); // C++14
782 constexpr chrono::duration<unspecified > operator ""s(long double); // C++14
783 constexpr chrono::milliseconds operator ""ms(unsigned long long); // C++14
784 constexpr chrono::duration<unspecified , milli> operator ""ms(long double); // C++14
785 constexpr chrono::microseconds operator ""us(unsigned long long); // C++14
786 constexpr chrono::duration<unspecified , micro> operator ""us(long double); // C++14
787 constexpr chrono::nanoseconds operator ""ns(unsigned long long); // C++14
788 constexpr chrono::duration<unspecified , nano> operator ""ns(long double); // C++14
789 constexpr chrono::day operator ""d(unsigned long long d) noexcept; // C++20
790 constexpr chrono::year operator ""y(unsigned long long y) noexcept; // C++20
799 #include <type_traits>
804 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
805 #pragma GCC system_header
809 #include <__undef_macros>
811 #ifndef _LIBCPP_CXX03_LANG
812 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
813 struct _FilesystemClock;
814 _LIBCPP_END_NAMESPACE_FILESYSTEM
815 #endif // !_LIBCPP_CXX03_LANG
817 _LIBCPP_BEGIN_NAMESPACE_STD
822 template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TEMPLATE_VIS duration;
825 struct __is_duration : false_type {};
827 template <class _Rep, class _Period>
828 struct __is_duration<duration<_Rep, _Period> > : true_type {};
830 template <class _Rep, class _Period>
831 struct __is_duration<const duration<_Rep, _Period> > : true_type {};
833 template <class _Rep, class _Period>
834 struct __is_duration<volatile duration<_Rep, _Period> > : true_type {};
836 template <class _Rep, class _Period>
837 struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
841 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
842 struct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>,
843 chrono::duration<_Rep2, _Period2> >
845 typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
846 typename __ratio_gcd<_Period1, _Period2>::type> type;
853 template <class _FromDuration, class _ToDuration,
854 class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
855 bool = _Period::num == 1,
856 bool = _Period::den == 1>
857 struct __duration_cast;
859 template <class _FromDuration, class _ToDuration, class _Period>
860 struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
862 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
863 _ToDuration operator()(const _FromDuration& __fd) const
865 return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
869 template <class _FromDuration, class _ToDuration, class _Period>
870 struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
872 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
873 _ToDuration operator()(const _FromDuration& __fd) const
875 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
876 return _ToDuration(static_cast<typename _ToDuration::rep>(
877 static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
881 template <class _FromDuration, class _ToDuration, class _Period>
882 struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
884 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
885 _ToDuration operator()(const _FromDuration& __fd) const
887 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
888 return _ToDuration(static_cast<typename _ToDuration::rep>(
889 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
893 template <class _FromDuration, class _ToDuration, class _Period>
894 struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
896 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
897 _ToDuration operator()(const _FromDuration& __fd) const
899 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
900 return _ToDuration(static_cast<typename _ToDuration::rep>(
901 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
902 / static_cast<_Ct>(_Period::den)));
906 template <class _ToDuration, class _Rep, class _Period>
907 inline _LIBCPP_INLINE_VISIBILITY
911 __is_duration<_ToDuration>::value,
914 duration_cast(const duration<_Rep, _Period>& __fd)
916 return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
919 template <class _Rep>
920 struct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {};
922 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
923 template <class _Rep>
924 _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool treat_as_floating_point_v
925 = treat_as_floating_point<_Rep>::value;
928 template <class _Rep>
929 struct _LIBCPP_TEMPLATE_VIS duration_values
932 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT {return _Rep(0);}
933 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() _NOEXCEPT {return numeric_limits<_Rep>::max();}
934 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() _NOEXCEPT {return numeric_limits<_Rep>::lowest();}
937 #if _LIBCPP_STD_VER > 14
938 template <class _ToDuration, class _Rep, class _Period>
939 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
942 __is_duration<_ToDuration>::value,
945 floor(const duration<_Rep, _Period>& __d)
947 _ToDuration __t = duration_cast<_ToDuration>(__d);
949 __t = __t - _ToDuration{1};
953 template <class _ToDuration, class _Rep, class _Period>
954 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
957 __is_duration<_ToDuration>::value,
960 ceil(const duration<_Rep, _Period>& __d)
962 _ToDuration __t = duration_cast<_ToDuration>(__d);
964 __t = __t + _ToDuration{1};
968 template <class _ToDuration, class _Rep, class _Period>
969 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
972 __is_duration<_ToDuration>::value,
975 round(const duration<_Rep, _Period>& __d)
977 _ToDuration __lower = floor<_ToDuration>(__d);
978 _ToDuration __upper = __lower + _ToDuration{1};
979 auto __lowerDiff = __d - __lower;
980 auto __upperDiff = __upper - __d;
981 if (__lowerDiff < __upperDiff)
983 if (__lowerDiff > __upperDiff)
985 return __lower.count() & 1 ? __upper : __lower;
991 template <class _Rep, class _Period>
992 class _LIBCPP_TEMPLATE_VIS duration
994 static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
995 static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
996 static_assert(_Period::num > 0, "duration period must be positive");
998 template <class _R1, class _R2>
1002 static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
1003 static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
1004 static const intmax_t __n1 = _R1::num / __gcd_n1_n2;
1005 static const intmax_t __d1 = _R1::den / __gcd_d1_d2;
1006 static const intmax_t __n2 = _R2::num / __gcd_n1_n2;
1007 static const intmax_t __d2 = _R2::den / __gcd_d1_d2;
1008 static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1);
1010 template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
1011 struct __mul // __overflow == false
1013 static const intmax_t value = _Xp * _Yp;
1016 template <intmax_t _Xp, intmax_t _Yp>
1017 struct __mul<_Xp, _Yp, true>
1019 static const intmax_t value = 1;
1023 static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
1024 typedef ratio<__mul<__n1, __d2, !value>::value,
1025 __mul<__n2, __d1, !value>::value> type;
1030 typedef typename _Period::type period;
1035 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1036 #ifndef _LIBCPP_CXX03_LANG
1037 duration() = default;
1042 template <class _Rep2>
1043 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1044 explicit duration(const _Rep2& __r,
1047 is_convertible<_Rep2, rep>::value &&
1048 (treat_as_floating_point<rep>::value ||
1049 !treat_as_floating_point<_Rep2>::value)
1054 template <class _Rep2, class _Period2>
1055 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1056 duration(const duration<_Rep2, _Period2>& __d,
1059 __no_overflow<_Period2, period>::value && (
1060 treat_as_floating_point<rep>::value ||
1061 (__no_overflow<_Period2, period>::type::den == 1 &&
1062 !treat_as_floating_point<_Rep2>::value))
1064 : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {}
1068 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
1072 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);}
1073 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);}
1074 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++() {++__rep_; return *this;}
1075 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator++(int) {return duration(__rep_++);}
1076 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--() {--__rep_; return *this;}
1077 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator--(int) {return duration(__rep_--);}
1079 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
1080 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
1082 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
1083 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
1084 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
1085 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
1089 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() _NOEXCEPT {return duration(duration_values<rep>::zero());}
1090 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() _NOEXCEPT {return duration(duration_values<rep>::min());}
1091 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() _NOEXCEPT {return duration(duration_values<rep>::max());}
1094 typedef duration<long long, nano> nanoseconds;
1095 typedef duration<long long, micro> microseconds;
1096 typedef duration<long long, milli> milliseconds;
1097 typedef duration<long long > seconds;
1098 typedef duration< long, ratio< 60> > minutes;
1099 typedef duration< long, ratio<3600> > hours;
1100 #if _LIBCPP_STD_VER > 17
1101 typedef duration< int, ratio_multiply<ratio<24>, hours::period>> days;
1102 typedef duration< int, ratio_multiply<ratio<7>, days::period>> weeks;
1103 typedef duration< int, ratio_multiply<ratio<146097, 400>, days::period>> years;
1104 typedef duration< int, ratio_divide<years::period, ratio<12>>> months;
1108 template <class _LhsDuration, class _RhsDuration>
1109 struct __duration_eq
1111 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1112 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
1114 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
1115 return _Ct(__lhs).count() == _Ct(__rhs).count();
1119 template <class _LhsDuration>
1120 struct __duration_eq<_LhsDuration, _LhsDuration>
1122 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1123 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
1124 {return __lhs.count() == __rhs.count();}
1127 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1128 inline _LIBCPP_INLINE_VISIBILITY
1131 operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1133 return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
1138 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1139 inline _LIBCPP_INLINE_VISIBILITY
1142 operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1144 return !(__lhs == __rhs);
1149 template <class _LhsDuration, class _RhsDuration>
1150 struct __duration_lt
1152 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1153 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
1155 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
1156 return _Ct(__lhs).count() < _Ct(__rhs).count();
1160 template <class _LhsDuration>
1161 struct __duration_lt<_LhsDuration, _LhsDuration>
1163 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1164 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
1165 {return __lhs.count() < __rhs.count();}
1168 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1169 inline _LIBCPP_INLINE_VISIBILITY
1172 operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1174 return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
1179 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1180 inline _LIBCPP_INLINE_VISIBILITY
1183 operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1185 return __rhs < __lhs;
1190 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1191 inline _LIBCPP_INLINE_VISIBILITY
1194 operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1196 return !(__rhs < __lhs);
1201 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1202 inline _LIBCPP_INLINE_VISIBILITY
1205 operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1207 return !(__lhs < __rhs);
1212 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1213 inline _LIBCPP_INLINE_VISIBILITY
1215 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
1216 operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1218 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
1219 return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
1224 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1225 inline _LIBCPP_INLINE_VISIBILITY
1227 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
1228 operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1230 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
1231 return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
1236 template <class _Rep1, class _Period, class _Rep2>
1237 inline _LIBCPP_INLINE_VISIBILITY
1241 is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
1242 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
1244 operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
1246 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
1247 typedef duration<_Cr, _Period> _Cd;
1248 return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
1251 template <class _Rep1, class _Period, class _Rep2>
1252 inline _LIBCPP_INLINE_VISIBILITY
1256 is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
1257 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
1259 operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
1266 template <class _Duration, class _Rep, bool = __is_duration<_Rep>::value>
1267 struct __duration_divide_result
1271 template <class _Duration, class _Rep2,
1272 bool = is_convertible<_Rep2,
1273 typename common_type<typename _Duration::rep, _Rep2>::type>::value>
1274 struct __duration_divide_imp
1278 template <class _Rep1, class _Period, class _Rep2>
1279 struct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true>
1281 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type;
1284 template <class _Rep1, class _Period, class _Rep2>
1285 struct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false>
1286 : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2>
1290 template <class _Rep1, class _Period, class _Rep2>
1291 inline _LIBCPP_INLINE_VISIBILITY
1293 typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
1294 operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
1296 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
1297 typedef duration<_Cr, _Period> _Cd;
1298 return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
1301 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1302 inline _LIBCPP_INLINE_VISIBILITY
1304 typename common_type<_Rep1, _Rep2>::type
1305 operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1307 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
1308 return _Ct(__lhs).count() / _Ct(__rhs).count();
1313 template <class _Rep1, class _Period, class _Rep2>
1314 inline _LIBCPP_INLINE_VISIBILITY
1316 typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
1317 operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
1319 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
1320 typedef duration<_Cr, _Period> _Cd;
1321 return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
1324 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1325 inline _LIBCPP_INLINE_VISIBILITY
1327 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
1328 operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1330 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
1331 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
1332 return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
1335 //////////////////////////////////////////////////////////
1336 ///////////////////// time_point /////////////////////////
1337 //////////////////////////////////////////////////////////
1339 template <class _Clock, class _Duration = typename _Clock::duration>
1340 class _LIBCPP_TEMPLATE_VIS time_point
1342 static_assert(__is_duration<_Duration>::value,
1343 "Second template parameter of time_point must be a std::chrono::duration");
1345 typedef _Clock clock;
1346 typedef _Duration duration;
1347 typedef typename duration::rep rep;
1348 typedef typename duration::period period;
1353 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
1354 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
1357 template <class _Duration2>
1358 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1359 time_point(const time_point<clock, _Duration2>& t,
1362 is_convertible<_Duration2, duration>::value
1364 : __d_(t.time_since_epoch()) {}
1368 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;}
1372 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
1373 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
1377 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() _NOEXCEPT {return time_point(duration::min());}
1378 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() _NOEXCEPT {return time_point(duration::max());}
1383 template <class _Clock, class _Duration1, class _Duration2>
1384 struct _LIBCPP_TEMPLATE_VIS common_type<chrono::time_point<_Clock, _Duration1>,
1385 chrono::time_point<_Clock, _Duration2> >
1387 typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
1392 template <class _ToDuration, class _Clock, class _Duration>
1393 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1394 time_point<_Clock, _ToDuration>
1395 time_point_cast(const time_point<_Clock, _Duration>& __t)
1397 return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
1400 #if _LIBCPP_STD_VER > 14
1401 template <class _ToDuration, class _Clock, class _Duration>
1402 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1405 __is_duration<_ToDuration>::value,
1406 time_point<_Clock, _ToDuration>
1408 floor(const time_point<_Clock, _Duration>& __t)
1410 return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())};
1413 template <class _ToDuration, class _Clock, class _Duration>
1414 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1417 __is_duration<_ToDuration>::value,
1418 time_point<_Clock, _ToDuration>
1420 ceil(const time_point<_Clock, _Duration>& __t)
1422 return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())};
1425 template <class _ToDuration, class _Clock, class _Duration>
1426 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1429 __is_duration<_ToDuration>::value,
1430 time_point<_Clock, _ToDuration>
1432 round(const time_point<_Clock, _Duration>& __t)
1434 return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())};
1437 template <class _Rep, class _Period>
1438 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1441 numeric_limits<_Rep>::is_signed,
1442 duration<_Rep, _Period>
1444 abs(duration<_Rep, _Period> __d)
1446 return __d >= __d.zero() ? __d : -__d;
1452 template <class _Clock, class _Duration1, class _Duration2>
1453 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1455 operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1457 return __lhs.time_since_epoch() == __rhs.time_since_epoch();
1462 template <class _Clock, class _Duration1, class _Duration2>
1463 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1465 operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1467 return !(__lhs == __rhs);
1472 template <class _Clock, class _Duration1, class _Duration2>
1473 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1475 operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1477 return __lhs.time_since_epoch() < __rhs.time_since_epoch();
1482 template <class _Clock, class _Duration1, class _Duration2>
1483 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1485 operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1487 return __rhs < __lhs;
1492 template <class _Clock, class _Duration1, class _Duration2>
1493 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1495 operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1497 return !(__rhs < __lhs);
1502 template <class _Clock, class _Duration1, class _Duration2>
1503 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1505 operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1507 return !(__lhs < __rhs);
1510 // time_point operator+(time_point x, duration y);
1512 template <class _Clock, class _Duration1, class _Rep2, class _Period2>
1513 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1514 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
1515 operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1517 typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
1518 return _Tr (__lhs.time_since_epoch() + __rhs);
1521 // time_point operator+(duration x, time_point y);
1523 template <class _Rep1, class _Period1, class _Clock, class _Duration2>
1524 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1525 time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
1526 operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1528 return __rhs + __lhs;
1531 // time_point operator-(time_point x, duration y);
1533 template <class _Clock, class _Duration1, class _Rep2, class _Period2>
1534 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1535 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
1536 operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1538 typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret;
1539 return _Ret(__lhs.time_since_epoch() -__rhs);
1542 // duration operator-(time_point x, time_point y);
1544 template <class _Clock, class _Duration1, class _Duration2>
1545 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1546 typename common_type<_Duration1, _Duration2>::type
1547 operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1549 return __lhs.time_since_epoch() - __rhs.time_since_epoch();
1552 //////////////////////////////////////////////////////////
1553 /////////////////////// clocks ///////////////////////////
1554 //////////////////////////////////////////////////////////
1556 class _LIBCPP_TYPE_VIS system_clock
1559 typedef microseconds duration;
1560 typedef duration::rep rep;
1561 typedef duration::period period;
1562 typedef chrono::time_point<system_clock> time_point;
1563 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
1565 static time_point now() _NOEXCEPT;
1566 static time_t to_time_t (const time_point& __t) _NOEXCEPT;
1567 static time_point from_time_t(time_t __t) _NOEXCEPT;
1570 #ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
1571 class _LIBCPP_TYPE_VIS steady_clock
1574 typedef nanoseconds duration;
1575 typedef duration::rep rep;
1576 typedef duration::period period;
1577 typedef chrono::time_point<steady_clock, duration> time_point;
1578 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true;
1580 static time_point now() _NOEXCEPT;
1583 typedef steady_clock high_resolution_clock;
1585 typedef system_clock high_resolution_clock;
1588 #if _LIBCPP_STD_VER > 17
1589 // [time.clock.file], type file_clock
1590 using file_clock = _VSTD_FS::_FilesystemClock;
1592 template<class _Duration>
1593 using file_time = time_point<file_clock, _Duration>;
1596 template <class _Duration>
1597 using sys_time = time_point<system_clock, _Duration>;
1598 using sys_seconds = sys_time<seconds>;
1599 using sys_days = sys_time<days>;
1602 template<class Duration>
1603 using local_time = time_point<local_t, Duration>;
1604 using local_seconds = local_time<seconds>;
1605 using local_days = local_time<days>;
1608 struct _LIBCPP_TYPE_VIS last_spec { explicit last_spec() = default; };
1610 class _LIBCPP_TYPE_VIS day {
1615 explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast<unsigned char>(__val)) {}
1616 inline constexpr day& operator++() noexcept { ++__d; return *this; }
1617 inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; }
1618 inline constexpr day& operator--() noexcept { --__d; return *this; }
1619 inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; }
1620 constexpr day& operator+=(const days& __dd) noexcept;
1621 constexpr day& operator-=(const days& __dd) noexcept;
1622 explicit inline constexpr operator unsigned() const noexcept { return __d; }
1623 inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; }
1628 bool operator==(const day& __lhs, const day& __rhs) noexcept
1629 { return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
1632 bool operator!=(const day& __lhs, const day& __rhs) noexcept
1633 { return !(__lhs == __rhs); }
1636 bool operator< (const day& __lhs, const day& __rhs) noexcept
1637 { return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); }
1640 bool operator> (const day& __lhs, const day& __rhs) noexcept
1641 { return __rhs < __lhs; }
1644 bool operator<=(const day& __lhs, const day& __rhs) noexcept
1645 { return !(__rhs < __lhs);}
1648 bool operator>=(const day& __lhs, const day& __rhs) noexcept
1649 { return !(__lhs < __rhs); }
1652 day operator+ (const day& __lhs, const days& __rhs) noexcept
1653 { return day(static_cast<unsigned>(__lhs) + __rhs.count()); }
1656 day operator+ (const days& __lhs, const day& __rhs) noexcept
1657 { return __rhs + __lhs; }
1660 day operator- (const day& __lhs, const days& __rhs) noexcept
1661 { return __lhs + -__rhs; }
1664 days operator-(const day& __lhs, const day& __rhs) noexcept
1665 { return days(static_cast<int>(static_cast<unsigned>(__lhs)) -
1666 static_cast<int>(static_cast<unsigned>(__rhs))); }
1668 inline constexpr day& day::operator+=(const days& __dd) noexcept
1669 { *this = *this + __dd; return *this; }
1671 inline constexpr day& day::operator-=(const days& __dd) noexcept
1672 { *this = *this - __dd; return *this; }
1675 class _LIBCPP_TYPE_VIS month {
1680 explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast<unsigned char>(__val)) {}
1681 inline constexpr month& operator++() noexcept { ++__m; return *this; }
1682 inline constexpr month operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; }
1683 inline constexpr month& operator--() noexcept { --__m; return *this; }
1684 inline constexpr month operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; }
1685 constexpr month& operator+=(const months& __m1) noexcept;
1686 constexpr month& operator-=(const months& __m1) noexcept;
1687 explicit inline constexpr operator unsigned() const noexcept { return __m; }
1688 inline constexpr bool ok() const noexcept { return __m >= 1 && __m <= 12; }
1693 bool operator==(const month& __lhs, const month& __rhs) noexcept
1694 { return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
1697 bool operator!=(const month& __lhs, const month& __rhs) noexcept
1698 { return !(__lhs == __rhs); }
1701 bool operator< (const month& __lhs, const month& __rhs) noexcept
1702 { return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); }
1705 bool operator> (const month& __lhs, const month& __rhs) noexcept
1706 { return __rhs < __lhs; }
1709 bool operator<=(const month& __lhs, const month& __rhs) noexcept
1710 { return !(__rhs < __lhs); }
1713 bool operator>=(const month& __lhs, const month& __rhs) noexcept
1714 { return !(__lhs < __rhs); }
1717 month operator+ (const month& __lhs, const months& __rhs) noexcept
1719 auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1);
1720 auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12;
1721 return month{static_cast<unsigned>(__mu - __yr * 12 + 1)};
1725 month operator+ (const months& __lhs, const month& __rhs) noexcept
1726 { return __rhs + __lhs; }
1729 month operator- (const month& __lhs, const months& __rhs) noexcept
1730 { return __lhs + -__rhs; }
1733 months operator-(const month& __lhs, const month& __rhs) noexcept
1735 auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
1736 return months(__dm <= 11 ? __dm : __dm + 12);
1739 inline constexpr month& month::operator+=(const months& __dm) noexcept
1740 { *this = *this + __dm; return *this; }
1742 inline constexpr month& month::operator-=(const months& __dm) noexcept
1743 { *this = *this - __dm; return *this; }
1746 class _LIBCPP_TYPE_VIS year {
1751 explicit inline constexpr year(int __val) noexcept : __y(static_cast<short>(__val)) {}
1753 inline constexpr year& operator++() noexcept { ++__y; return *this; };
1754 inline constexpr year operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; };
1755 inline constexpr year& operator--() noexcept { --__y; return *this; };
1756 inline constexpr year operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; };
1757 constexpr year& operator+=(const years& __dy) noexcept;
1758 constexpr year& operator-=(const years& __dy) noexcept;
1759 inline constexpr year operator+() const noexcept { return *this; }
1760 inline constexpr year operator-() const noexcept { return year{-__y}; };
1762 inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); }
1763 explicit inline constexpr operator int() const noexcept { return __y; }
1764 constexpr bool ok() const noexcept;
1765 static inline constexpr year min() noexcept { return year{-32767}; }
1766 static inline constexpr year max() noexcept { return year{ 32767}; }
1771 bool operator==(const year& __lhs, const year& __rhs) noexcept
1772 { return static_cast<int>(__lhs) == static_cast<int>(__rhs); }
1775 bool operator!=(const year& __lhs, const year& __rhs) noexcept
1776 { return !(__lhs == __rhs); }
1779 bool operator< (const year& __lhs, const year& __rhs) noexcept
1780 { return static_cast<int>(__lhs) < static_cast<int>(__rhs); }
1783 bool operator> (const year& __lhs, const year& __rhs) noexcept
1784 { return __rhs < __lhs; }
1787 bool operator<=(const year& __lhs, const year& __rhs) noexcept
1788 { return !(__rhs < __lhs); }
1791 bool operator>=(const year& __lhs, const year& __rhs) noexcept
1792 { return !(__lhs < __rhs); }
1795 year operator+ (const year& __lhs, const years& __rhs) noexcept
1796 { return year(static_cast<int>(__lhs) + __rhs.count()); }
1799 year operator+ (const years& __lhs, const year& __rhs) noexcept
1800 { return __rhs + __lhs; }
1803 year operator- (const year& __lhs, const years& __rhs) noexcept
1804 { return __lhs + -__rhs; }
1807 years operator-(const year& __lhs, const year& __rhs) noexcept
1808 { return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)}; }
1811 inline constexpr year& year::operator+=(const years& __dy) noexcept
1812 { *this = *this + __dy; return *this; }
1814 inline constexpr year& year::operator-=(const years& __dy) noexcept
1815 { *this = *this - __dy; return *this; }
1817 inline constexpr bool year::ok() const noexcept
1818 { return static_cast<int>(min()) <= __y && __y <= static_cast<int>(max()); }
1820 class _LIBCPP_TYPE_VIS weekday_indexed;
1821 class _LIBCPP_TYPE_VIS weekday_last;
1823 class _LIBCPP_TYPE_VIS weekday {
1827 weekday() = default;
1828 inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast<unsigned char>(__val)) {}
1829 inline constexpr weekday(const sys_days& __sysd) noexcept
1830 : __wd(__weekday_from_days(__sysd.time_since_epoch().count())) {}
1831 inline explicit constexpr weekday(const local_days& __locd) noexcept
1832 : __wd(__weekday_from_days(__locd.time_since_epoch().count())) {}
1834 inline constexpr weekday& operator++() noexcept { __wd = (__wd == 6 ? 0 : __wd + 1); return *this; }
1835 inline constexpr weekday operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; }
1836 inline constexpr weekday& operator--() noexcept { __wd = (__wd == 0 ? 6 : __wd - 1); return *this; }
1837 inline constexpr weekday operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; }
1838 constexpr weekday& operator+=(const days& __dd) noexcept;
1839 constexpr weekday& operator-=(const days& __dd) noexcept;
1840 inline explicit constexpr operator unsigned() const noexcept { return __wd; }
1841 inline constexpr bool ok() const noexcept { return __wd <= 6; }
1842 constexpr weekday_indexed operator[](unsigned __index) const noexcept;
1843 constexpr weekday_last operator[](last_spec) const noexcept;
1845 static constexpr unsigned char __weekday_from_days(int __days) noexcept;
1849 // https://howardhinnant.github.io/date_algorithms.html#weekday_from_days
1851 unsigned char weekday::__weekday_from_days(int __days) noexcept
1853 return static_cast<unsigned char>(
1854 static_cast<unsigned>(__days >= -4 ? (__days+4) % 7 : (__days+5) % 7 + 6)
1859 bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept
1860 { return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
1863 bool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept
1864 { return !(__lhs == __rhs); }
1867 bool operator< (const weekday& __lhs, const weekday& __rhs) noexcept
1868 { return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); }
1871 bool operator> (const weekday& __lhs, const weekday& __rhs) noexcept
1872 { return __rhs < __lhs; }
1875 bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept
1876 { return !(__rhs < __lhs);}
1879 bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept
1880 { return !(__lhs < __rhs); }
1882 constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept
1884 auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + __rhs.count();
1885 auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7;
1886 return weekday{static_cast<unsigned>(__mu - __yr * 7)};
1889 constexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept
1890 { return __rhs + __lhs; }
1892 constexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept
1893 { return __lhs + -__rhs; }
1895 constexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept
1897 const int __wdu = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
1898 const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7;
1899 return days{__wdu - __wk * 7};
1902 inline constexpr weekday& weekday::operator+=(const days& __dd) noexcept
1903 { *this = *this + __dd; return *this; }
1905 inline constexpr weekday& weekday::operator-=(const days& __dd) noexcept
1906 { *this = *this - __dd; return *this; }
1909 class _LIBCPP_TYPE_VIS weekday_indexed {
1911 _VSTD::chrono::weekday __wd;
1912 unsigned char __idx;
1914 weekday_indexed() = default;
1915 inline constexpr weekday_indexed(const _VSTD::chrono::weekday& __wdval, unsigned __idxval) noexcept
1916 : __wd{__wdval}, __idx(__idxval) {}
1917 inline constexpr _VSTD::chrono::weekday weekday() const noexcept { return __wd; }
1918 inline constexpr unsigned index() const noexcept { return __idx; }
1919 inline constexpr bool ok() const noexcept { return __wd.ok() && __idx >= 1 && __idx <= 5; }
1923 bool operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
1924 { return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); }
1927 bool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
1928 { return !(__lhs == __rhs); }
1931 class _LIBCPP_TYPE_VIS weekday_last {
1933 _VSTD::chrono::weekday __wd;
1935 explicit constexpr weekday_last(const _VSTD::chrono::weekday& __val) noexcept
1937 constexpr _VSTD::chrono::weekday weekday() const noexcept { return __wd; }
1938 constexpr bool ok() const noexcept { return __wd.ok(); }
1942 bool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
1943 { return __lhs.weekday() == __rhs.weekday(); }
1946 bool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
1947 { return !(__lhs == __rhs); }
1950 weekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; }
1953 weekday_last weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; }
1956 inline constexpr last_spec last{};
1957 inline constexpr weekday Sunday{0};
1958 inline constexpr weekday Monday{1};
1959 inline constexpr weekday Tuesday{2};
1960 inline constexpr weekday Wednesday{3};
1961 inline constexpr weekday Thursday{4};
1962 inline constexpr weekday Friday{5};
1963 inline constexpr weekday Saturday{6};
1965 inline constexpr month January{1};
1966 inline constexpr month February{2};
1967 inline constexpr month March{3};
1968 inline constexpr month April{4};
1969 inline constexpr month May{5};
1970 inline constexpr month June{6};
1971 inline constexpr month July{7};
1972 inline constexpr month August{8};
1973 inline constexpr month September{9};
1974 inline constexpr month October{10};
1975 inline constexpr month November{11};
1976 inline constexpr month December{12};
1979 class _LIBCPP_TYPE_VIS month_day {
1984 month_day() = default;
1985 constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept
1986 : __m{__mval}, __d{__dval} {}
1987 inline constexpr chrono::month month() const noexcept { return __m; }
1988 inline constexpr chrono::day day() const noexcept { return __d; }
1989 constexpr bool ok() const noexcept;
1993 bool month_day::ok() const noexcept
1995 if (!__m.ok()) return false;
1996 const unsigned __dval = static_cast<unsigned>(__d);
1997 if (__dval < 1 || __dval > 31) return false;
1998 if (__dval <= 29) return true;
1999 // Now we've got either 30 or 31
2000 const unsigned __mval = static_cast<unsigned>(__m);
2001 if (__mval == 2) return false;
2002 if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11)
2003 return __dval == 30;
2008 bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept
2009 { return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
2012 bool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept
2013 { return !(__lhs == __rhs); }
2016 month_day operator/(const month& __lhs, const day& __rhs) noexcept
2017 { return month_day{__lhs, __rhs}; }
2020 month_day operator/(const day& __lhs, const month& __rhs) noexcept
2021 { return __rhs / __lhs; }
2024 month_day operator/(const month& __lhs, int __rhs) noexcept
2025 { return __lhs / day(__rhs); }
2028 month_day operator/(int __lhs, const day& __rhs) noexcept
2029 { return month(__lhs) / __rhs; }
2032 month_day operator/(const day& __lhs, int __rhs) noexcept
2033 { return month(__rhs) / __lhs; }
2037 bool operator< (const month_day& __lhs, const month_day& __rhs) noexcept
2038 { return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); }
2041 bool operator> (const month_day& __lhs, const month_day& __rhs) noexcept
2042 { return __rhs < __lhs; }
2045 bool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept
2046 { return !(__rhs < __lhs);}
2049 bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept
2050 { return !(__lhs < __rhs); }
2054 class _LIBCPP_TYPE_VIS month_day_last {
2058 explicit constexpr month_day_last(const chrono::month& __val) noexcept
2060 inline constexpr chrono::month month() const noexcept { return __m; }
2061 inline constexpr bool ok() const noexcept { return __m.ok(); }
2065 bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2066 { return __lhs.month() == __rhs.month(); }
2069 bool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2070 { return !(__lhs == __rhs); }
2073 bool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2074 { return __lhs.month() < __rhs.month(); }
2077 bool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2078 { return __rhs < __lhs; }
2081 bool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2082 { return !(__rhs < __lhs);}
2085 bool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2086 { return !(__lhs < __rhs); }
2089 month_day_last operator/(const month& __lhs, last_spec) noexcept
2090 { return month_day_last{__lhs}; }
2093 month_day_last operator/(last_spec, const month& __rhs) noexcept
2094 { return month_day_last{__rhs}; }
2097 month_day_last operator/(int __lhs, last_spec) noexcept
2098 { return month_day_last{month(__lhs)}; }
2101 month_day_last operator/(last_spec, int __rhs) noexcept
2102 { return month_day_last{month(__rhs)}; }
2105 class _LIBCPP_TYPE_VIS month_weekday {
2108 chrono::weekday_indexed __wdi;
2110 month_weekday() = default;
2111 constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept
2112 : __m{__mval}, __wdi{__wdival} {}
2113 inline constexpr chrono::month month() const noexcept { return __m; }
2114 inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
2115 inline constexpr bool ok() const noexcept { return __m.ok() && __wdi.ok(); }
2119 bool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
2120 { return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
2123 bool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
2124 { return !(__lhs == __rhs); }
2127 month_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept
2128 { return month_weekday{__lhs, __rhs}; }
2131 month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept
2132 { return month_weekday{month(__lhs), __rhs}; }
2135 month_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept
2136 { return month_weekday{__rhs, __lhs}; }
2139 month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept
2140 { return month_weekday{month(__rhs), __lhs}; }
2143 class _LIBCPP_TYPE_VIS month_weekday_last {
2145 chrono::weekday_last __wdl;
2147 constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept
2148 : __m{__mval}, __wdl{__wdlval} {}
2149 inline constexpr chrono::month month() const noexcept { return __m; }
2150 inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
2151 inline constexpr bool ok() const noexcept { return __m.ok() && __wdl.ok(); }
2155 bool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
2156 { return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
2159 bool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
2160 { return !(__lhs == __rhs); }
2164 month_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept
2165 { return month_weekday_last{__lhs, __rhs}; }
2168 month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept
2169 { return month_weekday_last{month(__lhs), __rhs}; }
2172 month_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept
2173 { return month_weekday_last{__rhs, __lhs}; }
2176 month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept
2177 { return month_weekday_last{month(__rhs), __lhs}; }
2180 class _LIBCPP_TYPE_VIS year_month {
2184 year_month() = default;
2185 constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept
2186 : __y{__yval}, __m{__mval} {}
2187 inline constexpr chrono::year year() const noexcept { return __y; }
2188 inline constexpr chrono::month month() const noexcept { return __m; }
2189 inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m += __dm; return *this; }
2190 inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m -= __dm; return *this; }
2191 inline constexpr year_month& operator+=(const years& __dy) noexcept { this->__y += __dy; return *this; }
2192 inline constexpr year_month& operator-=(const years& __dy) noexcept { this->__y -= __dy; return *this; }
2193 inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok(); }
2197 year_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; }
2200 year_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; }
2203 bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept
2204 { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); }
2207 bool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept
2208 { return !(__lhs == __rhs); }
2211 bool operator< (const year_month& __lhs, const year_month& __rhs) noexcept
2212 { return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); }
2215 bool operator> (const year_month& __lhs, const year_month& __rhs) noexcept
2216 { return __rhs < __lhs; }
2219 bool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept
2220 { return !(__rhs < __lhs);}
2223 bool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept
2224 { return !(__lhs < __rhs); }
2226 constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept
2228 int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count();
2229 const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12;
2230 __dmi = __dmi - __dy * 12 + 1;
2231 return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi));
2234 constexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept
2235 { return __rhs + __lhs; }
2237 constexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept
2238 { return (__lhs.year() + __rhs) / __lhs.month(); }
2240 constexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept
2241 { return __rhs + __lhs; }
2243 constexpr months operator-(const year_month& __lhs, const year_month& __rhs) noexcept
2244 { return (__lhs.year() - __rhs.year()) + months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month())); }
2246 constexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept
2247 { return __lhs + -__rhs; }
2249 constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept
2250 { return __lhs + -__rhs; }
2252 class year_month_day_last;
2254 class _LIBCPP_TYPE_VIS year_month_day {
2260 year_month_day() = default;
2261 inline constexpr year_month_day(
2262 const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept
2263 : __y{__yval}, __m{__mval}, __d{__dval} {}
2264 constexpr year_month_day(const year_month_day_last& __ymdl) noexcept;
2265 inline constexpr year_month_day(const sys_days& __sysd) noexcept
2266 : year_month_day(__from_days(__sysd.time_since_epoch())) {}
2267 inline explicit constexpr year_month_day(const local_days& __locd) noexcept
2268 : year_month_day(__from_days(__locd.time_since_epoch())) {}
2270 constexpr year_month_day& operator+=(const months& __dm) noexcept;
2271 constexpr year_month_day& operator-=(const months& __dm) noexcept;
2272 constexpr year_month_day& operator+=(const years& __dy) noexcept;
2273 constexpr year_month_day& operator-=(const years& __dy) noexcept;
2275 inline constexpr chrono::year year() const noexcept { return __y; }
2276 inline constexpr chrono::month month() const noexcept { return __m; }
2277 inline constexpr chrono::day day() const noexcept { return __d; }
2278 inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
2279 inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
2281 constexpr bool ok() const noexcept;
2283 static constexpr year_month_day __from_days(days __d) noexcept;
2284 constexpr days __to_days() const noexcept;
2288 // https://howardhinnant.github.io/date_algorithms.html#civil_from_days
2291 year_month_day::__from_days(days __d) noexcept
2293 static_assert(std::numeric_limits<unsigned>::digits >= 18, "");
2294 static_assert(std::numeric_limits<int>::digits >= 20 , "");
2295 const int __z = __d.count() + 719468;
2296 const int __era = (__z >= 0 ? __z : __z - 146096) / 146097;
2297 const unsigned __doe = static_cast<unsigned>(__z - __era * 146097); // [0, 146096]
2298 const unsigned __yoe = (__doe - __doe/1460 + __doe/36524 - __doe/146096) / 365; // [0, 399]
2299 const int __yr = static_cast<int>(__yoe) + __era * 400;
2300 const unsigned __doy = __doe - (365 * __yoe + __yoe/4 - __yoe/100); // [0, 365]
2301 const unsigned __mp = (5 * __doy + 2)/153; // [0, 11]
2302 const unsigned __dy = __doy - (153 * __mp + 2)/5 + 1; // [1, 31]
2303 const unsigned __mth = __mp + (__mp < 10 ? 3 : -9); // [1, 12]
2304 return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}};
2307 // https://howardhinnant.github.io/date_algorithms.html#days_from_civil
2308 inline constexpr days year_month_day::__to_days() const noexcept
2310 static_assert(std::numeric_limits<unsigned>::digits >= 18, "");
2311 static_assert(std::numeric_limits<int>::digits >= 20 , "");
2313 const int __yr = static_cast<int>(__y) - (__m <= February);
2314 const unsigned __mth = static_cast<unsigned>(__m);
2315 const unsigned __dy = static_cast<unsigned>(__d);
2317 const int __era = (__yr >= 0 ? __yr : __yr - 399) / 400;
2318 const unsigned __yoe = static_cast<unsigned>(__yr - __era * 400); // [0, 399]
2319 const unsigned __doy = (153 * (__mth + (__mth > 2 ? -3 : 9)) + 2) / 5 + __dy-1; // [0, 365]
2320 const unsigned __doe = __yoe * 365 + __yoe/4 - __yoe/100 + __doy; // [0, 146096]
2321 return days{__era * 146097 + static_cast<int>(__doe) - 719468};
2325 bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2326 { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
2329 bool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2330 { return !(__lhs == __rhs); }
2333 bool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2335 if (__lhs.year() < __rhs.year()) return true;
2336 if (__lhs.year() > __rhs.year()) return false;
2337 if (__lhs.month() < __rhs.month()) return true;
2338 if (__lhs.month() > __rhs.month()) return false;
2339 return __lhs.day() < __rhs.day();
2343 bool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2344 { return __rhs < __lhs; }
2347 bool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2348 { return !(__rhs < __lhs);}
2351 bool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2352 { return !(__lhs < __rhs); }
2355 year_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept
2356 { return year_month_day{__lhs.year(), __lhs.month(), __rhs}; }
2359 year_month_day operator/(const year_month& __lhs, int __rhs) noexcept
2360 { return __lhs / day(__rhs); }
2363 year_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept
2364 { return __lhs / __rhs.month() / __rhs.day(); }
2367 year_month_day operator/(int __lhs, const month_day& __rhs) noexcept
2368 { return year(__lhs) / __rhs; }
2371 year_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept
2372 { return __rhs / __lhs; }
2375 year_month_day operator/(const month_day& __lhs, int __rhs) noexcept
2376 { return year(__rhs) / __lhs; }
2380 year_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept
2381 { return (__lhs.year()/__lhs.month() + __rhs)/__lhs.day(); }
2384 year_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept
2385 { return __rhs + __lhs; }
2388 year_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept
2389 { return __lhs + -__rhs; }
2392 year_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept
2393 { return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); }
2396 year_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept
2397 { return __rhs + __lhs; }
2400 year_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept
2401 { return __lhs + -__rhs; }
2403 inline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
2404 inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
2405 inline constexpr year_month_day& year_month_day::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
2406 inline constexpr year_month_day& year_month_day::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
2408 class _LIBCPP_TYPE_VIS year_month_day_last {
2411 chrono::month_day_last __mdl;
2413 constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept
2414 : __y{__yval}, __mdl{__mdlval} {}
2416 constexpr year_month_day_last& operator+=(const months& __m) noexcept;
2417 constexpr year_month_day_last& operator-=(const months& __m) noexcept;
2418 constexpr year_month_day_last& operator+=(const years& __y) noexcept;
2419 constexpr year_month_day_last& operator-=(const years& __y) noexcept;
2421 inline constexpr chrono::year year() const noexcept { return __y; }
2422 inline constexpr chrono::month month() const noexcept { return __mdl.month(); }
2423 inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl; }
2424 constexpr chrono::day day() const noexcept;
2425 inline constexpr operator sys_days() const noexcept { return sys_days{year()/month()/day()}; }
2426 inline explicit constexpr operator local_days() const noexcept { return local_days{year()/month()/day()}; }
2427 inline constexpr bool ok() const noexcept { return __y.ok() && __mdl.ok(); }
2431 chrono::day year_month_day_last::day() const noexcept
2433 constexpr chrono::day __d[] =
2435 chrono::day(31), chrono::day(28), chrono::day(31),
2436 chrono::day(30), chrono::day(31), chrono::day(30),
2437 chrono::day(31), chrono::day(31), chrono::day(30),
2438 chrono::day(31), chrono::day(30), chrono::day(31)
2440 return month() != February || !__y.is_leap() ?
2441 __d[static_cast<unsigned>(month()) - 1] : chrono::day{29};
2445 bool operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2446 { return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); }
2449 bool operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2450 { return !(__lhs == __rhs); }
2453 bool operator< (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2455 if (__lhs.year() < __rhs.year()) return true;
2456 if (__lhs.year() > __rhs.year()) return false;
2457 return __lhs.month_day_last() < __rhs.month_day_last();
2461 bool operator> (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2462 { return __rhs < __lhs; }
2465 bool operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2466 { return !(__rhs < __lhs);}
2469 bool operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2470 { return !(__lhs < __rhs); }
2472 inline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept
2473 { return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; }
2475 inline constexpr year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept
2476 { return year_month_day_last{__lhs, __rhs}; }
2478 inline constexpr year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept
2479 { return year_month_day_last{year{__lhs}, __rhs}; }
2481 inline constexpr year_month_day_last operator/(const month_day_last& __lhs, const year& __rhs) noexcept
2482 { return __rhs / __lhs; }
2484 inline constexpr year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept
2485 { return year{__rhs} / __lhs; }
2489 year_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept
2490 { return (__lhs.year() / __lhs.month() + __rhs) / last; }
2493 year_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept
2494 { return __rhs + __lhs; }
2497 year_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept
2498 { return __lhs + (-__rhs); }
2501 year_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept
2502 { return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; }
2505 year_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept
2506 { return __rhs + __lhs; }
2509 year_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept
2510 { return __lhs + (-__rhs); }
2512 inline constexpr year_month_day_last& year_month_day_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
2513 inline constexpr year_month_day_last& year_month_day_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
2514 inline constexpr year_month_day_last& year_month_day_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
2515 inline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
2517 inline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept
2518 : __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {}
2520 inline constexpr bool year_month_day::ok() const noexcept
2522 if (!__y.ok() || !__m.ok()) return false;
2523 return chrono::day{1} <= __d && __d <= (__y / __m / last).day();
2526 class _LIBCPP_TYPE_VIS year_month_weekday {
2529 chrono::weekday_indexed __wdi;
2531 year_month_weekday() = default;
2532 constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval,
2533 const chrono::weekday_indexed& __wdival) noexcept
2534 : __y{__yval}, __m{__mval}, __wdi{__wdival} {}
2535 constexpr year_month_weekday(const sys_days& __sysd) noexcept
2536 : year_month_weekday(__from_days(__sysd.time_since_epoch())) {}
2537 inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept
2538 : year_month_weekday(__from_days(__locd.time_since_epoch())) {}
2539 constexpr year_month_weekday& operator+=(const months& m) noexcept;
2540 constexpr year_month_weekday& operator-=(const months& m) noexcept;
2541 constexpr year_month_weekday& operator+=(const years& y) noexcept;
2542 constexpr year_month_weekday& operator-=(const years& y) noexcept;
2544 inline constexpr chrono::year year() const noexcept { return __y; }
2545 inline constexpr chrono::month month() const noexcept { return __m; }
2546 inline constexpr chrono::weekday weekday() const noexcept { return __wdi.weekday(); }
2547 inline constexpr unsigned index() const noexcept { return __wdi.index(); }
2548 inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
2550 inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
2551 inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
2552 inline constexpr bool ok() const noexcept
2554 if (!__y.ok() || !__m.ok() || !__wdi.ok()) return false;
2555 // TODO: make sure it's a valid date
2559 static constexpr year_month_weekday __from_days(days __d) noexcept;
2560 constexpr days __to_days() const noexcept;
2564 year_month_weekday year_month_weekday::__from_days(days __d) noexcept
2566 const sys_days __sysd{__d};
2567 const chrono::weekday __wd = chrono::weekday(__sysd);
2568 const year_month_day __ymd = year_month_day(__sysd);
2569 return year_month_weekday{__ymd.year(), __ymd.month(),
2570 __wd[(static_cast<unsigned>(__ymd.day())-1)/7+1]};
2574 days year_month_weekday::__to_days() const noexcept
2576 const sys_days __sysd = sys_days(__y/__m/1);
2577 return (__sysd + (__wdi.weekday() - chrono::weekday(__sysd) + days{(__wdi.index()-1)*7}))
2578 .time_since_epoch();
2582 bool operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
2583 { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
2586 bool operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
2587 { return !(__lhs == __rhs); }
2590 year_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept
2591 { return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; }
2594 year_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept
2595 { return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; }
2598 year_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept
2599 { return year(__lhs) / __rhs; }
2602 year_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept
2603 { return __rhs / __lhs; }
2606 year_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept
2607 { return year(__rhs) / __lhs; }
2611 year_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept
2612 { return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); }
2615 year_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept
2616 { return __rhs + __lhs; }
2619 year_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept
2620 { return __lhs + (-__rhs); }
2623 year_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept
2624 { return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; }
2627 year_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept
2628 { return __rhs + __lhs; }
2631 year_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept
2632 { return __lhs + (-__rhs); }
2635 inline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
2636 inline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
2637 inline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
2638 inline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
2640 class _LIBCPP_TYPE_VIS year_month_weekday_last {
2644 chrono::weekday_last __wdl;
2646 constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval,
2647 const chrono::weekday_last& __wdlval) noexcept
2648 : __y{__yval}, __m{__mval}, __wdl{__wdlval} {}
2649 constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept;
2650 constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept;
2651 constexpr year_month_weekday_last& operator+=(const years& __dy) noexcept;
2652 constexpr year_month_weekday_last& operator-=(const years& __dy) noexcept;
2654 inline constexpr chrono::year year() const noexcept { return __y; }
2655 inline constexpr chrono::month month() const noexcept { return __m; }
2656 inline constexpr chrono::weekday weekday() const noexcept { return __wdl.weekday(); }
2657 inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
2658 inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
2659 inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
2660 inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __wdl.ok(); }
2662 constexpr days __to_days() const noexcept;
2667 days year_month_weekday_last::__to_days() const noexcept
2669 const sys_days __last = sys_days{__y/__m/last};
2670 return (__last - (chrono::weekday{__last} - __wdl.weekday())).time_since_epoch();
2675 bool operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
2676 { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
2679 bool operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
2680 { return !(__lhs == __rhs); }
2684 year_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept
2685 { return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; }
2688 year_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept
2689 { return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; }
2692 year_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept
2693 { return year(__lhs) / __rhs; }
2696 year_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept
2697 { return __rhs / __lhs; }
2700 year_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept
2701 { return year(__rhs) / __lhs; }
2705 year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
2706 { return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); }
2709 year_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept
2710 { return __rhs + __lhs; }
2713 year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
2714 { return __lhs + (-__rhs); }
2717 year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
2718 { return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; }
2721 year_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept
2722 { return __rhs + __lhs; }
2725 year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
2726 { return __lhs + (-__rhs); }
2728 inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
2729 inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
2730 inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
2731 inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
2733 #endif // _LIBCPP_STD_VER > 17
2736 #if _LIBCPP_STD_VER > 11
2737 // Suffixes for duration literals [time.duration.literals]
2738 inline namespace literals
2740 inline namespace chrono_literals
2743 constexpr chrono::hours operator""h(unsigned long long __h)
2745 return chrono::hours(static_cast<chrono::hours::rep>(__h));
2748 constexpr chrono::duration<long double, ratio<3600,1>> operator""h(long double __h)
2750 return chrono::duration<long double, ratio<3600,1>>(__h);
2754 constexpr chrono::minutes operator""min(unsigned long long __m)
2756 return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
2759 constexpr chrono::duration<long double, ratio<60,1>> operator""min(long double __m)
2761 return chrono::duration<long double, ratio<60,1>> (__m);
2765 constexpr chrono::seconds operator""s(unsigned long long __s)
2767 return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
2770 constexpr chrono::duration<long double> operator""s(long double __s)
2772 return chrono::duration<long double> (__s);
2776 constexpr chrono::milliseconds operator""ms(unsigned long long __ms)
2778 return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
2781 constexpr chrono::duration<long double, milli> operator""ms(long double __ms)
2783 return chrono::duration<long double, milli>(__ms);
2787 constexpr chrono::microseconds operator""us(unsigned long long __us)
2789 return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
2792 constexpr chrono::duration<long double, micro> operator""us(long double __us)
2794 return chrono::duration<long double, micro> (__us);
2798 constexpr chrono::nanoseconds operator""ns(unsigned long long __ns)
2800 return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
2803 constexpr chrono::duration<long double, nano> operator""ns(long double __ns)
2805 return chrono::duration<long double, nano> (__ns);
2808 #if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS)
2809 constexpr chrono::day operator ""d(unsigned long long __d) noexcept
2811 return chrono::day(static_cast<unsigned>(__d));
2814 constexpr chrono::year operator ""y(unsigned long long __y) noexcept
2816 return chrono::year(static_cast<int>(__y));
2821 namespace chrono { // hoist the literals into namespace std::chrono
2822 using namespace literals::chrono_literals;
2827 _LIBCPP_END_NAMESPACE_STD
2829 #ifndef _LIBCPP_CXX03_LANG
2830 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
2831 struct _FilesystemClock {
2832 #if !defined(_LIBCPP_HAS_NO_INT128)
2833 typedef __int128_t rep;
2834 typedef nano period;
2836 typedef long long rep;
2837 typedef nano period;
2840 typedef chrono::duration<rep, period> duration;
2841 typedef chrono::time_point<_FilesystemClock> time_point;
2843 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
2845 _LIBCPP_FUNC_VIS static time_point now() noexcept;
2847 _LIBCPP_INLINE_VISIBILITY
2848 static time_t to_time_t(const time_point& __t) noexcept {
2849 typedef chrono::duration<rep> __secs;
2851 chrono::duration_cast<__secs>(__t.time_since_epoch()).count());
2854 _LIBCPP_INLINE_VISIBILITY
2855 static time_point from_time_t(time_t __t) noexcept {
2856 typedef chrono::duration<rep> __secs;
2857 return time_point(__secs(__t));
2860 _LIBCPP_END_NAMESPACE_FILESYSTEM
2861 #endif // !_LIBCPP_CXX03_LANG
2865 #endif // _LIBCPP_CHRONO