chrono 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  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. #ifndef _LIBCPP_CHRONO
  10. #define _LIBCPP_CHRONO
  11. /*
  12. chrono synopsis
  13. #include <compare> // C++20
  14. namespace std
  15. {
  16. namespace chrono
  17. {
  18. template <class ToDuration, class Rep, class Period>
  19. constexpr
  20. ToDuration
  21. duration_cast(const duration<Rep, Period>& fd);
  22. template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {};
  23. template <class Rep> inline constexpr bool treat_as_floating_point_v
  24. = treat_as_floating_point<Rep>::value; // C++17
  25. template <class Rep>
  26. struct duration_values
  27. {
  28. public:
  29. static constexpr Rep zero(); // noexcept in C++20
  30. static constexpr Rep max(); // noexcept in C++20
  31. static constexpr Rep min(); // noexcept in C++20
  32. };
  33. // duration
  34. template <class Rep, class Period = ratio<1>>
  35. class duration
  36. {
  37. static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration");
  38. static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio");
  39. static_assert(Period::num > 0, "duration period must be positive");
  40. public:
  41. typedef Rep rep;
  42. typedef typename _Period::type period;
  43. constexpr duration() = default;
  44. template <class Rep2>
  45. constexpr explicit duration(const Rep2& r,
  46. typename enable_if
  47. <
  48. is_convertible<Rep2, rep>::value &&
  49. (treat_as_floating_point<rep>::value ||
  50. !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value)
  51. >::type* = 0);
  52. // conversions
  53. template <class Rep2, class Period2>
  54. constexpr duration(const duration<Rep2, Period2>& d,
  55. typename enable_if
  56. <
  57. treat_as_floating_point<rep>::value ||
  58. ratio_divide<Period2, period>::type::den == 1
  59. >::type* = 0);
  60. // observer
  61. constexpr rep count() const;
  62. // arithmetic
  63. constexpr common_type<duration>::type operator+() const;
  64. constexpr common_type<duration>::type operator-() const;
  65. constexpr duration& operator++(); // constexpr in C++17
  66. constexpr duration operator++(int); // constexpr in C++17
  67. constexpr duration& operator--(); // constexpr in C++17
  68. constexpr duration operator--(int); // constexpr in C++17
  69. constexpr duration& operator+=(const duration& d); // constexpr in C++17
  70. constexpr duration& operator-=(const duration& d); // constexpr in C++17
  71. duration& operator*=(const rep& rhs); // constexpr in C++17
  72. duration& operator/=(const rep& rhs); // constexpr in C++17
  73. duration& operator%=(const rep& rhs); // constexpr in C++17
  74. duration& operator%=(const duration& rhs); // constexpr in C++17
  75. // special values
  76. static constexpr duration zero(); // noexcept in C++20
  77. static constexpr duration min(); // noexcept in C++20
  78. static constexpr duration max(); // noexcept in C++20
  79. };
  80. typedef duration<long long, nano> nanoseconds;
  81. typedef duration<long long, micro> microseconds;
  82. typedef duration<long long, milli> milliseconds;
  83. typedef duration<long long > seconds;
  84. typedef duration< long, ratio< 60> > minutes;
  85. typedef duration< long, ratio<3600> > hours;
  86. template <class Clock, class Duration = typename Clock::duration>
  87. class time_point
  88. {
  89. public:
  90. typedef Clock clock;
  91. typedef Duration duration;
  92. typedef typename duration::rep rep;
  93. typedef typename duration::period period;
  94. private:
  95. duration d_; // exposition only
  96. public:
  97. time_point(); // has value "epoch" // constexpr in C++14
  98. explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14
  99. // conversions
  100. template <class Duration2>
  101. time_point(const time_point<clock, Duration2>& t); // constexpr in C++14
  102. // observer
  103. duration time_since_epoch() const; // constexpr in C++14
  104. // arithmetic
  105. time_point& operator+=(const duration& d); // constexpr in C++17
  106. time_point& operator-=(const duration& d); // constexpr in C++17
  107. // special values
  108. static constexpr time_point min(); // noexcept in C++20
  109. static constexpr time_point max(); // noexcept in C++20
  110. };
  111. } // chrono
  112. // common_type traits
  113. template <class Rep1, class Period1, class Rep2, class Period2>
  114. struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>;
  115. template <class Clock, class Duration1, class Duration2>
  116. struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>;
  117. namespace chrono {
  118. // duration arithmetic
  119. template <class Rep1, class Period1, class Rep2, class Period2>
  120. constexpr
  121. typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
  122. operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  123. template <class Rep1, class Period1, class Rep2, class Period2>
  124. constexpr
  125. typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
  126. operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  127. template <class Rep1, class Period, class Rep2>
  128. constexpr
  129. duration<typename common_type<Rep1, Rep2>::type, Period>
  130. operator*(const duration<Rep1, Period>& d, const Rep2& s);
  131. template <class Rep1, class Period, class Rep2>
  132. constexpr
  133. duration<typename common_type<Rep1, Rep2>::type, Period>
  134. operator*(const Rep1& s, const duration<Rep2, Period>& d);
  135. template <class Rep1, class Period, class Rep2>
  136. constexpr
  137. duration<typename common_type<Rep1, Rep2>::type, Period>
  138. operator/(const duration<Rep1, Period>& d, const Rep2& s);
  139. template <class Rep1, class Period1, class Rep2, class Period2>
  140. constexpr
  141. typename common_type<Rep1, Rep2>::type
  142. operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  143. // duration comparisons
  144. template <class Rep1, class Period1, class Rep2, class Period2>
  145. constexpr
  146. bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  147. template <class Rep1, class Period1, class Rep2, class Period2>
  148. constexpr
  149. bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); // removed in C++20
  150. template <class Rep1, class Period1, class Rep2, class Period2>
  151. constexpr
  152. bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  153. template <class Rep1, class Period1, class Rep2, class Period2>
  154. constexpr
  155. bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  156. template <class Rep1, class Period1, class Rep2, class Period2>
  157. constexpr
  158. bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  159. template <class Rep1, class Period1, class Rep2, class Period2>
  160. constexpr
  161. bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
  162. template<class Rep1, class Period1, class Rep2, class Period2>
  163. requires three_way_comparable<typename CT::rep>
  164. constexpr auto operator<=>(const duration<Rep1, Period1>& lhs,
  165. const duration<Rep2, Period2>& rhs); // since C++20
  166. // duration_cast
  167. template <class ToDuration, class Rep, class Period>
  168. ToDuration duration_cast(const duration<Rep, Period>& d);
  169. template <class ToDuration, class Rep, class Period>
  170. constexpr ToDuration floor(const duration<Rep, Period>& d); // C++17
  171. template <class ToDuration, class Rep, class Period>
  172. constexpr ToDuration ceil(const duration<Rep, Period>& d); // C++17
  173. template <class ToDuration, class Rep, class Period>
  174. constexpr ToDuration round(const duration<Rep, Period>& d); // C++17
  175. // duration I/O
  176. template<class charT, class traits, class Rep, class Period> // C++20
  177. basic_ostream<charT, traits>&
  178. operator<<(basic_ostream<charT, traits>& os,
  179. const duration<Rep, Period>& d);
  180. // time_point arithmetic (all constexpr in C++14)
  181. template <class Clock, class Duration1, class Rep2, class Period2>
  182. time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
  183. operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
  184. template <class Rep1, class Period1, class Clock, class Duration2>
  185. time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
  186. operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
  187. template <class Clock, class Duration1, class Rep2, class Period2>
  188. time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
  189. operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
  190. template <class Clock, class Duration1, class Duration2>
  191. typename common_type<Duration1, Duration2>::type
  192. operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  193. // time_point comparisons (all constexpr in C++14)
  194. template <class Clock, class Duration1, class Duration2>
  195. bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  196. template <class Clock, class Duration1, class Duration2>
  197. bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); // removed in C++20
  198. template <class Clock, class Duration1, class Duration2>
  199. bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  200. template <class Clock, class Duration1, class Duration2>
  201. bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  202. template <class Clock, class Duration1, class Duration2>
  203. bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  204. template <class Clock, class Duration1, class Duration2>
  205. bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
  206. template<class Clock, class Duration1,
  207. three_way_comparable_with<Duration1> Duration2>
  208. constexpr auto operator<=>(const time_point<Clock, Duration1>& lhs,
  209. const time_point<Clock, Duration2>& rhs); // since C++20
  210. // time_point_cast (constexpr in C++14)
  211. template <class ToDuration, class Clock, class Duration>
  212. time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
  213. template <class ToDuration, class Clock, class Duration>
  214. constexpr time_point<Clock, ToDuration>
  215. floor(const time_point<Clock, Duration>& tp); // C++17
  216. template <class ToDuration, class Clock, class Duration>
  217. constexpr time_point<Clock, ToDuration>
  218. ceil(const time_point<Clock, Duration>& tp); // C++17
  219. template <class ToDuration, class Clock, class Duration>
  220. constexpr time_point<Clock, ToDuration>
  221. round(const time_point<Clock, Duration>& tp); // C++17
  222. template <class Rep, class Period>
  223. constexpr duration<Rep, Period> abs(duration<Rep, Period> d); // C++17
  224. // Clocks
  225. class system_clock
  226. {
  227. public:
  228. typedef microseconds duration;
  229. typedef duration::rep rep;
  230. typedef duration::period period;
  231. typedef chrono::time_point<system_clock> time_point;
  232. static const bool is_steady = false; // constexpr in C++14
  233. static time_point now() noexcept;
  234. static time_t to_time_t (const time_point& __t) noexcept;
  235. static time_point from_time_t(time_t __t) noexcept;
  236. };
  237. template <class Duration>
  238. using sys_time = time_point<system_clock, Duration>; // C++20
  239. using sys_seconds = sys_time<seconds>; // C++20
  240. using sys_days = sys_time<days>; // C++20
  241. template<class charT, class traits, class Duration> // C++20
  242. basic_ostream<charT, traits>&
  243. operator<<(basic_ostream<charT, traits>& os, const sys_time<Duration>& tp);
  244. class file_clock // C++20
  245. {
  246. public:
  247. typedef see-below rep;
  248. typedef nano period;
  249. typedef chrono::duration<rep, period> duration;
  250. typedef chrono::time_point<file_clock> time_point;
  251. static constexpr bool is_steady = false;
  252. static time_point now() noexcept;
  253. template<class Duration>
  254. static sys_time<see-below> to_sys(const file_time<Duration>&);
  255. template<class Duration>
  256. static file_time<see-below> from_sys(const sys_time<Duration>&);
  257. };
  258. template<class Duration>
  259. using file_time = time_point<file_clock, Duration>; // C++20
  260. template<class charT, class traits, class Duration> // C++20
  261. basic_ostream<charT, traits>&
  262. operator<<(basic_ostream<charT, traits>& os, const file_time<Duration>& tp);
  263. class steady_clock
  264. {
  265. public:
  266. typedef nanoseconds duration;
  267. typedef duration::rep rep;
  268. typedef duration::period period;
  269. typedef chrono::time_point<steady_clock, duration> time_point;
  270. static const bool is_steady = true; // constexpr in C++14
  271. static time_point now() noexcept;
  272. };
  273. typedef steady_clock high_resolution_clock;
  274. // 25.7.8, local time // C++20
  275. struct local_t {};
  276. template<class Duration>
  277. using local_time = time_point<local_t, Duration>;
  278. using local_seconds = local_time<seconds>;
  279. using local_days = local_time<days>;
  280. template<class charT, class traits, class Duration> // C++20
  281. basic_ostream<charT, traits>&
  282. operator<<(basic_ostream<charT, traits>& os, const local_time<Duration>& tp);
  283. // 25.8.2, class last_spec // C++20
  284. struct last_spec;
  285. // 25.8.3, class day // C++20
  286. class day;
  287. constexpr bool operator==(const day& x, const day& y) noexcept;
  288. constexpr strong_ordering operator<=>(const day& x, const day& y) noexcept;
  289. constexpr day operator+(const day& x, const days& y) noexcept;
  290. constexpr day operator+(const days& x, const day& y) noexcept;
  291. constexpr day operator-(const day& x, const days& y) noexcept;
  292. constexpr days operator-(const day& x, const day& y) noexcept;
  293. template<class charT, class traits>
  294. basic_ostream<charT, traits>&
  295. operator<<(basic_ostream<charT, traits>& os, const day& d);
  296. // 25.8.4, class month // C++20
  297. class month;
  298. constexpr bool operator==(const month& x, const month& y) noexcept;
  299. constexpr strong_ordering operator<=>(const month& x, const month& y) noexcept;
  300. constexpr month operator+(const month& x, const months& y) noexcept;
  301. constexpr month operator+(const months& x, const month& y) noexcept;
  302. constexpr month operator-(const month& x, const months& y) noexcept;
  303. constexpr months operator-(const month& x, const month& y) noexcept;
  304. template<class charT, class traits>
  305. basic_ostream<charT, traits>&
  306. operator<<(basic_ostream<charT, traits>& os, const month& m);
  307. // 25.8.5, class year // C++20
  308. class year;
  309. constexpr bool operator==(const year& x, const year& y) noexcept;
  310. constexpr strong_ordering operator<=>(const year& x, const year& y) noexcept;
  311. constexpr year operator+(const year& x, const years& y) noexcept;
  312. constexpr year operator+(const years& x, const year& y) noexcept;
  313. constexpr year operator-(const year& x, const years& y) noexcept;
  314. constexpr years operator-(const year& x, const year& y) noexcept;
  315. template<class charT, class traits>
  316. basic_ostream<charT, traits>&
  317. operator<<(basic_ostream<charT, traits>& os, const year& y);
  318. // 25.8.6, class weekday // C++20
  319. class weekday;
  320. constexpr bool operator==(const weekday& x, const weekday& y) noexcept;
  321. constexpr weekday operator+(const weekday& x, const days& y) noexcept;
  322. constexpr weekday operator+(const days& x, const weekday& y) noexcept;
  323. constexpr weekday operator-(const weekday& x, const days& y) noexcept;
  324. constexpr days operator-(const weekday& x, const weekday& y) noexcept;
  325. template<class charT, class traits>
  326. basic_ostream<charT, traits>&
  327. operator<<(basic_ostream<charT, traits>& os, const weekday& wd);
  328. // 25.8.7, class weekday_indexed // C++20
  329. class weekday_indexed;
  330. constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept;
  331. template<class charT, class traits>
  332. basic_ostream<charT, traits>&
  333. operator<<(basic_ostream<charT, traits>& os, const weekday_indexed& wdi);
  334. // 25.8.8, class weekday_last // C++20
  335. class weekday_last;
  336. constexpr bool operator==(const weekday_last& x, const weekday_last& y) noexcept;
  337. template<class charT, class traits>
  338. basic_ostream<charT, traits>&
  339. operator<<(basic_ostream<charT, traits>& os, const weekday_last& wdl);
  340. // 25.8.9, class month_day // C++20
  341. class month_day;
  342. constexpr bool operator==(const month_day& x, const month_day& y) noexcept;
  343. constexpr strong_ordering operator<=>(const month_day& x, const month_day& y) noexcept;
  344. template<class charT, class traits>
  345. basic_ostream<charT, traits>&
  346. operator<<(basic_ostream<charT, traits>& os, const month_day& md);
  347. // 25.8.10, class month_day_last // C++20
  348. class month_day_last;
  349. constexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept;
  350. constexpr strong_ordering operator<=>(const month_day_last& x, const month_day_last& y) noexcept;
  351. template<class charT, class traits>
  352. basic_ostream<charT, traits>&
  353. operator<<(basic_ostream<charT, traits>& os, const month_day_last& mdl);
  354. // 25.8.11, class month_weekday // C++20
  355. class month_weekday;
  356. constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept;
  357. template<class charT, class traits>
  358. basic_ostream<charT, traits>&
  359. operator<<(basic_ostream<charT, traits>& os, const month_weekday& mwd);
  360. // 25.8.12, class month_weekday_last // C++20
  361. class month_weekday_last;
  362. constexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept;
  363. template<class charT, class traits>
  364. basic_ostream<charT, traits>&
  365. operator<<(basic_ostream<charT, traits>& os, const month_weekday_last& mwdl);
  366. // 25.8.13, class year_month // C++20
  367. class year_month;
  368. constexpr bool operator==(const year_month& x, const year_month& y) noexcept;
  369. constexpr strong_ordering operator<=>(const year_month& x, const year_month& y) noexcept;
  370. constexpr year_month operator+(const year_month& ym, const months& dm) noexcept;
  371. constexpr year_month operator+(const months& dm, const year_month& ym) noexcept;
  372. constexpr year_month operator-(const year_month& ym, const months& dm) noexcept;
  373. constexpr months operator-(const year_month& x, const year_month& y) noexcept;
  374. constexpr year_month operator+(const year_month& ym, const years& dy) noexcept;
  375. constexpr year_month operator+(const years& dy, const year_month& ym) noexcept;
  376. constexpr year_month operator-(const year_month& ym, const years& dy) noexcept;
  377. template<class charT, class traits>
  378. basic_ostream<charT, traits>&
  379. operator<<(basic_ostream<charT, traits>& os, const year_month& ym);
  380. // 25.8.14, class year_month_day class // C++20
  381. year_month_day;
  382. constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept;
  383. constexpr strong_ordering operator<=>(const year_month_day& x, const year_month_day& y) noexcept;
  384. constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept;
  385. constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept;
  386. constexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept;
  387. constexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept;
  388. constexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept;
  389. constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept;
  390. template<class charT, class traits>
  391. basic_ostream<charT, traits>&
  392. operator<<(basic_ostream<charT, traits>& os, const year_month_day& ymd);
  393. // 25.8.15, class year_month_day_last // C++20
  394. class year_month_day_last;
  395. constexpr bool operator==(const year_month_day_last& x, const year_month_day_last& y) noexcept;
  396. constexpr strong_ordering operator<=>(const year_month_day_last_day& x, const year_month_day_last_day& y) noexcept;
  397. constexpr year_month_day_last
  398. operator+(const year_month_day_last& ymdl, const months& dm) noexcept;
  399. constexpr year_month_day_last
  400. operator+(const months& dm, const year_month_day_last& ymdl) noexcept;
  401. constexpr year_month_day_last
  402. operator+(const year_month_day_last& ymdl, const years& dy) noexcept;
  403. constexpr year_month_day_last
  404. operator+(const years& dy, const year_month_day_last& ymdl) noexcept;
  405. constexpr year_month_day_last
  406. operator-(const year_month_day_last& ymdl, const months& dm) noexcept;
  407. constexpr year_month_day_last
  408. operator-(const year_month_day_last& ymdl, const years& dy) noexcept;
  409. template<class charT, class traits>
  410. basic_ostream<charT, traits>&
  411. operator<<(basic_ostream<charT, traits>& os, const year_month_day_last& ymdl);
  412. // 25.8.16, class year_month_weekday // C++20
  413. class year_month_weekday;
  414. constexpr bool operator==(const year_month_weekday& x,
  415. const year_month_weekday& y) noexcept;
  416. constexpr year_month_weekday
  417. operator+(const year_month_weekday& ymwd, const months& dm) noexcept;
  418. constexpr year_month_weekday
  419. operator+(const months& dm, const year_month_weekday& ymwd) noexcept;
  420. constexpr year_month_weekday
  421. operator+(const year_month_weekday& ymwd, const years& dy) noexcept;
  422. constexpr year_month_weekday
  423. operator+(const years& dy, const year_month_weekday& ymwd) noexcept;
  424. constexpr year_month_weekday
  425. operator-(const year_month_weekday& ymwd, const months& dm) noexcept;
  426. constexpr year_month_weekday
  427. operator-(const year_month_weekday& ymwd, const years& dy) noexcept;
  428. template<class charT, class traits>
  429. basic_ostream<charT, traits>&
  430. operator<<(basic_ostream<charT, traits>& os, const year_month_weekday& ymwd);
  431. // 25.8.17, class year_month_weekday_last // C++20
  432. class year_month_weekday_last;
  433. constexpr bool operator==(const year_month_weekday_last& x,
  434. const year_month_weekday_last& y) noexcept;
  435. constexpr year_month_weekday_last
  436. operator+(const year_month_weekday_last& ymwdl, const months& dm) noexcept;
  437. constexpr year_month_weekday_last
  438. operator+(const months& dm, const year_month_weekday_last& ymwdl) noexcept;
  439. constexpr year_month_weekday_last
  440. operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept;
  441. constexpr year_month_weekday_last
  442. operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept;
  443. constexpr year_month_weekday_last
  444. operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept;
  445. constexpr year_month_weekday_last
  446. operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept;
  447. template<class charT, class traits>
  448. basic_ostream<charT, traits>&
  449. operator<<(basic_ostream<charT, traits>& os, const year_month_weekday_last& ymwdl);
  450. // 25.8.18, civil calendar conventional syntax operators // C++20
  451. constexpr year_month
  452. operator/(const year& y, const month& m) noexcept;
  453. constexpr year_month
  454. operator/(const year& y, int m) noexcept;
  455. constexpr month_day
  456. operator/(const month& m, const day& d) noexcept;
  457. constexpr month_day
  458. operator/(const month& m, int d) noexcept;
  459. constexpr month_day
  460. operator/(int m, const day& d) noexcept;
  461. constexpr month_day
  462. operator/(const day& d, const month& m) noexcept;
  463. constexpr month_day
  464. operator/(const day& d, int m) noexcept;
  465. constexpr month_day_last
  466. operator/(const month& m, last_spec) noexcept;
  467. constexpr month_day_last
  468. operator/(int m, last_spec) noexcept;
  469. constexpr month_day_last
  470. operator/(last_spec, const month& m) noexcept;
  471. constexpr month_day_last
  472. operator/(last_spec, int m) noexcept;
  473. constexpr month_weekday
  474. operator/(const month& m, const weekday_indexed& wdi) noexcept;
  475. constexpr month_weekday
  476. operator/(int m, const weekday_indexed& wdi) noexcept;
  477. constexpr month_weekday
  478. operator/(const weekday_indexed& wdi, const month& m) noexcept;
  479. constexpr month_weekday
  480. operator/(const weekday_indexed& wdi, int m) noexcept;
  481. constexpr month_weekday_last
  482. operator/(const month& m, const weekday_last& wdl) noexcept;
  483. constexpr month_weekday_last
  484. operator/(int m, const weekday_last& wdl) noexcept;
  485. constexpr month_weekday_last
  486. operator/(const weekday_last& wdl, const month& m) noexcept;
  487. constexpr month_weekday_last
  488. operator/(const weekday_last& wdl, int m) noexcept;
  489. constexpr year_month_day
  490. operator/(const year_month& ym, const day& d) noexcept;
  491. constexpr year_month_day
  492. operator/(const year_month& ym, int d) noexcept;
  493. constexpr year_month_day
  494. operator/(const year& y, const month_day& md) noexcept;
  495. constexpr year_month_day
  496. operator/(int y, const month_day& md) noexcept;
  497. constexpr year_month_day
  498. operator/(const month_day& md, const year& y) noexcept;
  499. constexpr year_month_day
  500. operator/(const month_day& md, int y) noexcept;
  501. constexpr year_month_day_last
  502. operator/(const year_month& ym, last_spec) noexcept;
  503. constexpr year_month_day_last
  504. operator/(const year& y, const month_day_last& mdl) noexcept;
  505. constexpr year_month_day_last
  506. operator/(int y, const month_day_last& mdl) noexcept;
  507. constexpr year_month_day_last
  508. operator/(const month_day_last& mdl, const year& y) noexcept;
  509. constexpr year_month_day_last
  510. operator/(const month_day_last& mdl, int y) noexcept;
  511. constexpr year_month_weekday
  512. operator/(const year_month& ym, const weekday_indexed& wdi) noexcept;
  513. constexpr year_month_weekday
  514. operator/(const year& y, const month_weekday& mwd) noexcept;
  515. constexpr year_month_weekday
  516. operator/(int y, const month_weekday& mwd) noexcept;
  517. constexpr year_month_weekday
  518. operator/(const month_weekday& mwd, const year& y) noexcept;
  519. constexpr year_month_weekday
  520. operator/(const month_weekday& mwd, int y) noexcept;
  521. constexpr year_month_weekday_last
  522. operator/(const year_month& ym, const weekday_last& wdl) noexcept;
  523. constexpr year_month_weekday_last
  524. operator/(const year& y, const month_weekday_last& mwdl) noexcept;
  525. constexpr year_month_weekday_last
  526. operator/(int y, const month_weekday_last& mwdl) noexcept;
  527. constexpr year_month_weekday_last
  528. operator/(const month_weekday_last& mwdl, const year& y) noexcept;
  529. constexpr year_month_weekday_last
  530. operator/(const month_weekday_last& mwdl, int y) noexcept;
  531. // 26.9, class template hh_mm_ss
  532. template <class Duration>
  533. class hh_mm_ss
  534. {
  535. bool is_neg; // exposition only
  536. chrono::hours h; // exposition only
  537. chrono::minutes m; // exposition only
  538. chrono::seconds s; // exposition only
  539. precision ss; // exposition only
  540. public:
  541. static unsigned constexpr fractional_width = see below;
  542. using precision = see below;
  543. constexpr hh_mm_ss() noexcept : hh_mm_ss{Duration::zero()} {}
  544. constexpr explicit hh_mm_ss(Duration d) noexcept;
  545. constexpr bool is_negative() const noexcept;
  546. constexpr chrono::hours hours() const noexcept;
  547. constexpr chrono::minutes minutes() const noexcept;
  548. constexpr chrono::seconds seconds() const noexcept;
  549. constexpr precision subseconds() const noexcept;
  550. constexpr explicit operator precision() const noexcept;
  551. constexpr precision to_duration() const noexcept;
  552. };
  553. template<class charT, class traits, class Duration>
  554. basic_ostream<charT, traits>&
  555. operator<<(basic_ostream<charT, traits>& os, const hh_mm_ss<Duration>& hms); // C++20
  556. // 26.10, 12/24 hour functions
  557. constexpr bool is_am(hours const& h) noexcept;
  558. constexpr bool is_pm(hours const& h) noexcept;
  559. constexpr hours make12(const hours& h) noexcept;
  560. constexpr hours make24(const hours& h, bool is_pm) noexcept;
  561. // [time.zone.db], time zone database
  562. struct tzdb { // C++20
  563. string version;
  564. };
  565. class tzdb_list { // C++20
  566. public:
  567. tzdb_list(const tzdb_list&) = delete;
  568. tzdb_list& operator=(const tzdb_list&) = delete;
  569. // unspecified additional constructors
  570. class const_iterator;
  571. const tzdb& front() const noexcept;
  572. const_iterator erase_after(const_iterator p);
  573. const_iterator begin() const noexcept;
  574. const_iterator end() const noexcept;
  575. const_iterator cbegin() const noexcept;
  576. const_iterator cend() const noexcept;
  577. };
  578. // [time.zone.db.access], time zone database access
  579. const tzdb& get_tzdb(); // C++20
  580. tzdb_list& get_tzdb_list(); // C++20
  581. // [time.zone.db.remote], remote time zone database support
  582. const tzdb& reload_tzdb(); // C++20
  583. string remote_version(); // C++20
  584. // 25.10.5, class time_zone // C++20
  585. enum class choose {earliest, latest};
  586. class time_zone;
  587. bool operator==(const time_zone& x, const time_zone& y) noexcept;
  588. bool operator!=(const time_zone& x, const time_zone& y) noexcept;
  589. bool operator<(const time_zone& x, const time_zone& y) noexcept;
  590. bool operator>(const time_zone& x, const time_zone& y) noexcept;
  591. bool operator<=(const time_zone& x, const time_zone& y) noexcept;
  592. bool operator>=(const time_zone& x, const time_zone& y) noexcept;
  593. } // chrono
  594. namespace std {
  595. template<class Duration, class charT>
  596. struct formatter<chrono::sys_time<Duration>, charT>; // C++20
  597. template<class Duration, class charT>
  598. struct formatter<chrono::filetime<Duration>, charT>; // C++20
  599. template<class Duration, class charT>
  600. struct formatter<chrono::local_time<Duration>, charT>; // C++20
  601. template<class Rep, class Period, class charT>
  602. struct formatter<chrono::duration<Rep, Period>, charT>; // C++20
  603. template<class charT> struct formatter<chrono::day, charT>; // C++20
  604. template<class charT> struct formatter<chrono::month, charT>; // C++20
  605. template<class charT> struct formatter<chrono::year, charT>; // C++20
  606. template<class charT> struct formatter<chrono::weekday, charT>; // C++20
  607. template<class charT> struct formatter<chrono::weekday_indexed, charT>; // C++20
  608. template<class charT> struct formatter<chrono::weekday_last, charT>; // C++20
  609. template<class charT> struct formatter<chrono::month_day, charT>; // C++20
  610. template<class charT> struct formatter<chrono::month_day_last, charT>; // C++20
  611. template<class charT> struct formatter<chrono::month_weekday, charT>; // C++20
  612. template<class charT> struct formatter<chrono::month_weekday_last, charT>; // C++20
  613. template<class charT> struct formatter<chrono::year_month, charT>; // C++20
  614. template<class charT> struct formatter<chrono::year_month_day, charT>; // C++20
  615. template<class charT> struct formatter<chrono::year_month_day_last, charT>; // C++20
  616. template<class charT> struct formatter<chrono::year_month_weekday, charT>; // C++20
  617. template<class charT> struct formatter<chrono::year_month_weekday_last, charT>; // C++20
  618. template<class Rep, class Period, class charT>
  619. struct formatter<chrono::hh_mm_ss<duration<Rep, Period>>, charT>; // C++20
  620. } // namespace std
  621. namespace chrono {
  622. // calendrical constants
  623. inline constexpr last_spec last{}; // C++20
  624. inline constexpr chrono::weekday Sunday{0}; // C++20
  625. inline constexpr chrono::weekday Monday{1}; // C++20
  626. inline constexpr chrono::weekday Tuesday{2}; // C++20
  627. inline constexpr chrono::weekday Wednesday{3}; // C++20
  628. inline constexpr chrono::weekday Thursday{4}; // C++20
  629. inline constexpr chrono::weekday Friday{5}; // C++20
  630. inline constexpr chrono::weekday Saturday{6}; // C++20
  631. inline constexpr chrono::month January{1}; // C++20
  632. inline constexpr chrono::month February{2}; // C++20
  633. inline constexpr chrono::month March{3}; // C++20
  634. inline constexpr chrono::month April{4}; // C++20
  635. inline constexpr chrono::month May{5}; // C++20
  636. inline constexpr chrono::month June{6}; // C++20
  637. inline constexpr chrono::month July{7}; // C++20
  638. inline constexpr chrono::month August{8}; // C++20
  639. inline constexpr chrono::month September{9}; // C++20
  640. inline constexpr chrono::month October{10}; // C++20
  641. inline constexpr chrono::month November{11}; // C++20
  642. inline constexpr chrono::month December{12}; // C++20
  643. } // chrono
  644. inline namespace literals {
  645. inline namespace chrono_literals {
  646. constexpr chrono::hours operator ""h(unsigned long long); // C++14
  647. constexpr chrono::duration<unspecified , ratio<3600,1>> operator ""h(long double); // C++14
  648. constexpr chrono::minutes operator ""min(unsigned long long); // C++14
  649. constexpr chrono::duration<unspecified , ratio<60,1>> operator ""min(long double); // C++14
  650. constexpr chrono::seconds operator ""s(unsigned long long); // C++14
  651. constexpr chrono::duration<unspecified > operator ""s(long double); // C++14
  652. constexpr chrono::milliseconds operator ""ms(unsigned long long); // C++14
  653. constexpr chrono::duration<unspecified , milli> operator ""ms(long double); // C++14
  654. constexpr chrono::microseconds operator ""us(unsigned long long); // C++14
  655. constexpr chrono::duration<unspecified , micro> operator ""us(long double); // C++14
  656. constexpr chrono::nanoseconds operator ""ns(unsigned long long); // C++14
  657. constexpr chrono::duration<unspecified , nano> operator ""ns(long double); // C++14
  658. constexpr chrono::day operator ""d(unsigned long long d) noexcept; // C++20
  659. constexpr chrono::year operator ""y(unsigned long long y) noexcept; // C++20
  660. } // chrono_literals
  661. } // literals
  662. } // std
  663. */
  664. #include <__assert> // all public C++ headers provide the assertion handler
  665. #include <__chrono/calendar.h>
  666. #include <__chrono/convert_to_timespec.h>
  667. #include <__chrono/convert_to_tm.h>
  668. #include <__chrono/day.h>
  669. #include <__chrono/duration.h>
  670. #include <__chrono/file_clock.h>
  671. #include <__chrono/hh_mm_ss.h>
  672. #include <__chrono/high_resolution_clock.h>
  673. #include <__chrono/literals.h>
  674. #include <__chrono/month.h>
  675. #include <__chrono/month_weekday.h>
  676. #include <__chrono/monthday.h>
  677. #include <__chrono/steady_clock.h>
  678. #include <__chrono/system_clock.h>
  679. #include <__chrono/time_point.h>
  680. #include <__chrono/weekday.h>
  681. #include <__chrono/year.h>
  682. #include <__chrono/year_month.h>
  683. #include <__chrono/year_month_day.h>
  684. #include <__chrono/year_month_weekday.h>
  685. #include <__config>
  686. #include <version>
  687. // standard-mandated includes
  688. // [time.syn]
  689. #include <compare>
  690. #if 0
  691. # include <__chrono/formatter.h>
  692. # include <__chrono/ostream.h>
  693. # include <__chrono/parser_std_format_spec.h>
  694. # include <__chrono/statically_widen.h>
  695. #endif
  696. #if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
  697. !defined(_LIBCPP_HAS_NO_LOCALIZATION)
  698. # include <__chrono/tzdb.h>
  699. # include <__chrono/tzdb_list.h>
  700. #endif
  701. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  702. # pragma GCC system_header
  703. #endif
  704. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  705. # include <bit>
  706. # include <concepts>
  707. # include <cstring>
  708. # include <forward_list>
  709. # include <string>
  710. #endif
  711. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER == 20
  712. # include <charconv>
  713. #endif
  714. #endif // _LIBCPP_CHRONO