2 //===---------------------------- chrono ----------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_CHRONO
11 #define _LIBCPP_CHRONO
21 template <class ToDuration, class Rep, class Period>
24 duration_cast(const duration<Rep, Period>& fd);
26 template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {};
28 template <class Rep> inline constexpr bool treat_as_floating_point_v
29 = treat_as_floating_point<Rep>::value; // C++17
32 struct duration_values
35 static constexpr Rep zero(); // noexcept in C++20
36 static constexpr Rep max(); // noexcept in C++20
37 static constexpr Rep min(); // noexcept in C++20
42 template <class Rep, class Period = ratio<1>>
45 static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration");
46 static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio");
47 static_assert(Period::num > 0, "duration period must be positive");
50 typedef typename _Period::type period;
52 constexpr duration() = default;
54 constexpr explicit duration(const Rep2& r,
57 is_convertible<Rep2, rep>::value &&
58 (treat_as_floating_point<rep>::value ||
59 !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value)
63 template <class Rep2, class Period2>
64 constexpr duration(const duration<Rep2, Period2>& d,
67 treat_as_floating_point<rep>::value ||
68 ratio_divide<Period2, period>::type::den == 1
73 constexpr rep count() const;
77 constexpr common_type<duration>::type operator+() const;
78 constexpr common_type<duration>::type operator-() const;
79 constexpr duration& operator++(); // constexpr in C++17
80 constexpr duration operator++(int); // constexpr in C++17
81 constexpr duration& operator--(); // constexpr in C++17
82 constexpr duration operator--(int); // constexpr in C++17
84 constexpr duration& operator+=(const duration& d); // constexpr in C++17
85 constexpr duration& operator-=(const duration& d); // constexpr in C++17
87 duration& operator*=(const rep& rhs); // 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 duration& rhs); // constexpr in C++17
94 static constexpr duration zero(); // noexcept in C++20
95 static constexpr duration min(); // noexcept in C++20
96 static constexpr duration max(); // noexcept in C++20
99 typedef duration<long long, nano> nanoseconds;
100 typedef duration<long long, micro> microseconds;
101 typedef duration<long long, milli> milliseconds;
102 typedef duration<long long > seconds;
103 typedef duration< long, ratio< 60> > minutes;
104 typedef duration< long, ratio<3600> > hours;
106 template <class Clock, class Duration = typename Clock::duration>
111 typedef Duration duration;
112 typedef typename duration::rep rep;
113 typedef typename duration::period period;
115 duration d_; // exposition only
118 time_point(); // has value "epoch" // constexpr in C++14
119 explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14
122 template <class Duration2>
123 time_point(const time_point<clock, Duration2>& t); // constexpr in C++14
127 duration time_since_epoch() const; // constexpr in C++14
131 time_point& operator+=(const duration& d); // constexpr in C++17
132 time_point& operator-=(const duration& d); // constexpr in C++17
136 static constexpr time_point min(); // noexcept in C++20
137 static constexpr time_point max(); // noexcept in C++20
142 // common_type traits
143 template <class Rep1, class Period1, class Rep2, class Period2>
144 struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>;
146 template <class Clock, class Duration1, class Duration2>
147 struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>;
152 template<class T> struct is_clock; // C++20
153 template<class T> inline constexpr bool is_clock_v = is_clock<T>::value; // C++20
156 // duration arithmetic
157 template <class Rep1, class Period1, class Rep2, class Period2>
159 typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
160 operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
161 template <class Rep1, class Period1, class Rep2, class Period2>
163 typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
164 operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
165 template <class Rep1, class Period, class Rep2>
167 duration<typename common_type<Rep1, Rep2>::type, Period>
168 operator*(const duration<Rep1, Period>& d, const Rep2& s);
169 template <class Rep1, class Period, class Rep2>
171 duration<typename common_type<Rep1, Rep2>::type, Period>
172 operator*(const Rep1& s, const duration<Rep2, Period>& d);
173 template <class Rep1, class Period, class Rep2>
175 duration<typename common_type<Rep1, Rep2>::type, Period>
176 operator/(const duration<Rep1, Period>& d, const Rep2& s);
177 template <class Rep1, class Period1, class Rep2, class Period2>
179 typename common_type<Rep1, Rep2>::type
180 operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
182 // duration comparisons
183 template <class Rep1, class Period1, class Rep2, class Period2>
185 bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
186 template <class Rep1, class Period1, class Rep2, class Period2>
188 bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
189 template <class Rep1, class Period1, class Rep2, class Period2>
191 bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
192 template <class Rep1, class Period1, class Rep2, class Period2>
194 bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
195 template <class Rep1, class Period1, class Rep2, class Period2>
197 bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
198 template <class Rep1, class Period1, class Rep2, class Period2>
200 bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
203 template <class ToDuration, class Rep, class Period>
204 ToDuration duration_cast(const duration<Rep, Period>& d);
206 template <class ToDuration, class Rep, class Period>
207 constexpr ToDuration floor(const duration<Rep, Period>& d); // C++17
208 template <class ToDuration, class Rep, class Period>
209 constexpr ToDuration ceil(const duration<Rep, Period>& d); // C++17
210 template <class ToDuration, class Rep, class Period>
211 constexpr ToDuration round(const duration<Rep, Period>& d); // C++17
213 // duration I/O is elsewhere
215 // time_point arithmetic (all constexpr in C++14)
216 template <class Clock, class Duration1, class Rep2, class Period2>
217 time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
218 operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
219 template <class Rep1, class Period1, class Clock, class Duration2>
220 time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
221 operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
222 template <class Clock, class Duration1, class Rep2, class Period2>
223 time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
224 operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
225 template <class Clock, class Duration1, class Duration2>
226 typename common_type<Duration1, Duration2>::type
227 operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
229 // time_point comparisons (all constexpr in C++14)
230 template <class Clock, class Duration1, class Duration2>
231 bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
232 template <class Clock, class Duration1, class Duration2>
233 bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
234 template <class Clock, class Duration1, class Duration2>
235 bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
236 template <class Clock, class Duration1, class Duration2>
237 bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
238 template <class Clock, class Duration1, class Duration2>
239 bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
240 template <class Clock, class Duration1, class Duration2>
241 bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
243 // time_point_cast (constexpr in C++14)
245 template <class ToDuration, class Clock, class Duration>
246 time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
248 template <class ToDuration, class Clock, class Duration>
249 constexpr time_point<Clock, ToDuration>
250 floor(const time_point<Clock, Duration>& tp); // C++17
252 template <class ToDuration, class Clock, class Duration>
253 constexpr time_point<Clock, ToDuration>
254 ceil(const time_point<Clock, Duration>& tp); // C++17
256 template <class ToDuration, class Clock, class Duration>
257 constexpr time_point<Clock, ToDuration>
258 round(const time_point<Clock, Duration>& tp); // C++17
260 template <class Rep, class Period>
261 constexpr duration<Rep, Period> abs(duration<Rep, Period> d); // C++17
268 typedef microseconds duration;
269 typedef duration::rep rep;
270 typedef duration::period period;
271 typedef chrono::time_point<system_clock> time_point;
272 static const bool is_steady = false; // constexpr in C++14
274 static time_point now() noexcept;
275 static time_t to_time_t (const time_point& __t) noexcept;
276 static time_point from_time_t(time_t __t) noexcept;
279 template <class Duration>
280 using sys_time = time_point<system_clock, Duration>; // C++20
281 using sys_seconds = sys_time<seconds>; // C++20
282 using sys_days = sys_time<days>; // C++20
284 class utc_clock; // C++20
286 template <class Duration>
287 using utc_time = time_point<utc_clock, Duration>; // C++20
288 using utc_seconds = utc_time<seconds>; // C++20
290 class tai_clock; // C++20
292 template <class Duration>
293 using tai_time = time_point<tai_clock, Duration>; // C++20
294 using tai_seconds = tai_time<seconds>; // C++20
296 class file_clock; // C++20
298 template<class Duration>
299 using file_time = time_point<file_clock, Duration>; // C++20
304 typedef nanoseconds duration;
305 typedef duration::rep rep;
306 typedef duration::period period;
307 typedef chrono::time_point<steady_clock, duration> time_point;
308 static const bool is_steady = true; // constexpr in C++14
310 static time_point now() noexcept;
313 typedef steady_clock high_resolution_clock;
315 // 25.7.8, local time // C++20
317 template<class Duration>
318 using local_time = time_point<local_t, Duration>;
319 using local_seconds = local_time<seconds>;
320 using local_days = local_time<days>;
322 // 25.7.9, time_point conversions template<class DestClock, class SourceClock> // C++20
323 struct clock_time_conversion;
325 template<class DestClock, class SourceClock, class Duration>
326 auto clock_cast(const time_point<SourceClock, Duration>& t);
328 // 25.8.2, class last_spec // C++20
331 // 25.8.3, class day // C++20
334 constexpr bool operator==(const day& x, const day& y) noexcept;
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 day operator+(const day& x, const days& y) noexcept;
341 constexpr day operator+(const days& x, const day& y) noexcept;
342 constexpr day operator-(const day& x, const days& y) noexcept;
343 constexpr days operator-(const day& x, const day& y) noexcept;
345 // 25.8.4, class month // C++20
347 constexpr bool operator==(const month& x, const month& y) noexcept;
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 month operator+(const month& x, const months& y) noexcept;
354 constexpr month operator+(const months& x, const month& y) noexcept;
355 constexpr month operator-(const month& x, const months& y) noexcept;
356 constexpr months operator-(const month& x, const month& y) noexcept;
358 // 25.8.5, class year // C++20
360 constexpr bool operator==(const year& x, const year& y) noexcept;
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 year operator+(const year& x, const years& y) noexcept;
367 constexpr year operator+(const years& x, const year& y) noexcept;
368 constexpr year operator-(const year& x, const years& y) noexcept;
369 constexpr years operator-(const year& x, const year& y) noexcept;
371 // 25.8.6, class weekday // C++20
374 constexpr bool operator==(const weekday& x, const weekday& y) noexcept;
375 constexpr bool operator!=(const weekday& x, const weekday& y) noexcept;
376 constexpr weekday operator+(const weekday& x, const days& y) noexcept;
377 constexpr weekday operator+(const days& x, const weekday& y) noexcept;
378 constexpr weekday operator-(const weekday& x, const days& y) noexcept;
379 constexpr days operator-(const weekday& x, const weekday& y) noexcept;
381 // 25.8.7, class weekday_indexed // C++20
383 class weekday_indexed;
384 constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept;
385 constexpr bool operator!=(const weekday_indexed& x, const weekday_indexed& y) noexcept;
387 // 25.8.8, class weekday_last // C++20
390 constexpr bool operator==(const weekday_last& x, const weekday_last& y) noexcept;
391 constexpr bool operator!=(const weekday_last& x, const weekday_last& y) noexcept;
393 // 25.8.9, class month_day // C++20
396 constexpr bool operator==(const month_day& x, const month_day& y) noexcept;
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;
404 // 25.8.10, class month_day_last // C++20
405 class month_day_last;
407 constexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept;
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;
414 // 25.8.11, class month_weekday // C++20
417 constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept;
418 constexpr bool operator!=(const month_weekday& x, const month_weekday& y) noexcept;
420 // 25.8.12, class month_weekday_last // C++20
421 class month_weekday_last;
423 constexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept;
424 constexpr bool operator!=(const month_weekday_last& x, const month_weekday_last& y) noexcept;
427 // 25.8.13, class year_month // C++20
430 constexpr bool operator==(const year_month& x, const year_month& y) noexcept;
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;
437 constexpr year_month operator+(const year_month& ym, const months& dm) noexcept;
438 constexpr year_month operator+(const months& dm, const year_month& ym) noexcept;
439 constexpr year_month operator-(const year_month& ym, const months& dm) noexcept;
440 constexpr months operator-(const year_month& x, const year_month& y) noexcept;
441 constexpr year_month operator+(const year_month& ym, const years& dy) noexcept;
442 constexpr year_month operator+(const years& dy, const year_month& ym) noexcept;
443 constexpr year_month operator-(const year_month& ym, const years& dy) noexcept;
445 // 25.8.14, class year_month_day class // C++20
448 constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept;
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;
455 constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept;
456 constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept;
457 constexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept;
458 constexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept;
459 constexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept;
460 constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept;
463 // 25.8.15, class year_month_day_last // C++20
464 class year_month_day_last;
466 constexpr bool operator==(const year_month_day_last& x,
467 const year_month_day_last& y) noexcept;
468 constexpr bool operator!=(const year_month_day_last& x,
469 const year_month_day_last& y) noexcept;
470 constexpr bool operator< (const year_month_day_last& x,
471 const year_month_day_last& y) noexcept;
472 constexpr bool operator> (const year_month_day_last& x,
473 const year_month_day_last& y) noexcept;
474 constexpr bool operator<=(const year_month_day_last& x,
475 const year_month_day_last& y) noexcept;
476 constexpr bool operator>=(const year_month_day_last& x,
477 const year_month_day_last& y) noexcept;
479 constexpr year_month_day_last
480 operator+(const year_month_day_last& ymdl, const months& dm) noexcept;
481 constexpr year_month_day_last
482 operator+(const months& dm, const year_month_day_last& ymdl) noexcept;
483 constexpr year_month_day_last
484 operator+(const year_month_day_last& ymdl, const years& dy) noexcept;
485 constexpr year_month_day_last
486 operator+(const years& dy, const year_month_day_last& ymdl) noexcept;
487 constexpr year_month_day_last
488 operator-(const year_month_day_last& ymdl, const months& dm) noexcept;
489 constexpr year_month_day_last
490 operator-(const year_month_day_last& ymdl, const years& dy) noexcept;
492 // 25.8.16, class year_month_weekday // C++20
493 class year_month_weekday;
495 constexpr bool operator==(const year_month_weekday& x,
496 const year_month_weekday& y) noexcept;
497 constexpr bool operator!=(const year_month_weekday& x,
498 const year_month_weekday& y) noexcept;
500 constexpr year_month_weekday
501 operator+(const year_month_weekday& ymwd, const months& dm) noexcept;
502 constexpr year_month_weekday
503 operator+(const months& dm, const year_month_weekday& ymwd) noexcept;
504 constexpr year_month_weekday
505 operator+(const year_month_weekday& ymwd, const years& dy) noexcept;
506 constexpr year_month_weekday
507 operator+(const years& dy, const year_month_weekday& ymwd) noexcept;
508 constexpr year_month_weekday
509 operator-(const year_month_weekday& ymwd, const months& dm) noexcept;
510 constexpr year_month_weekday
511 operator-(const year_month_weekday& ymwd, const years& dy) noexcept;
513 // 25.8.17, class year_month_weekday_last // C++20
514 class year_month_weekday_last;
516 constexpr bool operator==(const year_month_weekday_last& x,
517 const year_month_weekday_last& y) noexcept;
518 constexpr bool operator!=(const year_month_weekday_last& x,
519 const year_month_weekday_last& y) noexcept;
520 constexpr year_month_weekday_last
521 operator+(const year_month_weekday_last& ymwdl, const months& dm) noexcept;
522 constexpr year_month_weekday_last
523 operator+(const months& dm, const year_month_weekday_last& ymwdl) noexcept;
524 constexpr year_month_weekday_last
525 operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept;
526 constexpr year_month_weekday_last
527 operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept;
528 constexpr year_month_weekday_last
529 operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept;
530 constexpr year_month_weekday_last
531 operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept;
533 // 25.8.18, civil calendar conventional syntax operators // C++20
535 operator/(const year& y, const month& m) noexcept;
537 operator/(const year& y, int m) noexcept;
539 operator/(const month& m, const day& d) noexcept;
541 operator/(const month& m, int d) noexcept;
543 operator/(int m, const day& d) noexcept;
545 operator/(const day& d, const month& m) noexcept;
547 operator/(const day& d, int m) noexcept;
548 constexpr month_day_last
549 operator/(const month& m, last_spec) noexcept;
550 constexpr month_day_last
551 operator/(int m, last_spec) noexcept;
552 constexpr month_day_last
553 operator/(last_spec, const month& m) noexcept;
554 constexpr month_day_last
555 operator/(last_spec, int m) noexcept;
556 constexpr month_weekday
557 operator/(const month& m, const weekday_indexed& wdi) noexcept;
558 constexpr month_weekday
559 operator/(int m, const weekday_indexed& wdi) noexcept;
560 constexpr month_weekday
561 operator/(const weekday_indexed& wdi, const month& m) noexcept;
562 constexpr month_weekday
563 operator/(const weekday_indexed& wdi, int m) noexcept;
564 constexpr month_weekday_last
565 operator/(const month& m, const weekday_last& wdl) noexcept;
566 constexpr month_weekday_last
567 operator/(int m, const weekday_last& wdl) noexcept;
568 constexpr month_weekday_last
569 operator/(const weekday_last& wdl, const month& m) noexcept;
570 constexpr month_weekday_last
571 operator/(const weekday_last& wdl, int m) noexcept;
572 constexpr year_month_day
573 operator/(const year_month& ym, const day& d) noexcept;
574 constexpr year_month_day
575 operator/(const year_month& ym, int d) noexcept;
576 constexpr year_month_day
577 operator/(const year& y, const month_day& md) noexcept;
578 constexpr year_month_day
579 operator/(int y, const month_day& md) noexcept;
580 constexpr year_month_day
581 operator/(const month_day& md, const year& y) noexcept;
582 constexpr year_month_day
583 operator/(const month_day& md, int y) noexcept;
584 constexpr year_month_day_last
585 operator/(const year_month& ym, last_spec) noexcept;
586 constexpr year_month_day_last
587 operator/(const year& y, const month_day_last& mdl) noexcept;
588 constexpr year_month_day_last
589 operator/(int y, const month_day_last& mdl) noexcept;
590 constexpr year_month_day_last
591 operator/(const month_day_last& mdl, const year& y) noexcept;
592 constexpr year_month_day_last
593 operator/(const month_day_last& mdl, int y) noexcept;
594 constexpr year_month_weekday
595 operator/(const year_month& ym, const weekday_indexed& wdi) noexcept;
596 constexpr year_month_weekday
597 operator/(const year& y, const month_weekday& mwd) noexcept;
598 constexpr year_month_weekday
599 operator/(int y, const month_weekday& mwd) noexcept;
600 constexpr year_month_weekday
601 operator/(const month_weekday& mwd, const year& y) noexcept;
602 constexpr year_month_weekday
603 operator/(const month_weekday& mwd, int y) noexcept;
604 constexpr year_month_weekday_last
605 operator/(const year_month& ym, const weekday_last& wdl) noexcept;
606 constexpr year_month_weekday_last
607 operator/(const year& y, const month_weekday_last& mwdl) noexcept;
608 constexpr year_month_weekday_last
609 operator/(int y, const month_weekday_last& mwdl) noexcept;
610 constexpr year_month_weekday_last
611 operator/(const month_weekday_last& mwdl, const year& y) noexcept;
612 constexpr year_month_weekday_last
613 operator/(const month_weekday_last& mwdl, int y) noexcept;
615 // 25.9, class template time_of_day // C++20
616 template<class Duration> class time_of_day;
618 template<> class time_of_day<hours>;
619 template<> class time_of_day<minutes>;
620 template<> class time_of_day<seconds>;
621 template<class Rep, class Period> class time_of_day<duration<Rep, Period>>;
623 // 25.10.2, time zone database // C++20
627 // 25.10.2.3, time zone database access // C++20
628 const tzdb& get_tzdb();
629 tzdb_list& get_tzdb_list();
630 const time_zone* locate_zone(string_view tz_name);
631 const time_zone* current_zone();
633 // 25.10.2.4, remote time zone database support // C++20
634 const tzdb& reload_tzdb();
635 string remote_version();
637 // 25.10.3, exception classes // C++20
638 class nonexistent_local_time;
639 class ambiguous_local_time;
641 // 25.10.4, information classes // C++20
645 // 25.10.5, class time_zone // C++20
646 enum class choose {earliest, latest};
648 bool operator==(const time_zone& x, const time_zone& y) noexcept;
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;
655 // 25.10.6, class template zoned_traits // C++20
656 template<class T> struct zoned_traits;
658 // 25.10.7, class template zoned_time // C++20
659 template<class Duration, class TimeZonePtr = const time_zone*> class zoned_time;
660 using zoned_seconds = zoned_time<seconds>;
662 template<class Duration1, class Duration2, class TimeZonePtr>
663 bool operator==(const zoned_time<Duration1, TimeZonePtr>& x,
664 const zoned_time<Duration2, TimeZonePtr>& y);
665 template<class Duration1, class Duration2, class TimeZonePtr>
666 bool operator!=(const zoned_time<Duration1, TimeZonePtr>& x,
667 const zoned_time<Duration2, TimeZonePtr>& y);
669 // 25.10.8, leap second support // C++20
672 bool operator==(const leap& x, const leap& y);
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 template<class Duration>
679 bool operator==(const leap& x, const sys_time<Duration>& y);
680 template<class Duration>
681 bool operator==(const sys_time<Duration>& x, const leap& y);
682 template<class Duration>
683 bool operator!=(const leap& x, const sys_time<Duration>& y);
684 template<class Duration>
685 bool operator!=(const sys_time<Duration>& x, const leap& y);
686 template<class Duration>
687 bool operator< (const leap& x, const sys_time<Duration>& y);
688 template<class Duration>
689 bool operator< (const sys_time<Duration>& x, const leap& y);
690 template<class Duration>
691 bool operator> (const leap& x, const sys_time<Duration>& y);
692 template<class Duration>
693 bool operator> (const sys_time<Duration>& x, const leap& y);
694 template<class Duration>
695 bool operator<=(const leap& x, const sys_time<Duration>& y);
696 template<class Duration>
697 bool operator<=(const sys_time<Duration>& x, const leap& y);
698 template<class Duration>
699 bool operator>=(const leap& x, const sys_time<Duration>& y);
700 template<class Duration>
701 bool operator>=(const sys_time<Duration>& x, const leap& y);
703 // 25.10.9, class link // C++20
705 bool operator==(const link& x, const link& y);
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);
712 // 25.11, formatting // C++20
713 template<class charT, class Streamable>
715 format(const charT* fmt, const Streamable& s);
717 template<class charT, class Streamable>
719 format(const locale& loc, const charT* fmt, const Streamable& s);
721 template<class charT, class traits, class Alloc, class Streamable>
722 basic_string<charT, traits, Alloc>
723 format(const basic_string<charT, traits, Alloc>& fmt, const Streamable& s);
725 template<class charT, class traits, class Alloc, class Streamable>
726 basic_string<charT, traits, Alloc>
727 format(const locale& loc, const basic_string<charT, traits, Alloc>& fmt,
728 const Streamable& s);
730 // 25.12, parsing // C++20
731 template<class charT, class traits, class Alloc, class Parsable>
733 parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp);
735 template<class charT, class traits, class Alloc, class Parsable>
737 parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
738 basic_string<charT, traits, Alloc>& abbrev);
740 template<class charT, class traits, class Alloc, class Parsable>
742 parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
745 template<class charT, class traits, class Alloc, class Parsable>
747 parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
748 basic_string<charT, traits, Alloc>& abbrev, minutes& offset);
750 // calendrical constants
751 inline constexpr last_spec last{}; // C++20
752 inline constexpr chrono::weekday Sunday{0}; // C++20
753 inline constexpr chrono::weekday Monday{1}; // C++20
754 inline constexpr chrono::weekday Tuesday{2}; // C++20
755 inline constexpr chrono::weekday Wednesday{3}; // C++20
756 inline constexpr chrono::weekday Thursday{4}; // C++20
757 inline constexpr chrono::weekday Friday{5}; // C++20
758 inline constexpr chrono::weekday Saturday{6}; // C++20
760 inline constexpr chrono::month January{1}; // C++20
761 inline constexpr chrono::month February{2}; // C++20
762 inline constexpr chrono::month March{3}; // C++20
763 inline constexpr chrono::month April{4}; // C++20
764 inline constexpr chrono::month May{5}; // C++20
765 inline constexpr chrono::month June{6}; // C++20
766 inline constexpr chrono::month July{7}; // C++20
767 inline constexpr chrono::month August{8}; // C++20
768 inline constexpr chrono::month September{9}; // C++20
769 inline constexpr chrono::month October{10}; // C++20
770 inline constexpr chrono::month November{11}; // C++20
771 inline constexpr chrono::month December{12}; // C++20
774 inline namespace literals {
775 inline namespace chrono_literals {
776 constexpr chrono::hours operator ""h(unsigned long long); // C++14
777 constexpr chrono::duration<unspecified , ratio<3600,1>> operator ""h(long double); // C++14
778 constexpr chrono::minutes operator ""min(unsigned long long); // C++14
779 constexpr chrono::duration<unspecified , ratio<60,1>> operator ""min(long double); // C++14
780 constexpr chrono::seconds operator ""s(unsigned long long); // C++14
781 constexpr chrono::duration<unspecified > operator ""s(long double); // C++14
782 constexpr chrono::milliseconds operator ""ms(unsigned long long); // C++14
783 constexpr chrono::duration<unspecified , milli> operator ""ms(long double); // C++14
784 constexpr chrono::microseconds operator ""us(unsigned long long); // C++14
785 constexpr chrono::duration<unspecified , micro> operator ""us(long double); // C++14
786 constexpr chrono::nanoseconds operator ""ns(unsigned long long); // C++14
787 constexpr chrono::duration<unspecified , nano> operator ""ns(long double); // C++14
788 constexpr chrono::day operator ""d(unsigned long long d) noexcept; // C++20
789 constexpr chrono::year operator ""y(unsigned long long y) noexcept; // C++20
798 #include <type_traits>
803 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
804 #pragma GCC system_header
808 #include <__undef_macros>
810 #ifndef _LIBCPP_CXX03_LANG
811 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
812 struct _FilesystemClock;
813 _LIBCPP_END_NAMESPACE_FILESYSTEM
814 #endif // !_LIBCPP_CXX03_LANG
816 _LIBCPP_BEGIN_NAMESPACE_STD
821 template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TEMPLATE_VIS duration;
824 struct __is_duration : false_type {};
826 template <class _Rep, class _Period>
827 struct __is_duration<duration<_Rep, _Period> > : true_type {};
829 template <class _Rep, class _Period>
830 struct __is_duration<const duration<_Rep, _Period> > : true_type {};
832 template <class _Rep, class _Period>
833 struct __is_duration<volatile duration<_Rep, _Period> > : true_type {};
835 template <class _Rep, class _Period>
836 struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
840 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
841 struct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>,
842 chrono::duration<_Rep2, _Period2> >
844 typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
845 typename __ratio_gcd<_Period1, _Period2>::type> type;
852 template <class _FromDuration, class _ToDuration,
853 class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
854 bool = _Period::num == 1,
855 bool = _Period::den == 1>
856 struct __duration_cast;
858 template <class _FromDuration, class _ToDuration, class _Period>
859 struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
861 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
862 _ToDuration operator()(const _FromDuration& __fd) const
864 return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
868 template <class _FromDuration, class _ToDuration, class _Period>
869 struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
871 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
872 _ToDuration operator()(const _FromDuration& __fd) const
874 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
875 return _ToDuration(static_cast<typename _ToDuration::rep>(
876 static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
880 template <class _FromDuration, class _ToDuration, class _Period>
881 struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
883 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
884 _ToDuration operator()(const _FromDuration& __fd) const
886 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
887 return _ToDuration(static_cast<typename _ToDuration::rep>(
888 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
892 template <class _FromDuration, class _ToDuration, class _Period>
893 struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
895 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
896 _ToDuration operator()(const _FromDuration& __fd) const
898 typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
899 return _ToDuration(static_cast<typename _ToDuration::rep>(
900 static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
901 / static_cast<_Ct>(_Period::den)));
905 template <class _ToDuration, class _Rep, class _Period>
906 inline _LIBCPP_INLINE_VISIBILITY
910 __is_duration<_ToDuration>::value,
913 duration_cast(const duration<_Rep, _Period>& __fd)
915 return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
918 template <class _Rep>
919 struct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {};
921 #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
922 template <class _Rep>
923 _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool treat_as_floating_point_v
924 = treat_as_floating_point<_Rep>::value;
927 template <class _Rep>
928 struct _LIBCPP_TEMPLATE_VIS duration_values
931 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT {return _Rep(0);}
932 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() _NOEXCEPT {return numeric_limits<_Rep>::max();}
933 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() _NOEXCEPT {return numeric_limits<_Rep>::lowest();}
936 #if _LIBCPP_STD_VER > 14
937 template <class _ToDuration, class _Rep, class _Period>
938 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
941 __is_duration<_ToDuration>::value,
944 floor(const duration<_Rep, _Period>& __d)
946 _ToDuration __t = duration_cast<_ToDuration>(__d);
948 __t = __t - _ToDuration{1};
952 template <class _ToDuration, class _Rep, class _Period>
953 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
956 __is_duration<_ToDuration>::value,
959 ceil(const duration<_Rep, _Period>& __d)
961 _ToDuration __t = duration_cast<_ToDuration>(__d);
963 __t = __t + _ToDuration{1};
967 template <class _ToDuration, class _Rep, class _Period>
968 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
971 __is_duration<_ToDuration>::value,
974 round(const duration<_Rep, _Period>& __d)
976 _ToDuration __lower = floor<_ToDuration>(__d);
977 _ToDuration __upper = __lower + _ToDuration{1};
978 auto __lowerDiff = __d - __lower;
979 auto __upperDiff = __upper - __d;
980 if (__lowerDiff < __upperDiff)
982 if (__lowerDiff > __upperDiff)
984 return __lower.count() & 1 ? __upper : __lower;
990 template <class _Rep, class _Period>
991 class _LIBCPP_TEMPLATE_VIS duration
993 static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
994 static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
995 static_assert(_Period::num > 0, "duration period must be positive");
997 template <class _R1, class _R2>
1001 static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
1002 static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
1003 static const intmax_t __n1 = _R1::num / __gcd_n1_n2;
1004 static const intmax_t __d1 = _R1::den / __gcd_d1_d2;
1005 static const intmax_t __n2 = _R2::num / __gcd_n1_n2;
1006 static const intmax_t __d2 = _R2::den / __gcd_d1_d2;
1007 static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1);
1009 template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
1010 struct __mul // __overflow == false
1012 static const intmax_t value = _Xp * _Yp;
1015 template <intmax_t _Xp, intmax_t _Yp>
1016 struct __mul<_Xp, _Yp, true>
1018 static const intmax_t value = 1;
1022 static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
1023 typedef ratio<__mul<__n1, __d2, !value>::value,
1024 __mul<__n2, __d1, !value>::value> type;
1029 typedef typename _Period::type period;
1034 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1035 #ifndef _LIBCPP_CXX03_LANG
1036 duration() = default;
1041 template <class _Rep2>
1042 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1043 explicit duration(const _Rep2& __r,
1046 is_convertible<_Rep2, rep>::value &&
1047 (treat_as_floating_point<rep>::value ||
1048 !treat_as_floating_point<_Rep2>::value)
1053 template <class _Rep2, class _Period2>
1054 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1055 duration(const duration<_Rep2, _Period2>& __d,
1058 __no_overflow<_Period2, period>::value && (
1059 treat_as_floating_point<rep>::value ||
1060 (__no_overflow<_Period2, period>::type::den == 1 &&
1061 !treat_as_floating_point<_Rep2>::value))
1063 : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {}
1067 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
1071 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);}
1072 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);}
1073 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++() {++__rep_; return *this;}
1074 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator++(int) {return duration(__rep_++);}
1075 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--() {--__rep_; return *this;}
1076 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator--(int) {return duration(__rep_--);}
1078 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
1079 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
1081 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& rhs) {__rep_ *= rhs; 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 duration& rhs) {__rep_ %= rhs.count(); return *this;}
1088 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() _NOEXCEPT {return duration(duration_values<rep>::zero());}
1089 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() _NOEXCEPT {return duration(duration_values<rep>::min());}
1090 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() _NOEXCEPT {return duration(duration_values<rep>::max());}
1093 typedef duration<long long, nano> nanoseconds;
1094 typedef duration<long long, micro> microseconds;
1095 typedef duration<long long, milli> milliseconds;
1096 typedef duration<long long > seconds;
1097 typedef duration< long, ratio< 60> > minutes;
1098 typedef duration< long, ratio<3600> > hours;
1099 #if _LIBCPP_STD_VER > 17
1100 typedef duration< int, ratio_multiply<ratio<24>, hours::period>> days;
1101 typedef duration< int, ratio_multiply<ratio<7>, days::period>> weeks;
1102 typedef duration< int, ratio_multiply<ratio<146097, 400>, days::period>> years;
1103 typedef duration< int, ratio_divide<years::period, ratio<12>>> months;
1107 template <class _LhsDuration, class _RhsDuration>
1108 struct __duration_eq
1110 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1111 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
1113 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
1114 return _Ct(__lhs).count() == _Ct(__rhs).count();
1118 template <class _LhsDuration>
1119 struct __duration_eq<_LhsDuration, _LhsDuration>
1121 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1122 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
1123 {return __lhs.count() == __rhs.count();}
1126 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1127 inline _LIBCPP_INLINE_VISIBILITY
1130 operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1132 return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
1137 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1138 inline _LIBCPP_INLINE_VISIBILITY
1141 operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1143 return !(__lhs == __rhs);
1148 template <class _LhsDuration, class _RhsDuration>
1149 struct __duration_lt
1151 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1152 bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
1154 typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
1155 return _Ct(__lhs).count() < _Ct(__rhs).count();
1159 template <class _LhsDuration>
1160 struct __duration_lt<_LhsDuration, _LhsDuration>
1162 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1163 bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
1164 {return __lhs.count() < __rhs.count();}
1167 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1168 inline _LIBCPP_INLINE_VISIBILITY
1171 operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1173 return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
1178 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1179 inline _LIBCPP_INLINE_VISIBILITY
1182 operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1184 return __rhs < __lhs;
1189 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1190 inline _LIBCPP_INLINE_VISIBILITY
1193 operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1195 return !(__rhs < __lhs);
1200 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1201 inline _LIBCPP_INLINE_VISIBILITY
1204 operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1206 return !(__lhs < __rhs);
1211 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1212 inline _LIBCPP_INLINE_VISIBILITY
1214 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
1215 operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1217 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
1218 return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
1223 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1224 inline _LIBCPP_INLINE_VISIBILITY
1226 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
1227 operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1229 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
1230 return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
1235 template <class _Rep1, class _Period, class _Rep2>
1236 inline _LIBCPP_INLINE_VISIBILITY
1240 is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
1241 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
1243 operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
1245 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
1246 typedef duration<_Cr, _Period> _Cd;
1247 return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
1250 template <class _Rep1, class _Period, class _Rep2>
1251 inline _LIBCPP_INLINE_VISIBILITY
1255 is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
1256 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
1258 operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
1265 template <class _Rep1, class _Period, class _Rep2>
1266 inline _LIBCPP_INLINE_VISIBILITY
1270 !__is_duration<_Rep2>::value &&
1271 is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
1272 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
1274 operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
1276 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
1277 typedef duration<_Cr, _Period> _Cd;
1278 return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
1281 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1282 inline _LIBCPP_INLINE_VISIBILITY
1284 typename common_type<_Rep1, _Rep2>::type
1285 operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1287 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
1288 return _Ct(__lhs).count() / _Ct(__rhs).count();
1293 template <class _Rep1, class _Period, class _Rep2>
1294 inline _LIBCPP_INLINE_VISIBILITY
1298 !__is_duration<_Rep2>::value &&
1299 is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
1300 duration<typename common_type<_Rep1, _Rep2>::type, _Period>
1302 operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
1304 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
1305 typedef duration<_Cr, _Period> _Cd;
1306 return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
1309 template <class _Rep1, class _Period1, class _Rep2, class _Period2>
1310 inline _LIBCPP_INLINE_VISIBILITY
1312 typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
1313 operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1315 typedef typename common_type<_Rep1, _Rep2>::type _Cr;
1316 typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
1317 return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
1320 //////////////////////////////////////////////////////////
1321 ///////////////////// time_point /////////////////////////
1322 //////////////////////////////////////////////////////////
1324 template <class _Clock, class _Duration = typename _Clock::duration>
1325 class _LIBCPP_TEMPLATE_VIS time_point
1327 static_assert(__is_duration<_Duration>::value,
1328 "Second template parameter of time_point must be a std::chrono::duration");
1330 typedef _Clock clock;
1331 typedef _Duration duration;
1332 typedef typename duration::rep rep;
1333 typedef typename duration::period period;
1338 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
1339 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
1342 template <class _Duration2>
1343 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1344 time_point(const time_point<clock, _Duration2>& t,
1347 is_convertible<_Duration2, duration>::value
1349 : __d_(t.time_since_epoch()) {}
1353 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;}
1357 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
1358 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
1362 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() _NOEXCEPT {return time_point(duration::min());}
1363 _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() _NOEXCEPT {return time_point(duration::max());}
1368 template <class _Clock, class _Duration1, class _Duration2>
1369 struct _LIBCPP_TEMPLATE_VIS common_type<chrono::time_point<_Clock, _Duration1>,
1370 chrono::time_point<_Clock, _Duration2> >
1372 typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
1377 template <class _ToDuration, class _Clock, class _Duration>
1378 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1379 time_point<_Clock, _ToDuration>
1380 time_point_cast(const time_point<_Clock, _Duration>& __t)
1382 return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
1385 #if _LIBCPP_STD_VER > 14
1386 template <class _ToDuration, class _Clock, class _Duration>
1387 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1390 __is_duration<_ToDuration>::value,
1391 time_point<_Clock, _ToDuration>
1393 floor(const time_point<_Clock, _Duration>& __t)
1395 return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())};
1398 template <class _ToDuration, class _Clock, class _Duration>
1399 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1402 __is_duration<_ToDuration>::value,
1403 time_point<_Clock, _ToDuration>
1405 ceil(const time_point<_Clock, _Duration>& __t)
1407 return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())};
1410 template <class _ToDuration, class _Clock, class _Duration>
1411 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1414 __is_duration<_ToDuration>::value,
1415 time_point<_Clock, _ToDuration>
1417 round(const time_point<_Clock, _Duration>& __t)
1419 return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())};
1422 template <class _Rep, class _Period>
1423 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1426 numeric_limits<_Rep>::is_signed,
1427 duration<_Rep, _Period>
1429 abs(duration<_Rep, _Period> __d)
1431 return __d >= __d.zero() ? __d : -__d;
1437 template <class _Clock, class _Duration1, class _Duration2>
1438 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1440 operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1442 return __lhs.time_since_epoch() == __rhs.time_since_epoch();
1447 template <class _Clock, class _Duration1, class _Duration2>
1448 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1450 operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1452 return !(__lhs == __rhs);
1457 template <class _Clock, class _Duration1, class _Duration2>
1458 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1460 operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1462 return __lhs.time_since_epoch() < __rhs.time_since_epoch();
1467 template <class _Clock, class _Duration1, class _Duration2>
1468 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1470 operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1472 return __rhs < __lhs;
1477 template <class _Clock, class _Duration1, class _Duration2>
1478 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1480 operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1482 return !(__rhs < __lhs);
1487 template <class _Clock, class _Duration1, class _Duration2>
1488 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1490 operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1492 return !(__lhs < __rhs);
1495 // time_point operator+(time_point x, duration y);
1497 template <class _Clock, class _Duration1, class _Rep2, class _Period2>
1498 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1499 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
1500 operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1502 typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
1503 return _Tr (__lhs.time_since_epoch() + __rhs);
1506 // time_point operator+(duration x, time_point y);
1508 template <class _Rep1, class _Period1, class _Clock, class _Duration2>
1509 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1510 time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
1511 operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1513 return __rhs + __lhs;
1516 // time_point operator-(time_point x, duration y);
1518 template <class _Clock, class _Duration1, class _Rep2, class _Period2>
1519 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1520 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
1521 operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
1523 typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret;
1524 return _Ret(__lhs.time_since_epoch() -__rhs);
1527 // duration operator-(time_point x, time_point y);
1529 template <class _Clock, class _Duration1, class _Duration2>
1530 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1531 typename common_type<_Duration1, _Duration2>::type
1532 operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
1534 return __lhs.time_since_epoch() - __rhs.time_since_epoch();
1537 //////////////////////////////////////////////////////////
1538 /////////////////////// clocks ///////////////////////////
1539 //////////////////////////////////////////////////////////
1541 class _LIBCPP_TYPE_VIS system_clock
1544 typedef microseconds duration;
1545 typedef duration::rep rep;
1546 typedef duration::period period;
1547 typedef chrono::time_point<system_clock> time_point;
1548 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
1550 static time_point now() _NOEXCEPT;
1551 static time_t to_time_t (const time_point& __t) _NOEXCEPT;
1552 static time_point from_time_t(time_t __t) _NOEXCEPT;
1555 #ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
1556 class _LIBCPP_TYPE_VIS steady_clock
1559 typedef nanoseconds duration;
1560 typedef duration::rep rep;
1561 typedef duration::period period;
1562 typedef chrono::time_point<steady_clock, duration> time_point;
1563 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true;
1565 static time_point now() _NOEXCEPT;
1568 typedef steady_clock high_resolution_clock;
1570 typedef system_clock high_resolution_clock;
1573 #if _LIBCPP_STD_VER > 17
1574 // [time.clock.file], type file_clock
1575 using file_clock = _VSTD_FS::_FilesystemClock;
1577 template<class _Duration>
1578 using file_time = time_point<file_clock, _Duration>;
1581 template <class _Duration>
1582 using sys_time = time_point<system_clock, _Duration>;
1583 using sys_seconds = sys_time<seconds>;
1584 using sys_days = sys_time<days>;
1587 template<class Duration>
1588 using local_time = time_point<local_t, Duration>;
1589 using local_seconds = local_time<seconds>;
1590 using local_days = local_time<days>;
1593 struct last_spec { explicit last_spec() = default; };
1600 explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast<unsigned char>(__val)) {}
1601 inline constexpr day& operator++() noexcept { ++__d; return *this; }
1602 inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; }
1603 inline constexpr day& operator--() noexcept { --__d; return *this; }
1604 inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; }
1605 constexpr day& operator+=(const days& __dd) noexcept;
1606 constexpr day& operator-=(const days& __dd) noexcept;
1607 explicit inline constexpr operator unsigned() const noexcept { return __d; }
1608 inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; }
1613 bool operator==(const day& __lhs, const day& __rhs) noexcept
1614 { return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
1617 bool operator!=(const day& __lhs, const day& __rhs) noexcept
1618 { return !(__lhs == __rhs); }
1621 bool operator< (const day& __lhs, const day& __rhs) noexcept
1622 { return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); }
1625 bool operator> (const day& __lhs, const day& __rhs) noexcept
1626 { return __rhs < __lhs; }
1629 bool operator<=(const day& __lhs, const day& __rhs) noexcept
1630 { return !(__rhs < __lhs);}
1633 bool operator>=(const day& __lhs, const day& __rhs) noexcept
1634 { return !(__lhs < __rhs); }
1637 day operator+ (const day& __lhs, const days& __rhs) noexcept
1638 { return day(static_cast<unsigned>(__lhs) + __rhs.count()); }
1641 day operator+ (const days& __lhs, const day& __rhs) noexcept
1642 { return __rhs + __lhs; }
1645 day operator- (const day& __lhs, const days& __rhs) noexcept
1646 { return __lhs + -__rhs; }
1649 days operator-(const day& __lhs, const day& __rhs) noexcept
1650 { return days(static_cast<int>(static_cast<unsigned>(__lhs)) -
1651 static_cast<int>(static_cast<unsigned>(__rhs))); }
1653 inline constexpr day& day::operator+=(const days& __dd) noexcept
1654 { *this = *this + __dd; return *this; }
1656 inline constexpr day& day::operator-=(const days& __dd) noexcept
1657 { *this = *this - __dd; return *this; }
1665 explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast<unsigned char>(__val)) {}
1666 inline constexpr month& operator++() noexcept { ++__m; return *this; }
1667 inline constexpr month operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; }
1668 inline constexpr month& operator--() noexcept { --__m; return *this; }
1669 inline constexpr month operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; }
1670 constexpr month& operator+=(const months& __m1) noexcept;
1671 constexpr month& operator-=(const months& __m1) noexcept;
1672 explicit inline constexpr operator unsigned() const noexcept { return __m; }
1673 inline constexpr bool ok() const noexcept { return __m >= 1 && __m <= 12; }
1678 bool operator==(const month& __lhs, const month& __rhs) noexcept
1679 { return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
1682 bool operator!=(const month& __lhs, const month& __rhs) noexcept
1683 { return !(__lhs == __rhs); }
1686 bool operator< (const month& __lhs, const month& __rhs) noexcept
1687 { return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); }
1690 bool operator> (const month& __lhs, const month& __rhs) noexcept
1691 { return __rhs < __lhs; }
1694 bool operator<=(const month& __lhs, const month& __rhs) noexcept
1695 { return !(__rhs < __lhs); }
1698 bool operator>=(const month& __lhs, const month& __rhs) noexcept
1699 { return !(__lhs < __rhs); }
1702 month operator+ (const month& __lhs, const months& __rhs) noexcept
1704 auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1);
1705 auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12;
1706 return month{static_cast<unsigned>(__mu - __yr * 12 + 1)};
1710 month operator+ (const months& __lhs, const month& __rhs) noexcept
1711 { return __rhs + __lhs; }
1714 month operator- (const month& __lhs, const months& __rhs) noexcept
1715 { return __lhs + -__rhs; }
1718 months operator-(const month& __lhs, const month& __rhs) noexcept
1720 auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
1721 return months(__dm <= 11 ? __dm : __dm + 12);
1724 inline constexpr month& month::operator+=(const months& __dm) noexcept
1725 { *this = *this + __dm; return *this; }
1727 inline constexpr month& month::operator-=(const months& __dm) noexcept
1728 { *this = *this - __dm; return *this; }
1736 explicit inline constexpr year(int __val) noexcept : __y(static_cast<short>(__val)) {}
1738 inline constexpr year& operator++() noexcept { ++__y; return *this; }
1739 inline constexpr year operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; }
1740 inline constexpr year& operator--() noexcept { --__y; return *this; }
1741 inline constexpr year operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; }
1742 constexpr year& operator+=(const years& __dy) noexcept;
1743 constexpr year& operator-=(const years& __dy) noexcept;
1744 inline constexpr year operator+() const noexcept { return *this; }
1745 inline constexpr year operator-() const noexcept { return year{-__y}; }
1747 inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); }
1748 explicit inline constexpr operator int() const noexcept { return __y; }
1749 constexpr bool ok() const noexcept;
1750 static inline constexpr year min() noexcept { return year{-32767}; }
1751 static inline constexpr year max() noexcept { return year{ 32767}; }
1756 bool operator==(const year& __lhs, const year& __rhs) noexcept
1757 { return static_cast<int>(__lhs) == static_cast<int>(__rhs); }
1760 bool operator!=(const year& __lhs, const year& __rhs) noexcept
1761 { return !(__lhs == __rhs); }
1764 bool operator< (const year& __lhs, const year& __rhs) noexcept
1765 { return static_cast<int>(__lhs) < static_cast<int>(__rhs); }
1768 bool operator> (const year& __lhs, const year& __rhs) noexcept
1769 { return __rhs < __lhs; }
1772 bool operator<=(const year& __lhs, const year& __rhs) noexcept
1773 { return !(__rhs < __lhs); }
1776 bool operator>=(const year& __lhs, const year& __rhs) noexcept
1777 { return !(__lhs < __rhs); }
1780 year operator+ (const year& __lhs, const years& __rhs) noexcept
1781 { return year(static_cast<int>(__lhs) + __rhs.count()); }
1784 year operator+ (const years& __lhs, const year& __rhs) noexcept
1785 { return __rhs + __lhs; }
1788 year operator- (const year& __lhs, const years& __rhs) noexcept
1789 { return __lhs + -__rhs; }
1792 years operator-(const year& __lhs, const year& __rhs) noexcept
1793 { return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)}; }
1796 inline constexpr year& year::operator+=(const years& __dy) noexcept
1797 { *this = *this + __dy; return *this; }
1799 inline constexpr year& year::operator-=(const years& __dy) noexcept
1800 { *this = *this - __dy; return *this; }
1802 inline constexpr bool year::ok() const noexcept
1803 { return static_cast<int>(min()) <= __y && __y <= static_cast<int>(max()); }
1805 class weekday_indexed;
1812 weekday() = default;
1813 inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast<unsigned char>(__val)) {}
1814 inline constexpr weekday(const sys_days& __sysd) noexcept
1815 : __wd(__weekday_from_days(__sysd.time_since_epoch().count())) {}
1816 inline explicit constexpr weekday(const local_days& __locd) noexcept
1817 : __wd(__weekday_from_days(__locd.time_since_epoch().count())) {}
1819 inline constexpr weekday& operator++() noexcept { __wd = (__wd == 6 ? 0 : __wd + 1); return *this; }
1820 inline constexpr weekday operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; }
1821 inline constexpr weekday& operator--() noexcept { __wd = (__wd == 0 ? 6 : __wd - 1); return *this; }
1822 inline constexpr weekday operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; }
1823 constexpr weekday& operator+=(const days& __dd) noexcept;
1824 constexpr weekday& operator-=(const days& __dd) noexcept;
1825 inline explicit constexpr operator unsigned() const noexcept { return __wd; }
1826 inline constexpr bool ok() const noexcept { return __wd <= 6; }
1827 constexpr weekday_indexed operator[](unsigned __index) const noexcept;
1828 constexpr weekday_last operator[](last_spec) const noexcept;
1830 static constexpr unsigned char __weekday_from_days(int __days) noexcept;
1834 // https://howardhinnant.github.io/date_algorithms.html#weekday_from_days
1836 unsigned char weekday::__weekday_from_days(int __days) noexcept
1838 return static_cast<unsigned char>(
1839 static_cast<unsigned>(__days >= -4 ? (__days+4) % 7 : (__days+5) % 7 + 6)
1844 bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept
1845 { return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
1848 bool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept
1849 { return !(__lhs == __rhs); }
1852 bool operator< (const weekday& __lhs, const weekday& __rhs) noexcept
1853 { return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); }
1856 bool operator> (const weekday& __lhs, const weekday& __rhs) noexcept
1857 { return __rhs < __lhs; }
1860 bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept
1861 { return !(__rhs < __lhs);}
1864 bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept
1865 { return !(__lhs < __rhs); }
1867 constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept
1869 auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + __rhs.count();
1870 auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7;
1871 return weekday{static_cast<unsigned>(__mu - __yr * 7)};
1874 constexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept
1875 { return __rhs + __lhs; }
1877 constexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept
1878 { return __lhs + -__rhs; }
1880 constexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept
1882 const int __wdu = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
1883 const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7;
1884 return days{__wdu - __wk * 7};
1887 inline constexpr weekday& weekday::operator+=(const days& __dd) noexcept
1888 { *this = *this + __dd; return *this; }
1890 inline constexpr weekday& weekday::operator-=(const days& __dd) noexcept
1891 { *this = *this - __dd; return *this; }
1894 class weekday_indexed {
1896 _VSTD::chrono::weekday __wd;
1897 unsigned char __idx;
1899 weekday_indexed() = default;
1900 inline constexpr weekday_indexed(const _VSTD::chrono::weekday& __wdval, unsigned __idxval) noexcept
1901 : __wd{__wdval}, __idx(__idxval) {}
1902 inline constexpr _VSTD::chrono::weekday weekday() const noexcept { return __wd; }
1903 inline constexpr unsigned index() const noexcept { return __idx; }
1904 inline constexpr bool ok() const noexcept { return __wd.ok() && __idx >= 1 && __idx <= 5; }
1908 bool operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
1909 { return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); }
1912 bool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
1913 { return !(__lhs == __rhs); }
1916 class weekday_last {
1918 _VSTD::chrono::weekday __wd;
1920 explicit constexpr weekday_last(const _VSTD::chrono::weekday& __val) noexcept
1922 constexpr _VSTD::chrono::weekday weekday() const noexcept { return __wd; }
1923 constexpr bool ok() const noexcept { return __wd.ok(); }
1927 bool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
1928 { return __lhs.weekday() == __rhs.weekday(); }
1931 bool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
1932 { return !(__lhs == __rhs); }
1935 weekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; }
1938 weekday_last weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; }
1941 inline constexpr last_spec last{};
1942 inline constexpr weekday Sunday{0};
1943 inline constexpr weekday Monday{1};
1944 inline constexpr weekday Tuesday{2};
1945 inline constexpr weekday Wednesday{3};
1946 inline constexpr weekday Thursday{4};
1947 inline constexpr weekday Friday{5};
1948 inline constexpr weekday Saturday{6};
1950 inline constexpr month January{1};
1951 inline constexpr month February{2};
1952 inline constexpr month March{3};
1953 inline constexpr month April{4};
1954 inline constexpr month May{5};
1955 inline constexpr month June{6};
1956 inline constexpr month July{7};
1957 inline constexpr month August{8};
1958 inline constexpr month September{9};
1959 inline constexpr month October{10};
1960 inline constexpr month November{11};
1961 inline constexpr month December{12};
1969 month_day() = default;
1970 constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept
1971 : __m{__mval}, __d{__dval} {}
1972 inline constexpr chrono::month month() const noexcept { return __m; }
1973 inline constexpr chrono::day day() const noexcept { return __d; }
1974 constexpr bool ok() const noexcept;
1978 bool month_day::ok() const noexcept
1980 if (!__m.ok()) return false;
1981 const unsigned __dval = static_cast<unsigned>(__d);
1982 if (__dval < 1 || __dval > 31) return false;
1983 if (__dval <= 29) return true;
1984 // Now we've got either 30 or 31
1985 const unsigned __mval = static_cast<unsigned>(__m);
1986 if (__mval == 2) return false;
1987 if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11)
1988 return __dval == 30;
1993 bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept
1994 { return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
1997 bool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept
1998 { return !(__lhs == __rhs); }
2001 month_day operator/(const month& __lhs, const day& __rhs) noexcept
2002 { return month_day{__lhs, __rhs}; }
2005 month_day operator/(const day& __lhs, const month& __rhs) noexcept
2006 { return __rhs / __lhs; }
2009 month_day operator/(const month& __lhs, int __rhs) noexcept
2010 { return __lhs / day(__rhs); }
2013 month_day operator/(int __lhs, const day& __rhs) noexcept
2014 { return month(__lhs) / __rhs; }
2017 month_day operator/(const day& __lhs, int __rhs) noexcept
2018 { return month(__rhs) / __lhs; }
2022 bool operator< (const month_day& __lhs, const month_day& __rhs) noexcept
2023 { return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); }
2026 bool operator> (const month_day& __lhs, const month_day& __rhs) noexcept
2027 { return __rhs < __lhs; }
2030 bool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept
2031 { return !(__rhs < __lhs);}
2034 bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept
2035 { return !(__lhs < __rhs); }
2039 class month_day_last {
2043 explicit constexpr month_day_last(const chrono::month& __val) noexcept
2045 inline constexpr chrono::month month() const noexcept { return __m; }
2046 inline constexpr bool ok() const noexcept { return __m.ok(); }
2050 bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2051 { return __lhs.month() == __rhs.month(); }
2054 bool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2055 { return !(__lhs == __rhs); }
2058 bool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2059 { return __lhs.month() < __rhs.month(); }
2062 bool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2063 { return __rhs < __lhs; }
2066 bool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2067 { return !(__rhs < __lhs);}
2070 bool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2071 { return !(__lhs < __rhs); }
2074 month_day_last operator/(const month& __lhs, last_spec) noexcept
2075 { return month_day_last{__lhs}; }
2078 month_day_last operator/(last_spec, const month& __rhs) noexcept
2079 { return month_day_last{__rhs}; }
2082 month_day_last operator/(int __lhs, last_spec) noexcept
2083 { return month_day_last{month(__lhs)}; }
2086 month_day_last operator/(last_spec, int __rhs) noexcept
2087 { return month_day_last{month(__rhs)}; }
2090 class month_weekday {
2093 chrono::weekday_indexed __wdi;
2095 month_weekday() = default;
2096 constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept
2097 : __m{__mval}, __wdi{__wdival} {}
2098 inline constexpr chrono::month month() const noexcept { return __m; }
2099 inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
2100 inline constexpr bool ok() const noexcept { return __m.ok() && __wdi.ok(); }
2104 bool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
2105 { return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
2108 bool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
2109 { return !(__lhs == __rhs); }
2112 month_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept
2113 { return month_weekday{__lhs, __rhs}; }
2116 month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept
2117 { return month_weekday{month(__lhs), __rhs}; }
2120 month_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept
2121 { return month_weekday{__rhs, __lhs}; }
2124 month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept
2125 { return month_weekday{month(__rhs), __lhs}; }
2128 class month_weekday_last {
2130 chrono::weekday_last __wdl;
2132 constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept
2133 : __m{__mval}, __wdl{__wdlval} {}
2134 inline constexpr chrono::month month() const noexcept { return __m; }
2135 inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
2136 inline constexpr bool ok() const noexcept { return __m.ok() && __wdl.ok(); }
2140 bool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
2141 { return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
2144 bool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
2145 { return !(__lhs == __rhs); }
2149 month_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept
2150 { return month_weekday_last{__lhs, __rhs}; }
2153 month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept
2154 { return month_weekday_last{month(__lhs), __rhs}; }
2157 month_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept
2158 { return month_weekday_last{__rhs, __lhs}; }
2161 month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept
2162 { return month_weekday_last{month(__rhs), __lhs}; }
2169 year_month() = default;
2170 constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept
2171 : __y{__yval}, __m{__mval} {}
2172 inline constexpr chrono::year year() const noexcept { return __y; }
2173 inline constexpr chrono::month month() const noexcept { return __m; }
2174 inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m += __dm; return *this; }
2175 inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m -= __dm; return *this; }
2176 inline constexpr year_month& operator+=(const years& __dy) noexcept { this->__y += __dy; return *this; }
2177 inline constexpr year_month& operator-=(const years& __dy) noexcept { this->__y -= __dy; return *this; }
2178 inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok(); }
2182 year_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; }
2185 year_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; }
2188 bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept
2189 { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); }
2192 bool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept
2193 { return !(__lhs == __rhs); }
2196 bool operator< (const year_month& __lhs, const year_month& __rhs) noexcept
2197 { return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); }
2200 bool operator> (const year_month& __lhs, const year_month& __rhs) noexcept
2201 { return __rhs < __lhs; }
2204 bool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept
2205 { return !(__rhs < __lhs);}
2208 bool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept
2209 { return !(__lhs < __rhs); }
2211 constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept
2213 int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count();
2214 const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12;
2215 __dmi = __dmi - __dy * 12 + 1;
2216 return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi));
2219 constexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept
2220 { return __rhs + __lhs; }
2222 constexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept
2223 { return (__lhs.year() + __rhs) / __lhs.month(); }
2225 constexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept
2226 { return __rhs + __lhs; }
2228 constexpr months operator-(const year_month& __lhs, const year_month& __rhs) noexcept
2229 { return (__lhs.year() - __rhs.year()) + months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month())); }
2231 constexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept
2232 { return __lhs + -__rhs; }
2234 constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept
2235 { return __lhs + -__rhs; }
2237 class year_month_day_last;
2239 class year_month_day {
2245 year_month_day() = default;
2246 inline constexpr year_month_day(
2247 const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept
2248 : __y{__yval}, __m{__mval}, __d{__dval} {}
2249 constexpr year_month_day(const year_month_day_last& __ymdl) noexcept;
2250 inline constexpr year_month_day(const sys_days& __sysd) noexcept
2251 : year_month_day(__from_days(__sysd.time_since_epoch())) {}
2252 inline explicit constexpr year_month_day(const local_days& __locd) noexcept
2253 : year_month_day(__from_days(__locd.time_since_epoch())) {}
2255 constexpr year_month_day& operator+=(const months& __dm) noexcept;
2256 constexpr year_month_day& operator-=(const months& __dm) noexcept;
2257 constexpr year_month_day& operator+=(const years& __dy) noexcept;
2258 constexpr year_month_day& operator-=(const years& __dy) noexcept;
2260 inline constexpr chrono::year year() const noexcept { return __y; }
2261 inline constexpr chrono::month month() const noexcept { return __m; }
2262 inline constexpr chrono::day day() const noexcept { return __d; }
2263 inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
2264 inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
2266 constexpr bool ok() const noexcept;
2268 static constexpr year_month_day __from_days(days __d) noexcept;
2269 constexpr days __to_days() const noexcept;
2273 // https://howardhinnant.github.io/date_algorithms.html#civil_from_days
2276 year_month_day::__from_days(days __d) noexcept
2278 static_assert(std::numeric_limits<unsigned>::digits >= 18, "");
2279 static_assert(std::numeric_limits<int>::digits >= 20 , "");
2280 const int __z = __d.count() + 719468;
2281 const int __era = (__z >= 0 ? __z : __z - 146096) / 146097;
2282 const unsigned __doe = static_cast<unsigned>(__z - __era * 146097); // [0, 146096]
2283 const unsigned __yoe = (__doe - __doe/1460 + __doe/36524 - __doe/146096) / 365; // [0, 399]
2284 const int __yr = static_cast<int>(__yoe) + __era * 400;
2285 const unsigned __doy = __doe - (365 * __yoe + __yoe/4 - __yoe/100); // [0, 365]
2286 const unsigned __mp = (5 * __doy + 2)/153; // [0, 11]
2287 const unsigned __dy = __doy - (153 * __mp + 2)/5 + 1; // [1, 31]
2288 const unsigned __mth = __mp + (__mp < 10 ? 3 : -9); // [1, 12]
2289 return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}};
2292 // https://howardhinnant.github.io/date_algorithms.html#days_from_civil
2293 inline constexpr days year_month_day::__to_days() const noexcept
2295 static_assert(std::numeric_limits<unsigned>::digits >= 18, "");
2296 static_assert(std::numeric_limits<int>::digits >= 20 , "");
2298 const int __yr = static_cast<int>(__y) - (__m <= February);
2299 const unsigned __mth = static_cast<unsigned>(__m);
2300 const unsigned __dy = static_cast<unsigned>(__d);
2302 const int __era = (__yr >= 0 ? __yr : __yr - 399) / 400;
2303 const unsigned __yoe = static_cast<unsigned>(__yr - __era * 400); // [0, 399]
2304 const unsigned __doy = (153 * (__mth + (__mth > 2 ? -3 : 9)) + 2) / 5 + __dy-1; // [0, 365]
2305 const unsigned __doe = __yoe * 365 + __yoe/4 - __yoe/100 + __doy; // [0, 146096]
2306 return days{__era * 146097 + static_cast<int>(__doe) - 719468};
2310 bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2311 { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
2314 bool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2315 { return !(__lhs == __rhs); }
2318 bool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2320 if (__lhs.year() < __rhs.year()) return true;
2321 if (__lhs.year() > __rhs.year()) return false;
2322 if (__lhs.month() < __rhs.month()) return true;
2323 if (__lhs.month() > __rhs.month()) return false;
2324 return __lhs.day() < __rhs.day();
2328 bool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2329 { return __rhs < __lhs; }
2332 bool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2333 { return !(__rhs < __lhs);}
2336 bool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2337 { return !(__lhs < __rhs); }
2340 year_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept
2341 { return year_month_day{__lhs.year(), __lhs.month(), __rhs}; }
2344 year_month_day operator/(const year_month& __lhs, int __rhs) noexcept
2345 { return __lhs / day(__rhs); }
2348 year_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept
2349 { return __lhs / __rhs.month() / __rhs.day(); }
2352 year_month_day operator/(int __lhs, const month_day& __rhs) noexcept
2353 { return year(__lhs) / __rhs; }
2356 year_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept
2357 { return __rhs / __lhs; }
2360 year_month_day operator/(const month_day& __lhs, int __rhs) noexcept
2361 { return year(__rhs) / __lhs; }
2365 year_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept
2366 { return (__lhs.year()/__lhs.month() + __rhs)/__lhs.day(); }
2369 year_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept
2370 { return __rhs + __lhs; }
2373 year_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept
2374 { return __lhs + -__rhs; }
2377 year_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept
2378 { return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); }
2381 year_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept
2382 { return __rhs + __lhs; }
2385 year_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept
2386 { return __lhs + -__rhs; }
2388 inline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
2389 inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
2390 inline constexpr year_month_day& year_month_day::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
2391 inline constexpr year_month_day& year_month_day::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
2393 class year_month_day_last {
2396 chrono::month_day_last __mdl;
2398 constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept
2399 : __y{__yval}, __mdl{__mdlval} {}
2401 constexpr year_month_day_last& operator+=(const months& __m) noexcept;
2402 constexpr year_month_day_last& operator-=(const months& __m) noexcept;
2403 constexpr year_month_day_last& operator+=(const years& __y) noexcept;
2404 constexpr year_month_day_last& operator-=(const years& __y) noexcept;
2406 inline constexpr chrono::year year() const noexcept { return __y; }
2407 inline constexpr chrono::month month() const noexcept { return __mdl.month(); }
2408 inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl; }
2409 constexpr chrono::day day() const noexcept;
2410 inline constexpr operator sys_days() const noexcept { return sys_days{year()/month()/day()}; }
2411 inline explicit constexpr operator local_days() const noexcept { return local_days{year()/month()/day()}; }
2412 inline constexpr bool ok() const noexcept { return __y.ok() && __mdl.ok(); }
2416 chrono::day year_month_day_last::day() const noexcept
2418 constexpr chrono::day __d[] =
2420 chrono::day(31), chrono::day(28), chrono::day(31),
2421 chrono::day(30), chrono::day(31), chrono::day(30),
2422 chrono::day(31), chrono::day(31), chrono::day(30),
2423 chrono::day(31), chrono::day(30), chrono::day(31)
2425 return month() != February || !__y.is_leap() ?
2426 __d[static_cast<unsigned>(month()) - 1] : chrono::day{29};
2430 bool operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2431 { return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); }
2434 bool operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2435 { return !(__lhs == __rhs); }
2438 bool operator< (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2440 if (__lhs.year() < __rhs.year()) return true;
2441 if (__lhs.year() > __rhs.year()) return false;
2442 return __lhs.month_day_last() < __rhs.month_day_last();
2446 bool operator> (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2447 { return __rhs < __lhs; }
2450 bool operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2451 { return !(__rhs < __lhs);}
2454 bool operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2455 { return !(__lhs < __rhs); }
2457 inline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept
2458 { return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; }
2460 inline constexpr year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept
2461 { return year_month_day_last{__lhs, __rhs}; }
2463 inline constexpr year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept
2464 { return year_month_day_last{year{__lhs}, __rhs}; }
2466 inline constexpr year_month_day_last operator/(const month_day_last& __lhs, const year& __rhs) noexcept
2467 { return __rhs / __lhs; }
2469 inline constexpr year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept
2470 { return year{__rhs} / __lhs; }
2474 year_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept
2475 { return (__lhs.year() / __lhs.month() + __rhs) / last; }
2478 year_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept
2479 { return __rhs + __lhs; }
2482 year_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept
2483 { return __lhs + (-__rhs); }
2486 year_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept
2487 { return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; }
2490 year_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept
2491 { return __rhs + __lhs; }
2494 year_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept
2495 { return __lhs + (-__rhs); }
2497 inline constexpr year_month_day_last& year_month_day_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
2498 inline constexpr year_month_day_last& year_month_day_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
2499 inline constexpr year_month_day_last& year_month_day_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
2500 inline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
2502 inline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept
2503 : __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {}
2505 inline constexpr bool year_month_day::ok() const noexcept
2507 if (!__y.ok() || !__m.ok()) return false;
2508 return chrono::day{1} <= __d && __d <= (__y / __m / last).day();
2511 class year_month_weekday {
2514 chrono::weekday_indexed __wdi;
2516 year_month_weekday() = default;
2517 constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval,
2518 const chrono::weekday_indexed& __wdival) noexcept
2519 : __y{__yval}, __m{__mval}, __wdi{__wdival} {}
2520 constexpr year_month_weekday(const sys_days& __sysd) noexcept
2521 : year_month_weekday(__from_days(__sysd.time_since_epoch())) {}
2522 inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept
2523 : year_month_weekday(__from_days(__locd.time_since_epoch())) {}
2524 constexpr year_month_weekday& operator+=(const months& m) noexcept;
2525 constexpr year_month_weekday& operator-=(const months& m) noexcept;
2526 constexpr year_month_weekday& operator+=(const years& y) noexcept;
2527 constexpr year_month_weekday& operator-=(const years& y) noexcept;
2529 inline constexpr chrono::year year() const noexcept { return __y; }
2530 inline constexpr chrono::month month() const noexcept { return __m; }
2531 inline constexpr chrono::weekday weekday() const noexcept { return __wdi.weekday(); }
2532 inline constexpr unsigned index() const noexcept { return __wdi.index(); }
2533 inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
2535 inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
2536 inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
2537 inline constexpr bool ok() const noexcept
2539 if (!__y.ok() || !__m.ok() || !__wdi.ok()) return false;
2540 // TODO: make sure it's a valid date
2544 static constexpr year_month_weekday __from_days(days __d) noexcept;
2545 constexpr days __to_days() const noexcept;
2549 year_month_weekday year_month_weekday::__from_days(days __d) noexcept
2551 const sys_days __sysd{__d};
2552 const chrono::weekday __wd = chrono::weekday(__sysd);
2553 const year_month_day __ymd = year_month_day(__sysd);
2554 return year_month_weekday{__ymd.year(), __ymd.month(),
2555 __wd[(static_cast<unsigned>(__ymd.day())-1)/7+1]};
2559 days year_month_weekday::__to_days() const noexcept
2561 const sys_days __sysd = sys_days(__y/__m/1);
2562 return (__sysd + (__wdi.weekday() - chrono::weekday(__sysd) + days{(__wdi.index()-1)*7}))
2563 .time_since_epoch();
2567 bool operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
2568 { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
2571 bool operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
2572 { return !(__lhs == __rhs); }
2575 year_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept
2576 { return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; }
2579 year_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept
2580 { return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; }
2583 year_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept
2584 { return year(__lhs) / __rhs; }
2587 year_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept
2588 { return __rhs / __lhs; }
2591 year_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept
2592 { return year(__rhs) / __lhs; }
2596 year_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept
2597 { return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); }
2600 year_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept
2601 { return __rhs + __lhs; }
2604 year_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept
2605 { return __lhs + (-__rhs); }
2608 year_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept
2609 { return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; }
2612 year_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept
2613 { return __rhs + __lhs; }
2616 year_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept
2617 { return __lhs + (-__rhs); }
2620 inline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
2621 inline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
2622 inline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
2623 inline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
2625 class year_month_weekday_last {
2629 chrono::weekday_last __wdl;
2631 constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval,
2632 const chrono::weekday_last& __wdlval) noexcept
2633 : __y{__yval}, __m{__mval}, __wdl{__wdlval} {}
2634 constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept;
2635 constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept;
2636 constexpr year_month_weekday_last& operator+=(const years& __dy) noexcept;
2637 constexpr year_month_weekday_last& operator-=(const years& __dy) noexcept;
2639 inline constexpr chrono::year year() const noexcept { return __y; }
2640 inline constexpr chrono::month month() const noexcept { return __m; }
2641 inline constexpr chrono::weekday weekday() const noexcept { return __wdl.weekday(); }
2642 inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
2643 inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
2644 inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
2645 inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __wdl.ok(); }
2647 constexpr days __to_days() const noexcept;
2652 days year_month_weekday_last::__to_days() const noexcept
2654 const sys_days __last = sys_days{__y/__m/last};
2655 return (__last - (chrono::weekday{__last} - __wdl.weekday())).time_since_epoch();
2660 bool operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
2661 { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
2664 bool operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
2665 { return !(__lhs == __rhs); }
2669 year_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept
2670 { return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; }
2673 year_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept
2674 { return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; }
2677 year_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept
2678 { return year(__lhs) / __rhs; }
2681 year_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept
2682 { return __rhs / __lhs; }
2685 year_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept
2686 { return year(__rhs) / __lhs; }
2690 year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
2691 { return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); }
2694 year_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept
2695 { return __rhs + __lhs; }
2698 year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
2699 { return __lhs + (-__rhs); }
2702 year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
2703 { return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; }
2706 year_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept
2707 { return __rhs + __lhs; }
2710 year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
2711 { return __lhs + (-__rhs); }
2713 inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
2714 inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
2715 inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
2716 inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
2718 #endif // _LIBCPP_STD_VER > 17
2721 #if _LIBCPP_STD_VER > 11
2722 // Suffixes for duration literals [time.duration.literals]
2723 inline namespace literals
2725 inline namespace chrono_literals
2728 constexpr chrono::hours operator""h(unsigned long long __h)
2730 return chrono::hours(static_cast<chrono::hours::rep>(__h));
2733 constexpr chrono::duration<long double, ratio<3600,1>> operator""h(long double __h)
2735 return chrono::duration<long double, ratio<3600,1>>(__h);
2739 constexpr chrono::minutes operator""min(unsigned long long __m)
2741 return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
2744 constexpr chrono::duration<long double, ratio<60,1>> operator""min(long double __m)
2746 return chrono::duration<long double, ratio<60,1>> (__m);
2750 constexpr chrono::seconds operator""s(unsigned long long __s)
2752 return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
2755 constexpr chrono::duration<long double> operator""s(long double __s)
2757 return chrono::duration<long double> (__s);
2761 constexpr chrono::milliseconds operator""ms(unsigned long long __ms)
2763 return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
2766 constexpr chrono::duration<long double, milli> operator""ms(long double __ms)
2768 return chrono::duration<long double, milli>(__ms);
2772 constexpr chrono::microseconds operator""us(unsigned long long __us)
2774 return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
2777 constexpr chrono::duration<long double, micro> operator""us(long double __us)
2779 return chrono::duration<long double, micro> (__us);
2783 constexpr chrono::nanoseconds operator""ns(unsigned long long __ns)
2785 return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
2788 constexpr chrono::duration<long double, nano> operator""ns(long double __ns)
2790 return chrono::duration<long double, nano> (__ns);
2793 #if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS)
2794 constexpr chrono::day operator ""d(unsigned long long __d) noexcept
2796 return chrono::day(static_cast<unsigned>(__d));
2799 constexpr chrono::year operator ""y(unsigned long long __y) noexcept
2801 return chrono::year(static_cast<int>(__y));
2806 namespace chrono { // hoist the literals into namespace std::chrono
2807 using namespace literals::chrono_literals;
2812 _LIBCPP_END_NAMESPACE_STD
2814 #ifndef _LIBCPP_CXX03_LANG
2815 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
2816 struct _FilesystemClock {
2817 #if !defined(_LIBCPP_HAS_NO_INT128)
2818 typedef __int128_t rep;
2819 typedef nano period;
2821 typedef long long rep;
2822 typedef nano period;
2825 typedef chrono::duration<rep, period> duration;
2826 typedef chrono::time_point<_FilesystemClock> time_point;
2828 static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
2830 _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_FUNC_VIS static time_point now() noexcept;
2832 _LIBCPP_INLINE_VISIBILITY
2833 static time_t to_time_t(const time_point& __t) noexcept {
2834 typedef chrono::duration<rep> __secs;
2836 chrono::duration_cast<__secs>(__t.time_since_epoch()).count());
2839 _LIBCPP_INLINE_VISIBILITY
2840 static time_point from_time_t(time_t __t) noexcept {
2841 typedef chrono::duration<rep> __secs;
2842 return time_point(__secs(__t));
2845 _LIBCPP_END_NAMESPACE_FILESYSTEM
2846 #endif // !_LIBCPP_CXX03_LANG
2850 #endif // _LIBCPP_CHRONO