| 1 |
// { dg-do run { target c++20 } } |
| 2 |
// { dg-additional-options "-DSTART_DAY=-50000 -DSTART_YMD=1833y/February/8d -DEND_YMD=2106y/November/24d" { target simulator } } |
| 3 |
|
| 4 |
// Copyright (C) 2021-2025 Free Software Foundation, Inc. |
| 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 |
#ifdef START_DAY |
| 55 |
auto n = days{START_DAY}; |
| 56 |
auto ymd = START_YMD; |
| 57 |
#else |
| 58 |
// [-32767y/January/1d, 32767y/December/31d] maps to [-12687428, 11248737] |
| 59 |
|
| 60 |
auto n = days{-12687428}; |
| 61 |
auto ymd = -32767y/January/1d; |
| 62 |
#define END_YMD 32767y/December/31d |
| 63 |
#endif |
| 64 |
|
| 65 |
while (ymd < END_YMD) { |
| 66 |
VERIFY( static_cast<sys_days>(ymd) == sys_days{n} ); |
| 67 |
++n; |
| 68 |
advance(ymd); |
| 69 |
} |
| 70 |
// One more for ymd = 32767y/December/31d and n = 11248737. |
| 71 |
VERIFY( sys_days{days{11248737}} == static_cast<sys_days>(32767y/December/31d) ); |
| 72 |
} |
| 73 |
|
| 74 |
int main() |
| 75 |
{ |
| 76 |
test01(); |
| 77 |
return 0; |
| 78 |
} |