]>
Commit | Line | Data |
---|---|---|
97d6161f CN |
1 | // { dg-options "-std=gnu++2a" } |
2 | // { dg-do run { target c++2a } } | |
3 | ||
83ffe9cd | 4 | // Copyright (C) 2021-2023 Free Software Foundation, Inc. |
97d6161f CN |
5 | // |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 3, or (at your option) | |
10 | // any later version. | |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
17 | // You should have received a copy of the GNU General Public License along | |
18 | // with this library; see the file COPYING3. If not see | |
19 | // <http://www.gnu.org/licenses/>. | |
20 | ||
21 | // Class year_month_day [time.cal.year_month_day] | |
22 | ||
23 | #include <chrono> | |
24 | #include <testsuite_hooks.h> | |
25 | ||
26 | // Slow but very clear way of advancing one day. | |
27 | constexpr void | |
28 | advance(std::chrono::year_month_day& ymd) noexcept { | |
29 | ||
30 | using namespace std::chrono; | |
31 | ||
32 | auto y = ymd.year(); | |
33 | auto m = ymd.month(); | |
34 | auto d = ymd.day(); | |
35 | ||
36 | if (d != year_month_day_last{year{y}, month_day_last{m}}.day()) | |
37 | ++d; | |
38 | else { | |
39 | d = day{1}; | |
40 | if (m != December) | |
41 | ++m; | |
42 | else { | |
43 | m = January; | |
44 | ++y; | |
45 | } | |
46 | } | |
47 | ymd = year_month_day{y, m, d}; | |
48 | } | |
49 | ||
50 | void test01() | |
51 | { | |
52 | using namespace std::chrono; | |
53 | ||
54 | // [-32767y/January/1d, 32767y/December/31d] maps to [-12687428, 11248737] | |
55 | ||
56 | auto n = days{-12687428}; | |
57 | auto ymd = -32767y/January/1d; | |
58 | while (ymd < 32767y/December/31d) { | |
59 | VERIFY( static_cast<sys_days>(ymd) == sys_days{n} ); | |
60 | ++n; | |
61 | advance(ymd); | |
62 | } | |
63 | // One more for ymd = 32767y/December/31d and n = 11248737. | |
64 | VERIFY( sys_days{days{11248737}} == static_cast<sys_days>(32767y/December/31d) ); | |
65 | } | |
66 | ||
67 | int main() | |
68 | { | |
69 | test01(); | |
70 | return 0; | |
71 | } |