| 1 |
// { dg-do run { target c++20 } } |
| 2 |
|
| 3 |
// Copyright (C) 2021-2025 Free Software Foundation, Inc. |
| 4 |
// |
| 5 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 6 |
// software; you can redistribute it and/or modify it under the |
| 7 |
// terms of the GNU General Public License as published by the |
| 8 |
// Free Software Foundation; either version 3, or (at your option) |
| 9 |
// any later version. |
| 10 |
|
| 11 |
// This library is distributed in the hope that it will be useful, |
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
// GNU General Public License for more details. |
| 15 |
|
| 16 |
// You should have received a copy of the GNU General Public License along |
| 17 |
// with this library; see the file COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
// Class year [time.cal.year_month_day] |
| 21 |
|
| 22 |
#include <chrono> |
| 23 |
#include <testsuite_hooks.h> |
| 24 |
|
| 25 |
// Slow but clear test for leap year. |
| 26 |
constexpr bool |
| 27 |
is_leap_year(const std::chrono::year& y) noexcept |
| 28 |
{ |
| 29 |
const int n = static_cast<int>(y); |
| 30 |
return n % 4 == 0 && (n % 100 != 0 || n % 400 == 0); |
| 31 |
} |
| 32 |
|
| 33 |
void test01() |
| 34 |
{ |
| 35 |
using namespace std::chrono; |
| 36 |
|
| 37 |
year y{-32767}; |
| 38 |
while (y < year{32767}) { |
| 39 |
VERIFY( y.is_leap() == is_leap_year(y) ); |
| 40 |
++y; |
| 41 |
} |
| 42 |
|
| 43 |
// One more for y = 32767. |
| 44 |
VERIFY( year{32767}.is_leap() == is_leap_year(year{32767}) ); |
| 45 |
} |
| 46 |
|
| 47 |
int main() |
| 48 |
{ |
| 49 |
test01(); |
| 50 |
return 0; |
| 51 |
} |