1 // { dg-options "-std=gnu++2a" }
2 // { dg-do compile { target c++2a } }
4 // Copyright (C) 2020-2022 Free Software Foundation, Inc.
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)
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.
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/>.
21 // Class template day [time.cal.year_month_day_last]
26 constexpr_year_month_day_last()
28 using namespace std::chrono
;
29 using mdl
= month_day_last
;
30 using ymdl
= year_month_day_last
;
32 year_month_day_last ymdl1
{year
{1066}, mdl
{October
}};
38 constexpr ymdl ymdl2
{year
{1984}, mdl
{August
}};
39 static_assert(ymdl2
.year() == year
{1984});
40 static_assert(ymdl2
.month() == August
);
41 static_assert(ymdl2
.month_day_last() == mdl
{August
});
42 static_assert(ymdl2
.day() == day
{31});
43 static_assert(sys_days(ymdl2
).time_since_epoch().count() == 5356);
44 static_assert(local_days(ymdl2
).time_since_epoch().count() == 5356);
46 static_assert( (ymdl
{year
{1984}, mdl
{August
}}.ok()));
47 static_assert(!(ymdl
{year
{1984}, mdl
{month
{13}}}.ok()));
49 static_assert(2015y
/August
/last
== ymdl
{year
{2015}, month_day_last
{month
{8}}});
50 static_assert(2015y
/(August
/last
) == ymdl
{year
{2015}, month_day_last
{month
{8}}});
51 static_assert(2015/(August
/last
) == ymdl
{year
{2015}, month_day_last
{month
{8}}});
52 static_assert(August
/last
/2015y
== ymdl
{year
{2015}, month_day_last
{month
{8}}});
53 static_assert(August
/last
/2015 == ymdl
{year
{2015}, month_day_last
{month
{8}}});
55 static_assert(January
/last
/2000 <=> January
/last
/2000
56 == std::strong_ordering::equal
);
57 static_assert(January
/last
/2000 <=> February
/last
/2000
58 == std::strong_ordering::less
);
59 static_assert(January
/last
/2000 <=> January
/last
/1999
60 == std::strong_ordering::greater
);
62 static_assert(January
/last
/2000 + months
{13} == February
/last
/2001);
63 static_assert(January
/last
/2000 + months
{-1} == December
/last
/1999);
64 static_assert(January
/last
/2000 - months
{13} == December
/last
/1998);
65 static_assert(January
/last
/2000 - months
{-13} == February
/last
/2001);
67 static_assert(January
/last
/2000 + years
{5} == January
/last
/2005);
68 static_assert(January
/last
/2000 - years
{5} == January
/last
/1995);
70 static_assert(year_month_day
{January
/last
/2000} == January
/31/2000);
71 static_assert(year_month_day
{February
/last
/2000} == February
/29/2000);
72 static_assert(year_month_day
{March
/last
/2000} == March
/31/2000);
73 static_assert(year_month_day
{April
/last
/2000} == April
/30/2000);
74 static_assert(year_month_day
{May
/last
/2000} == May
/31/2000);
75 static_assert(year_month_day
{June
/last
/2000} == June
/30/2000);
76 static_assert(year_month_day
{July
/last
/2000} == July
/31/2000);
77 static_assert(year_month_day
{August
/last
/2000} == August
/31/2000);
78 static_assert(year_month_day
{September
/last
/2000} == September
/30/2000);
79 static_assert(year_month_day
{October
/last
/2000} == October
/31/2000);
80 static_assert(year_month_day
{November
/last
/2000} == November
/30/2000);
81 static_assert(year_month_day
{December
/last
/2000} == December
/31/2000);