]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/time/year_month_weekday/1.cc
1 // { dg-do compile { target c++20 } }
3 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
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)
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.
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/>.
20 // Class template day [time.cal.year_month_weekday]
25 constexpr_year_month_weekday()
27 using namespace std::chrono
;
28 using ymwd
= year_month_weekday
;
30 year_month_weekday ymwd1
{};
36 constexpr ymwd ymwd2
{year
{1984}, month
{August
},
37 weekday_indexed
{Wednesday
, 3}};
38 static_assert(ymwd2
.ok());
39 static_assert(ymwd2
.year() == year
{1984});
40 static_assert(ymwd2
.month() == August
);
41 static_assert(ymwd2
.weekday() == Wednesday
);
42 static_assert(ymwd2
.index() == 3);
43 static_assert(ymwd2
.weekday_indexed() == weekday_indexed
{Wednesday
, 3});
44 static_assert(ymwd
{sys_days
{ymwd2
}} == ymwd2
);
45 static_assert(ymwd
{local_days
{ymwd2
}} == ymwd2
);
47 static_assert(2015y
/August
/Friday
[2] == ymwd
{year
{2015}, month
{8}, weekday_indexed
{weekday
{5u}, 2}});
48 static_assert(2015y
/(August
/Friday
[2]) == ymwd
{year
{2015}, month
{8}, weekday_indexed
{weekday
{5u}, 2}});
49 static_assert(2015/(August
/Friday
[2]) == ymwd
{year
{2015}, month
{8}, weekday_indexed
{weekday
{5u}, 2}});
50 static_assert(August
/Friday
[2]/2015y
== ymwd
{year
{2015}, month
{8}, weekday_indexed
{weekday
{5u}, 2}});
51 static_assert(August
/Friday
[2]/2015 == ymwd
{year
{2015}, month
{8}, weekday_indexed
{weekday
{5u}, 2}});
53 static_assert(January
/Tuesday
[2]/1900y
+ months
{1} == February
/Tuesday
[2]/1900y
);
54 static_assert(months
{1} + January
/Tuesday
[2]/1900y
== February
/Tuesday
[2]/1900y
);
55 static_assert(January
/Tuesday
[2]/1900y
- months
{1} == December
/Tuesday
[2]/1899y
);
56 static_assert(January
/Tuesday
[2]/1900y
+ years
{1} == January
/Tuesday
[2]/1901y
);
57 static_assert(years
{1} + January
/Tuesday
[2]/1900y
== January
/Tuesday
[2]/1901y
);
58 static_assert(January
/Tuesday
[2]/1900y
- years
{1} == January
/Tuesday
[2]/1899y
);
60 static_assert(January
/Tuesday
[1]/1900y
!= February
/Tuesday
[1]/1900y
);
61 static_assert(January
/Tuesday
[1]/1900y
!= January
/Wednesday
[1]/1900y
);
62 static_assert(January
/Tuesday
[1]/1900y
!= January
/Tuesday
[1]/1901y
);
63 static_assert(January
/Tuesday
[1]/1900y
!= January
/Tuesday
[2]/1900y
);
65 // N.B. unix seems to be a macro somewhere!
66 constexpr ymwd
myunix(local_days
{days
{0}});
67 static_assert(myunix
.ok());
68 static_assert(myunix
.year() == year
{1970});
69 static_assert(myunix
.month() == January
);
70 static_assert(myunix
.weekday() == Thursday
);
71 static_assert(myunix
.index() == 1);
72 static_assert(myunix
.weekday_indexed() == weekday_indexed
{Thursday
, 1});
73 static_assert(ymwd
{sys_days
{myunix
}} == myunix
);
74 static_assert(ymwd
{local_days
{myunix
}} == myunix
);
76 static_assert((2020y
/August
/Monday
[5]).ok());
77 static_assert(!(2020y
/August
/Tuesday
[5]).ok());