| 1 |
// { dg-do compile { target c++20 } } |
| 2 |
|
| 3 |
// Copyright (C) 2020-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 template day [time.cal.year_month_day_last] |
| 21 |
|
| 22 |
#include <chrono> |
| 23 |
|
| 24 |
constexpr void |
| 25 |
constexpr_year_month_day_last() |
| 26 |
{ |
| 27 |
using namespace std::chrono; |
| 28 |
using mdl = month_day_last; |
| 29 |
using ymdl = year_month_day_last; |
| 30 |
|
| 31 |
year_month_day_last ymdl1{year{1066}, mdl{October}}; |
| 32 |
ymdl1 += months{9}; |
| 33 |
ymdl1 -= months{9}; |
| 34 |
ymdl1 += years{12}; |
| 35 |
ymdl1 -= years{12}; |
| 36 |
|
| 37 |
constexpr ymdl ymdl2{year{1984}, mdl{August}}; |
| 38 |
static_assert(ymdl2.year() == year{1984}); |
| 39 |
static_assert(ymdl2.month() == August); |
| 40 |
static_assert(ymdl2.month_day_last() == mdl{August}); |
| 41 |
static_assert(ymdl2.day() == day{31}); |
| 42 |
static_assert(sys_days(ymdl2).time_since_epoch().count() == 5356); |
| 43 |
static_assert(local_days(ymdl2).time_since_epoch().count() == 5356); |
| 44 |
|
| 45 |
static_assert( (ymdl{year{1984}, mdl{August}}.ok())); |
| 46 |
static_assert(!(ymdl{year{1984}, mdl{month{13}}}.ok())); |
| 47 |
|
| 48 |
static_assert(2015y/August/last == ymdl{year{2015}, month_day_last{month{8}}}); |
| 49 |
static_assert(2015y/(August/last) == ymdl{year{2015}, month_day_last{month{8}}}); |
| 50 |
static_assert(2015/(August/last) == ymdl{year{2015}, month_day_last{month{8}}}); |
| 51 |
static_assert(August/last/2015y == ymdl{year{2015}, month_day_last{month{8}}}); |
| 52 |
static_assert(August/last/2015 == ymdl{year{2015}, month_day_last{month{8}}}); |
| 53 |
|
| 54 |
static_assert(January/last/2000 <=> January/last/2000 |
| 55 |
== std::strong_ordering::equal); |
| 56 |
static_assert(January/last/2000 <=> February/last/2000 |
| 57 |
== std::strong_ordering::less); |
| 58 |
static_assert(January/last/2000 <=> January/last/1999 |
| 59 |
== std::strong_ordering::greater); |
| 60 |
|
| 61 |
static_assert(January/last/2000 + months{13} == February/last/2001); |
| 62 |
static_assert(January/last/2000 + months{-1} == December/last/1999); |
| 63 |
static_assert(January/last/2000 - months{13} == December/last/1998); |
| 64 |
static_assert(January/last/2000 - months{-13} == February/last/2001); |
| 65 |
|
| 66 |
static_assert(January/last/2000 + years{5} == January/last/2005); |
| 67 |
static_assert(January/last/2000 - years{5} == January/last/1995); |
| 68 |
|
| 69 |
static_assert(year_month_day{January/last/2000} == January/31/2000); |
| 70 |
static_assert(year_month_day{February/last/2000} == February/29/2000); |
| 71 |
static_assert(year_month_day{March/last/2000} == March/31/2000); |
| 72 |
static_assert(year_month_day{April/last/2000} == April/30/2000); |
| 73 |
static_assert(year_month_day{May/last/2000} == May/31/2000); |
| 74 |
static_assert(year_month_day{June/last/2000} == June/30/2000); |
| 75 |
static_assert(year_month_day{July/last/2000} == July/31/2000); |
| 76 |
static_assert(year_month_day{August/last/2000} == August/31/2000); |
| 77 |
static_assert(year_month_day{September/last/2000} == September/30/2000); |
| 78 |
static_assert(year_month_day{October/last/2000} == October/31/2000); |
| 79 |
static_assert(year_month_day{November/last/2000} == November/30/2000); |
| 80 |
static_assert(year_month_day{December/last/2000} == December/31/2000); |
| 81 |
} |