1// -*- C++ -*- 2//===----------------------------------------------------------------------===// 3// 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 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef _LIBCPP_CHRONO 11#define _LIBCPP_CHRONO 12 13// clang-format off 14 15/* 16 chrono synopsis 17 18#include <compare> // C++20 19 20namespace std 21{ 22namespace chrono 23{ 24 25template <class ToDuration, class Rep, class Period> 26constexpr 27ToDuration 28duration_cast(const duration<Rep, Period>& fd); 29 30template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {}; 31 32template <class Rep> inline constexpr bool treat_as_floating_point_v 33 = treat_as_floating_point<Rep>::value; // C++17 34 35template <class Rep> 36struct duration_values 37{ 38public: 39 static constexpr Rep zero(); // noexcept in C++20 40 static constexpr Rep max(); // noexcept in C++20 41 static constexpr Rep min(); // noexcept in C++20 42}; 43 44// duration 45 46template <class Rep, class Period = ratio<1>> 47class duration 48{ 49 static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration"); 50 static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio"); 51 static_assert(Period::num > 0, "duration period must be positive"); 52public: 53 typedef Rep rep; 54 typedef typename _Period::type period; 55 56 constexpr duration() = default; 57 template <class Rep2> 58 constexpr explicit duration(const Rep2& r, 59 typename enable_if 60 < 61 is_convertible<const Rep2&, rep>::value && 62 (treat_as_floating_point<rep>::value || 63 !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value) 64 >::type* = 0); 65 66 // conversions 67 template <class Rep2, class Period2> 68 constexpr duration(const duration<Rep2, Period2>& d, 69 typename enable_if 70 < 71 treat_as_floating_point<rep>::value || 72 ratio_divide<Period2, period>::type::den == 1 73 >::type* = 0); 74 75 // observer 76 77 constexpr rep count() const; 78 79 // arithmetic 80 81 constexpr common_type<duration>::type operator+() const; 82 constexpr common_type<duration>::type operator-() const; 83 constexpr duration& operator++(); // constexpr in C++17 84 constexpr duration operator++(int); // constexpr in C++17 85 constexpr duration& operator--(); // constexpr in C++17 86 constexpr duration operator--(int); // constexpr in C++17 87 88 constexpr duration& operator+=(const duration& d); // constexpr in C++17 89 constexpr duration& operator-=(const duration& d); // constexpr in C++17 90 91 duration& operator*=(const rep& rhs); // constexpr in C++17 92 duration& operator/=(const rep& rhs); // constexpr in C++17 93 duration& operator%=(const rep& rhs); // constexpr in C++17 94 duration& operator%=(const duration& rhs); // constexpr in C++17 95 96 // special values 97 98 static constexpr duration zero(); // noexcept in C++20 99 static constexpr duration min(); // noexcept in C++20 100 static constexpr duration max(); // noexcept in C++20 101}; 102 103typedef duration<long long, nano> nanoseconds; 104typedef duration<long long, micro> microseconds; 105typedef duration<long long, milli> milliseconds; 106typedef duration<long long > seconds; 107typedef duration< long, ratio< 60> > minutes; 108typedef duration< long, ratio<3600> > hours; 109 110template <class Clock, class Duration = typename Clock::duration> 111class time_point 112{ 113public: 114 typedef Clock clock; 115 typedef Duration duration; 116 typedef typename duration::rep rep; 117 typedef typename duration::period period; 118private: 119 duration d_; // exposition only 120 121public: 122 time_point(); // has value "epoch" // constexpr in C++14 123 explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14 124 125 // conversions 126 template <class Duration2> 127 time_point(const time_point<clock, Duration2>& t); // constexpr in C++14 128 129 // observer 130 131 duration time_since_epoch() const; // constexpr in C++14 132 133 // arithmetic 134 135 time_point& operator+=(const duration& d); // constexpr in C++17 136 time_point& operator-=(const duration& d); // constexpr in C++17 137 138 // special values 139 140 static constexpr time_point min(); // noexcept in C++20 141 static constexpr time_point max(); // noexcept in C++20 142}; 143 144} // chrono 145 146// common_type traits 147template <class Rep1, class Period1, class Rep2, class Period2> 148 struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>; 149 150template <class Clock, class Duration1, class Duration2> 151 struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>; 152 153namespace chrono { 154 155// duration arithmetic 156template <class Rep1, class Period1, class Rep2, class Period2> 157 constexpr 158 typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type 159 operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 160template <class Rep1, class Period1, class Rep2, class Period2> 161 constexpr 162 typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type 163 operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 164template <class Rep1, class Period, class Rep2> 165 constexpr 166 duration<typename common_type<Rep1, Rep2>::type, Period> 167 operator*(const duration<Rep1, Period>& d, const Rep2& s); 168template <class Rep1, class Period, class Rep2> 169 constexpr 170 duration<typename common_type<Rep1, Rep2>::type, Period> 171 operator*(const Rep1& s, const duration<Rep2, Period>& d); 172template <class Rep1, class Period, class Rep2> 173 constexpr 174 duration<typename common_type<Rep1, Rep2>::type, Period> 175 operator/(const duration<Rep1, Period>& d, const Rep2& s); 176template <class Rep1, class Period1, class Rep2, class Period2> 177 constexpr 178 typename common_type<Rep1, Rep2>::type 179 operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 180 181// duration comparisons 182template <class Rep1, class Period1, class Rep2, class Period2> 183 constexpr 184 bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 185template <class Rep1, class Period1, class Rep2, class Period2> 186 constexpr 187 bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); // removed in C++20 188template <class Rep1, class Period1, class Rep2, class Period2> 189 constexpr 190 bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 191template <class Rep1, class Period1, class Rep2, class Period2> 192 constexpr 193 bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 194template <class Rep1, class Period1, class Rep2, class Period2> 195 constexpr 196 bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 197template <class Rep1, class Period1, class Rep2, class Period2> 198 constexpr 199 bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 200template<class Rep1, class Period1, class Rep2, class Period2> 201 requires three_way_comparable<typename CT::rep> 202 constexpr auto operator<=>(const duration<Rep1, Period1>& lhs, 203 const duration<Rep2, Period2>& rhs); // since C++20 204 205// duration_cast 206template <class ToDuration, class Rep, class Period> 207 ToDuration duration_cast(const duration<Rep, Period>& d); 208 209template <class ToDuration, class Rep, class Period> 210 constexpr ToDuration floor(const duration<Rep, Period>& d); // C++17 211template <class ToDuration, class Rep, class Period> 212 constexpr ToDuration ceil(const duration<Rep, Period>& d); // C++17 213template <class ToDuration, class Rep, class Period> 214 constexpr ToDuration round(const duration<Rep, Period>& d); // C++17 215 216// duration I/O 217template<class charT, class traits, class Rep, class Period> // C++20 218 basic_ostream<charT, traits>& 219 operator<<(basic_ostream<charT, traits>& os, 220 const duration<Rep, Period>& d); 221 222// time_point arithmetic (all constexpr in C++14) 223template <class Clock, class Duration1, class Rep2, class Period2> 224 time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> 225 operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); 226template <class Rep1, class Period1, class Clock, class Duration2> 227 time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type> 228 operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs); 229template <class Clock, class Duration1, class Rep2, class Period2> 230 time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> 231 operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); 232template <class Clock, class Duration1, class Duration2> 233 typename common_type<Duration1, Duration2>::type 234 operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 235 236// time_point comparisons (all constexpr in C++14) 237template <class Clock, class Duration1, class Duration2> 238 bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 239template <class Clock, class Duration1, class Duration2> 240 bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); // removed in C++20 241template <class Clock, class Duration1, class Duration2> 242 bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 243template <class Clock, class Duration1, class Duration2> 244 bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 245template <class Clock, class Duration1, class Duration2> 246 bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 247template <class Clock, class Duration1, class Duration2> 248 bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 249template<class Clock, class Duration1, 250 three_way_comparable_with<Duration1> Duration2> 251 constexpr auto operator<=>(const time_point<Clock, Duration1>& lhs, 252 const time_point<Clock, Duration2>& rhs); // since C++20 253 254// time_point_cast (constexpr in C++14) 255 256template <class ToDuration, class Clock, class Duration> 257 time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t); 258 259template <class ToDuration, class Clock, class Duration> 260 constexpr time_point<Clock, ToDuration> 261 floor(const time_point<Clock, Duration>& tp); // C++17 262 263template <class ToDuration, class Clock, class Duration> 264 constexpr time_point<Clock, ToDuration> 265 ceil(const time_point<Clock, Duration>& tp); // C++17 266 267template <class ToDuration, class Clock, class Duration> 268 constexpr time_point<Clock, ToDuration> 269 round(const time_point<Clock, Duration>& tp); // C++17 270 271template <class Rep, class Period> 272 constexpr duration<Rep, Period> abs(duration<Rep, Period> d); // C++17 273 274// Clocks 275 276class system_clock 277{ 278public: 279 typedef microseconds duration; 280 typedef duration::rep rep; 281 typedef duration::period period; 282 typedef chrono::time_point<system_clock> time_point; 283 static const bool is_steady = false; // constexpr in C++14 284 285 static time_point now() noexcept; 286 static time_t to_time_t (const time_point& __t) noexcept; 287 static time_point from_time_t(time_t __t) noexcept; 288}; 289 290template <class Duration> 291 using sys_time = time_point<system_clock, Duration>; // C++20 292using sys_seconds = sys_time<seconds>; // C++20 293using sys_days = sys_time<days>; // C++20 294 295template<class charT, class traits, class Duration> // C++20 296 basic_ostream<charT, traits>& 297 operator<<(basic_ostream<charT, traits>& os, const sys_time<Duration>& tp); 298 299template<class charT, class traits> // C++20 300 basic_ostream<charT, traits>& 301 operator<<(basic_ostream<charT, traits>& os, const sys_days& dp); 302 303class file_clock // C++20 304{ 305public: 306 typedef see-below rep; 307 typedef nano period; 308 typedef chrono::duration<rep, period> duration; 309 typedef chrono::time_point<file_clock> time_point; 310 static constexpr bool is_steady = false; 311 312 static time_point now() noexcept; 313 314 template<class Duration> 315 static sys_time<see-below> to_sys(const file_time<Duration>&); 316 317 template<class Duration> 318 static file_time<see-below> from_sys(const sys_time<Duration>&); 319}; 320 321template<class Duration> 322 using file_time = time_point<file_clock, Duration>; // C++20 323 324template<class charT, class traits, class Duration> // C++20 325 basic_ostream<charT, traits>& 326 operator<<(basic_ostream<charT, traits>& os, const file_time<Duration>& tp); 327 328class steady_clock 329{ 330public: 331 typedef nanoseconds duration; 332 typedef duration::rep rep; 333 typedef duration::period period; 334 typedef chrono::time_point<steady_clock, duration> time_point; 335 static const bool is_steady = true; // constexpr in C++14 336 337 static time_point now() noexcept; 338}; 339 340typedef steady_clock high_resolution_clock; 341 342// 25.7.8, local time // C++20 343struct local_t {}; 344template<class Duration> 345 using local_time = time_point<local_t, Duration>; 346using local_seconds = local_time<seconds>; 347using local_days = local_time<days>; 348 349template<class charT, class traits, class Duration> // C++20 350 basic_ostream<charT, traits>& 351 operator<<(basic_ostream<charT, traits>& os, const local_time<Duration>& tp); 352 353// 25.8.2, class last_spec // C++20 354struct last_spec; 355 356// 25.8.3, class day // C++20 357 358class day; 359constexpr bool operator==(const day& x, const day& y) noexcept; 360constexpr strong_ordering operator<=>(const day& x, const day& y) noexcept; 361constexpr day operator+(const day& x, const days& y) noexcept; 362constexpr day operator+(const days& x, const day& y) noexcept; 363constexpr day operator-(const day& x, const days& y) noexcept; 364constexpr days operator-(const day& x, const day& y) noexcept; 365template<class charT, class traits> 366 basic_ostream<charT, traits>& 367 operator<<(basic_ostream<charT, traits>& os, const day& d); 368 369// 25.8.4, class month // C++20 370class month; 371constexpr bool operator==(const month& x, const month& y) noexcept; 372constexpr strong_ordering operator<=>(const month& x, const month& y) noexcept; 373 374constexpr month operator+(const month& x, const months& y) noexcept; 375constexpr month operator+(const months& x, const month& y) noexcept; 376constexpr month operator-(const month& x, const months& y) noexcept; 377constexpr months operator-(const month& x, const month& y) noexcept; 378template<class charT, class traits> 379 basic_ostream<charT, traits>& 380 operator<<(basic_ostream<charT, traits>& os, const month& m); 381 382// 25.8.5, class year // C++20 383class year; 384constexpr bool operator==(const year& x, const year& y) noexcept; 385constexpr strong_ordering operator<=>(const year& x, const year& y) noexcept; 386 387constexpr year operator+(const year& x, const years& y) noexcept; 388constexpr year operator+(const years& x, const year& y) noexcept; 389constexpr year operator-(const year& x, const years& y) noexcept; 390constexpr years operator-(const year& x, const year& y) noexcept; 391template<class charT, class traits> 392 basic_ostream<charT, traits>& 393 operator<<(basic_ostream<charT, traits>& os, const year& y); 394 395// 25.8.6, class weekday // C++20 396class weekday; 397 398constexpr bool operator==(const weekday& x, const weekday& y) noexcept; 399constexpr weekday operator+(const weekday& x, const days& y) noexcept; 400constexpr weekday operator+(const days& x, const weekday& y) noexcept; 401constexpr weekday operator-(const weekday& x, const days& y) noexcept; 402constexpr days operator-(const weekday& x, const weekday& y) noexcept; 403template<class charT, class traits> 404 basic_ostream<charT, traits>& 405 operator<<(basic_ostream<charT, traits>& os, const weekday& wd); 406 407// 25.8.7, class weekday_indexed // C++20 408 409class weekday_indexed; 410constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept; 411 412template<class charT, class traits> 413 basic_ostream<charT, traits>& 414 operator<<(basic_ostream<charT, traits>& os, const weekday_indexed& wdi); 415 416// 25.8.8, class weekday_last // C++20 417class weekday_last; 418 419constexpr bool operator==(const weekday_last& x, const weekday_last& y) noexcept; 420 421template<class charT, class traits> 422 basic_ostream<charT, traits>& 423 operator<<(basic_ostream<charT, traits>& os, const weekday_last& wdl); 424 425// 25.8.9, class month_day // C++20 426class month_day; 427 428constexpr bool operator==(const month_day& x, const month_day& y) noexcept; 429constexpr strong_ordering operator<=>(const month_day& x, const month_day& y) noexcept; 430 431template<class charT, class traits> 432 basic_ostream<charT, traits>& 433 operator<<(basic_ostream<charT, traits>& os, const month_day& md); 434 435// 25.8.10, class month_day_last // C++20 436class month_day_last; 437 438constexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept; 439constexpr strong_ordering operator<=>(const month_day_last& x, const month_day_last& y) noexcept; 440 441template<class charT, class traits> 442 basic_ostream<charT, traits>& 443 operator<<(basic_ostream<charT, traits>& os, const month_day_last& mdl); 444 445// 25.8.11, class month_weekday // C++20 446class month_weekday; 447 448constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept; 449 450template<class charT, class traits> 451 basic_ostream<charT, traits>& 452 operator<<(basic_ostream<charT, traits>& os, const month_weekday& mwd); 453 454// 25.8.12, class month_weekday_last // C++20 455class month_weekday_last; 456 457constexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept; 458 459template<class charT, class traits> 460 basic_ostream<charT, traits>& 461 operator<<(basic_ostream<charT, traits>& os, const month_weekday_last& mwdl); 462 463 464// 25.8.13, class year_month // C++20 465class year_month; 466 467constexpr bool operator==(const year_month& x, const year_month& y) noexcept; 468constexpr strong_ordering operator<=>(const year_month& x, const year_month& y) noexcept; 469 470constexpr year_month operator+(const year_month& ym, const months& dm) noexcept; 471constexpr year_month operator+(const months& dm, const year_month& ym) noexcept; 472constexpr year_month operator-(const year_month& ym, const months& dm) noexcept; 473constexpr months operator-(const year_month& x, const year_month& y) noexcept; 474constexpr year_month operator+(const year_month& ym, const years& dy) noexcept; 475constexpr year_month operator+(const years& dy, const year_month& ym) noexcept; 476constexpr year_month operator-(const year_month& ym, const years& dy) noexcept; 477 478template<class charT, class traits> 479 basic_ostream<charT, traits>& 480 operator<<(basic_ostream<charT, traits>& os, const year_month& ym); 481 482// 25.8.14, class year_month_day class // C++20 483year_month_day; 484 485constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept; 486constexpr strong_ordering operator<=>(const year_month_day& x, const year_month_day& y) noexcept; 487 488constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept; 489constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept; 490constexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept; 491constexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept; 492constexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept; 493constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept; 494 495template<class charT, class traits> 496 basic_ostream<charT, traits>& 497 operator<<(basic_ostream<charT, traits>& os, const year_month_day& ymd); 498 499// 25.8.15, class year_month_day_last // C++20 500class year_month_day_last; 501 502constexpr bool operator==(const year_month_day_last& x, const year_month_day_last& y) noexcept; 503constexpr strong_ordering operator<=>(const year_month_day_last_day& x, const year_month_day_last_day& y) noexcept; 504 505constexpr year_month_day_last 506 operator+(const year_month_day_last& ymdl, const months& dm) noexcept; 507constexpr year_month_day_last 508 operator+(const months& dm, const year_month_day_last& ymdl) noexcept; 509constexpr year_month_day_last 510 operator+(const year_month_day_last& ymdl, const years& dy) noexcept; 511constexpr year_month_day_last 512 operator+(const years& dy, const year_month_day_last& ymdl) noexcept; 513constexpr year_month_day_last 514 operator-(const year_month_day_last& ymdl, const months& dm) noexcept; 515constexpr year_month_day_last 516 operator-(const year_month_day_last& ymdl, const years& dy) noexcept; 517 518template<class charT, class traits> 519 basic_ostream<charT, traits>& 520 operator<<(basic_ostream<charT, traits>& os, const year_month_day_last& ymdl); 521 522// 25.8.16, class year_month_weekday // C++20 523class year_month_weekday; 524 525constexpr bool operator==(const year_month_weekday& x, 526 const year_month_weekday& y) noexcept; 527 528constexpr year_month_weekday 529 operator+(const year_month_weekday& ymwd, const months& dm) noexcept; 530constexpr year_month_weekday 531 operator+(const months& dm, const year_month_weekday& ymwd) noexcept; 532constexpr year_month_weekday 533 operator+(const year_month_weekday& ymwd, const years& dy) noexcept; 534constexpr year_month_weekday 535 operator+(const years& dy, const year_month_weekday& ymwd) noexcept; 536constexpr year_month_weekday 537 operator-(const year_month_weekday& ymwd, const months& dm) noexcept; 538constexpr year_month_weekday 539 operator-(const year_month_weekday& ymwd, const years& dy) noexcept; 540 541template<class charT, class traits> 542 basic_ostream<charT, traits>& 543 operator<<(basic_ostream<charT, traits>& os, const year_month_weekday& ymwd); 544 545// 25.8.17, class year_month_weekday_last // C++20 546class year_month_weekday_last; 547 548constexpr bool operator==(const year_month_weekday_last& x, 549 const year_month_weekday_last& y) noexcept; 550constexpr year_month_weekday_last 551 operator+(const year_month_weekday_last& ymwdl, const months& dm) noexcept; 552constexpr year_month_weekday_last 553 operator+(const months& dm, const year_month_weekday_last& ymwdl) noexcept; 554constexpr year_month_weekday_last 555 operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept; 556constexpr year_month_weekday_last 557 operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept; 558constexpr year_month_weekday_last 559 operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept; 560constexpr year_month_weekday_last 561 operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept; 562 563template<class charT, class traits> 564 basic_ostream<charT, traits>& 565 operator<<(basic_ostream<charT, traits>& os, const year_month_weekday_last& ymwdl); 566 567// 25.8.18, civil calendar conventional syntax operators // C++20 568constexpr year_month 569 operator/(const year& y, const month& m) noexcept; 570constexpr year_month 571 operator/(const year& y, int m) noexcept; 572constexpr month_day 573 operator/(const month& m, const day& d) noexcept; 574constexpr month_day 575 operator/(const month& m, int d) noexcept; 576constexpr month_day 577 operator/(int m, const day& d) noexcept; 578constexpr month_day 579 operator/(const day& d, const month& m) noexcept; 580constexpr month_day 581 operator/(const day& d, int m) noexcept; 582constexpr month_day_last 583 operator/(const month& m, last_spec) noexcept; 584constexpr month_day_last 585 operator/(int m, last_spec) noexcept; 586constexpr month_day_last 587 operator/(last_spec, const month& m) noexcept; 588constexpr month_day_last 589 operator/(last_spec, int m) noexcept; 590constexpr month_weekday 591 operator/(const month& m, const weekday_indexed& wdi) noexcept; 592constexpr month_weekday 593 operator/(int m, const weekday_indexed& wdi) noexcept; 594constexpr month_weekday 595 operator/(const weekday_indexed& wdi, const month& m) noexcept; 596constexpr month_weekday 597 operator/(const weekday_indexed& wdi, int m) noexcept; 598constexpr month_weekday_last 599 operator/(const month& m, const weekday_last& wdl) noexcept; 600constexpr month_weekday_last 601 operator/(int m, const weekday_last& wdl) noexcept; 602constexpr month_weekday_last 603 operator/(const weekday_last& wdl, const month& m) noexcept; 604constexpr month_weekday_last 605 operator/(const weekday_last& wdl, int m) noexcept; 606constexpr year_month_day 607 operator/(const year_month& ym, const day& d) noexcept; 608constexpr year_month_day 609 operator/(const year_month& ym, int d) noexcept; 610constexpr year_month_day 611 operator/(const year& y, const month_day& md) noexcept; 612constexpr year_month_day 613 operator/(int y, const month_day& md) noexcept; 614constexpr year_month_day 615 operator/(const month_day& md, const year& y) noexcept; 616constexpr year_month_day 617 operator/(const month_day& md, int y) noexcept; 618constexpr year_month_day_last 619 operator/(const year_month& ym, last_spec) noexcept; 620constexpr year_month_day_last 621 operator/(const year& y, const month_day_last& mdl) noexcept; 622constexpr year_month_day_last 623 operator/(int y, const month_day_last& mdl) noexcept; 624constexpr year_month_day_last 625 operator/(const month_day_last& mdl, const year& y) noexcept; 626constexpr year_month_day_last 627 operator/(const month_day_last& mdl, int y) noexcept; 628constexpr year_month_weekday 629 operator/(const year_month& ym, const weekday_indexed& wdi) noexcept; 630constexpr year_month_weekday 631 operator/(const year& y, const month_weekday& mwd) noexcept; 632constexpr year_month_weekday 633 operator/(int y, const month_weekday& mwd) noexcept; 634constexpr year_month_weekday 635 operator/(const month_weekday& mwd, const year& y) noexcept; 636constexpr year_month_weekday 637 operator/(const month_weekday& mwd, int y) noexcept; 638constexpr year_month_weekday_last 639 operator/(const year_month& ym, const weekday_last& wdl) noexcept; 640constexpr year_month_weekday_last 641 operator/(const year& y, const month_weekday_last& mwdl) noexcept; 642constexpr year_month_weekday_last 643 operator/(int y, const month_weekday_last& mwdl) noexcept; 644constexpr year_month_weekday_last 645 operator/(const month_weekday_last& mwdl, const year& y) noexcept; 646constexpr year_month_weekday_last 647 operator/(const month_weekday_last& mwdl, int y) noexcept; 648 649// 26.9, class template hh_mm_ss 650template <class Duration> 651class hh_mm_ss 652{ 653 bool is_neg; // exposition only 654 chrono::hours h; // exposition only 655 chrono::minutes m; // exposition only 656 chrono::seconds s; // exposition only 657 precision ss; // exposition only 658 659public: 660 static unsigned constexpr fractional_width = see below; 661 using precision = see below; 662 663 constexpr hh_mm_ss() noexcept : hh_mm_ss{Duration::zero()} {} 664 constexpr explicit hh_mm_ss(Duration d) noexcept; 665 666 constexpr bool is_negative() const noexcept; 667 constexpr chrono::hours hours() const noexcept; 668 constexpr chrono::minutes minutes() const noexcept; 669 constexpr chrono::seconds seconds() const noexcept; 670 constexpr precision subseconds() const noexcept; 671 672 constexpr explicit operator precision() const noexcept; 673 constexpr precision to_duration() const noexcept; 674}; 675 676template<class charT, class traits, class Duration> 677 basic_ostream<charT, traits>& 678 operator<<(basic_ostream<charT, traits>& os, const hh_mm_ss<Duration>& hms); // C++20 679 680// 26.10, 12/24 hour functions 681constexpr bool is_am(hours const& h) noexcept; 682constexpr bool is_pm(hours const& h) noexcept; 683constexpr hours make12(const hours& h) noexcept; 684constexpr hours make24(const hours& h, bool is_pm) noexcept; 685 686// [time.zone.db], time zone database 687struct tzdb { // C++20 688 string version; 689 vector<time_zone> zones; 690 vector<time_zone_link> links; 691 vector<leap_second> leap_seconds; 692 693 const time_zone* locate_zone(string_view tz_name) const; 694 const time_zone* current_zone() const; 695}; 696 697class tzdb_list { // C++20 698public: 699 tzdb_list(const tzdb_list&) = delete; 700 tzdb_list& operator=(const tzdb_list&) = delete; 701 702 // unspecified additional constructors 703 704 class const_iterator; 705 706 const tzdb& front() const noexcept; 707 708 const_iterator erase_after(const_iterator p); 709 710 const_iterator begin() const noexcept; 711 const_iterator end() const noexcept; 712 713 const_iterator cbegin() const noexcept; 714 const_iterator cend() const noexcept; 715}; 716 717// [time.zone.db.access], time zone database access 718const tzdb& get_tzdb(); // C++20 719tzdb_list& get_tzdb_list(); // C++20 720const time_zone* locate_zone(string_view tz_name); // C++20 721const time_zone* current_zone() // C++20 722 723// [time.zone.db.remote], remote time zone database support 724const tzdb& reload_tzdb(); // C++20 725string remote_version(); // C++20 726 727// [time.zone.exception], exception classes 728class nonexistent_local_time; // C++20 729class ambiguous_local_time; // C++20 730 731// [time.zone.info], information classes 732struct sys_info { // C++20 733 sys_seconds begin; 734 sys_seconds end; 735 seconds offset; 736 minutes save; 737 string abbrev; 738}; 739 740template<class charT, class traits> // C++20 741 basic_ostream<charT, traits>& 742 operator<<(basic_ostream<charT, traits>& os, const sys_info& si); 743 744struct local_info { // C++20 745 static constexpr int unique = 0; 746 static constexpr int nonexistent = 1; 747 static constexpr int ambiguous = 2; 748 749 int result; 750 sys_info first; 751 sys_info second; 752}; 753 754template<class charT, class traits> // C++20 755 basic_ostream<charT, traits>& 756 operator<<(basic_ostream<charT, traits>& os, const local_info& li); 757 758// 25.10.5, class time_zone // C++20 759enum class choose {earliest, latest}; 760class time_zone { 761 time_zone(time_zone&&) = default; 762 time_zone& operator=(time_zone&&) = default; 763 764 // unspecified additional constructors 765 766 string_view name() const noexcept; 767 768 template<class Duration> 769 sys_info get_info(const sys_time<Duration>& st) const; 770 771 template<class Duration> 772 local_info get_info(const local_time<Duration>& tp) const; 773 774 template<class Duration> 775 sys_time<common_type_t<Duration, seconds>> 776 to_sys(const local_time<Duration>& tp) const; 777 778 template<class Duration> 779 sys_time<common_type_t<Duration, seconds>> 780 to_sys(const local_time<Duration>& tp, choose z) const; 781 782 template<class Duration> 783 local_time<common_type_t<Duration, seconds>> 784 to_local(const sys_time<Duration>& tp) const; 785}; 786bool operator==(const time_zone& x, const time_zone& y) noexcept; // C++20 787strong_ordering operator<=>(const time_zone& x, const time_zone& y) noexcept; // C++20 788 789// [time.zone.zonedtraits], class template zoned_traits 790template<class T> struct zoned_traits; // C++20 791 792// [time.zone.zonedtime], class template zoned_time 793template<class Duration, class TimeZonePtr = const time_zone*> // C++20 794class zoned_time; 795 796using zoned_seconds = zoned_time<seconds>; // C++20 797 798template<class Duration1, class Duration2, class TimeZonePtr> // C++20 799 bool operator==(const zoned_time<Duration1, TimeZonePtr>& x, 800 const zoned_time<Duration2, TimeZonePtr>& y); 801 802template<class charT, class traits, class Duration, class TimeZonePtr> // C++20 803 basic_ostream<charT, traits>& 804 operator<<(basic_ostream<charT, traits>& os, 805 const zoned_time<Duration, TimeZonePtr>& t); 806 807// [time.zone.leap], leap second support 808class leap_second { // C++20 809public: 810 leap_second(const leap_second&) = default; 811 leap_second& operator=(const leap_second&) = default; 812 813 // unspecified additional constructors 814 815 constexpr sys_seconds date() const noexcept; 816 constexpr seconds value() const noexcept; 817}; 818 819constexpr bool operator==(const leap_second& x, const leap_second& y); // C++20 820constexpr strong_ordering operator<=>(const leap_second& x, const leap_second& y); 821 822template<class Duration> // C++20 823 constexpr bool operator==(const leap_second& x, const sys_time<Duration>& y); 824template<class Duration> // C++20 825 constexpr bool operator< (const leap_second& x, const sys_time<Duration>& y); 826template<class Duration> // C++20 827 constexpr bool operator< (const sys_time<Duration>& x, const leap_second& y); 828template<class Duration> // C++20 829 constexpr bool operator> (const leap_second& x, const sys_time<Duration>& y); 830template<class Duration> // C++20 831 constexpr bool operator> (const sys_time<Duration>& x, const leap_second& y); 832template<class Duration> // C++20 833 constexpr bool operator<=(const leap_second& x, const sys_time<Duration>& y); 834template<class Duration> // C++20 835 constexpr bool operator<=(const sys_time<Duration>& x, const leap_second& y); 836template<class Duration> // C++20 837 constexpr bool operator>=(const leap_second& x, const sys_time<Duration>& y); 838template<class Duration> // C++20 839 constexpr bool operator>=(const sys_time<Duration>& x, const leap_second& y); 840template<class Duration> // C++20 841 requires three_way_comparable_with<sys_seconds, sys_time<Duration>> 842 constexpr auto operator<=>(const leap_second& x, const sys_time<Duration>& y); 843 844// [time.zone.link], class time_zone_link 845class time_zone_link { // C++20 846public: 847 time_zone_link(time_zone_link&&) = default; 848 time_zone_link& operator=(time_zone_link&&) = default; 849 850 // unspecified additional constructors 851 852 string_view name() const noexcept; 853 string_view target() const noexcept; 854}; 855 856bool operator==(const time_zone_link& x, const time_zone_link& y); // C++20 857strong_ordering operator<=>(const time_zone_link& x, const time_zone_link& y); // C++20 858 859} // chrono 860 861namespace std { 862 template<class Duration, class charT> 863 struct formatter<chrono::sys_time<Duration>, charT>; // C++20 864 template<class Duration, class charT> 865 struct formatter<chrono::filetime<Duration>, charT>; // C++20 866 template<class Duration, class charT> 867 struct formatter<chrono::local_time<Duration>, charT>; // C++20 868 template<class Rep, class Period, class charT> 869 struct formatter<chrono::duration<Rep, Period>, charT>; // C++20 870 template<class charT> struct formatter<chrono::day, charT>; // C++20 871 template<class charT> struct formatter<chrono::month, charT>; // C++20 872 template<class charT> struct formatter<chrono::year, charT>; // C++20 873 template<class charT> struct formatter<chrono::weekday, charT>; // C++20 874 template<class charT> struct formatter<chrono::weekday_indexed, charT>; // C++20 875 template<class charT> struct formatter<chrono::weekday_last, charT>; // C++20 876 template<class charT> struct formatter<chrono::month_day, charT>; // C++20 877 template<class charT> struct formatter<chrono::month_day_last, charT>; // C++20 878 template<class charT> struct formatter<chrono::month_weekday, charT>; // C++20 879 template<class charT> struct formatter<chrono::month_weekday_last, charT>; // C++20 880 template<class charT> struct formatter<chrono::year_month, charT>; // C++20 881 template<class charT> struct formatter<chrono::year_month_day, charT>; // C++20 882 template<class charT> struct formatter<chrono::year_month_day_last, charT>; // C++20 883 template<class charT> struct formatter<chrono::year_month_weekday, charT>; // C++20 884 template<class charT> struct formatter<chrono::year_month_weekday_last, charT>; // C++20 885 template<class Rep, class Period, class charT> 886 struct formatter<chrono::hh_mm_ss<duration<Rep, Period>>, charT>; // C++20 887 template<class charT> struct formatter<chrono::sys_info, charT>; // C++20 888 template<class charT> struct formatter<chrono::local_info, charT>; // C++20 889 template<class Duration, class TimeZonePtr, class charT> // C++20 890 struct formatter<chrono::zoned_time<Duration, TimeZonePtr>, charT>; 891} // namespace std 892 893namespace chrono { 894// calendrical constants 895inline constexpr last_spec last{}; // C++20 896inline constexpr chrono::weekday Sunday{0}; // C++20 897inline constexpr chrono::weekday Monday{1}; // C++20 898inline constexpr chrono::weekday Tuesday{2}; // C++20 899inline constexpr chrono::weekday Wednesday{3}; // C++20 900inline constexpr chrono::weekday Thursday{4}; // C++20 901inline constexpr chrono::weekday Friday{5}; // C++20 902inline constexpr chrono::weekday Saturday{6}; // C++20 903 904inline constexpr chrono::month January{1}; // C++20 905inline constexpr chrono::month February{2}; // C++20 906inline constexpr chrono::month March{3}; // C++20 907inline constexpr chrono::month April{4}; // C++20 908inline constexpr chrono::month May{5}; // C++20 909inline constexpr chrono::month June{6}; // C++20 910inline constexpr chrono::month July{7}; // C++20 911inline constexpr chrono::month August{8}; // C++20 912inline constexpr chrono::month September{9}; // C++20 913inline constexpr chrono::month October{10}; // C++20 914inline constexpr chrono::month November{11}; // C++20 915inline constexpr chrono::month December{12}; // C++20 916} // chrono 917 918inline namespace literals { 919 inline namespace chrono_literals { 920constexpr chrono::hours operator ""h(unsigned long long); // C++14 921constexpr chrono::duration<unspecified , ratio<3600,1>> operator ""h(long double); // C++14 922constexpr chrono::minutes operator ""min(unsigned long long); // C++14 923constexpr chrono::duration<unspecified , ratio<60,1>> operator ""min(long double); // C++14 924constexpr chrono::seconds operator ""s(unsigned long long); // C++14 925constexpr chrono::duration<unspecified > operator ""s(long double); // C++14 926constexpr chrono::milliseconds operator ""ms(unsigned long long); // C++14 927constexpr chrono::duration<unspecified , milli> operator ""ms(long double); // C++14 928constexpr chrono::microseconds operator ""us(unsigned long long); // C++14 929constexpr chrono::duration<unspecified , micro> operator ""us(long double); // C++14 930constexpr chrono::nanoseconds operator ""ns(unsigned long long); // C++14 931constexpr chrono::duration<unspecified , nano> operator ""ns(long double); // C++14 932constexpr chrono::day operator ""d(unsigned long long d) noexcept; // C++20 933constexpr chrono::year operator ""y(unsigned long long y) noexcept; // C++20 934} // chrono_literals 935} // literals 936 937} // std 938*/ 939 940// clang-format on 941 942#include <__config> 943 944#include <__chrono/duration.h> 945#include <__chrono/file_clock.h> 946#include <__chrono/high_resolution_clock.h> 947#include <__chrono/steady_clock.h> 948#include <__chrono/system_clock.h> 949#include <__chrono/time_point.h> 950 951#if _LIBCPP_STD_VER >= 20 952# include <__chrono/calendar.h> 953# include <__chrono/day.h> 954# include <__chrono/exception.h> 955# include <__chrono/hh_mm_ss.h> 956# include <__chrono/literals.h> 957# include <__chrono/local_info.h> 958# include <__chrono/month.h> 959# include <__chrono/month_weekday.h> 960# include <__chrono/monthday.h> 961# include <__chrono/sys_info.h> 962# include <__chrono/weekday.h> 963# include <__chrono/year.h> 964# include <__chrono/year_month.h> 965# include <__chrono/year_month_day.h> 966# include <__chrono/year_month_weekday.h> 967 968# if !defined(_LIBCPP_HAS_NO_LOCALIZATION) 969# include <__chrono/formatter.h> 970# include <__chrono/ostream.h> 971# include <__chrono/parser_std_format_spec.h> 972# include <__chrono/statically_widen.h> 973# endif 974 975# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ 976 !defined(_LIBCPP_HAS_NO_LOCALIZATION) 977# include <__chrono/leap_second.h> 978# include <__chrono/time_zone.h> 979# include <__chrono/time_zone_link.h> 980# include <__chrono/tzdb.h> 981# include <__chrono/tzdb_list.h> 982# include <__chrono/zoned_time.h> 983# endif 984 985#endif 986 987#include <version> 988 989// standard-mandated includes 990 991// [time.syn] 992#include <compare> 993 994#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 995# pragma GCC system_header 996#endif 997 998#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17 999# include <cstdint> 1000# include <stdexcept> 1001# include <string_view> 1002# include <vector> 1003#endif 1004 1005#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 1006# include <bit> 1007# include <concepts> 1008# include <cstring> 1009# include <forward_list> 1010# include <string> 1011# include <tuple> 1012#endif 1013 1014#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER == 20 1015# include <charconv> 1016# if !defined(_LIBCPP_HAS_NO_LOCALIZATION) 1017# include <locale> 1018# include <ostream> 1019# endif 1020#endif 1021 1022#endif // _LIBCPP_CHRONO 1023