]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/time/year_month_weekday/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / std / time / year_month_weekday / 1.cc
1 // { dg-do compile { target c++20 } }
2
3 // Copyright (C) 2020-2024 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_weekday]
21
22 #include <chrono>
23
24 constexpr void
25 constexpr_year_month_weekday()
26 {
27 using namespace std::chrono;
28 using ymwd = year_month_weekday;
29
30 year_month_weekday ymwd1{};
31 ymwd1 += months{9};
32 ymwd1 -= months{9};
33 ymwd1 += years{12};
34 ymwd1 -= years{12};
35
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);
46
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}});
52
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);
59
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);
64
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);
75
76 static_assert((2020y/August/Monday[5]).ok());
77 static_assert(!(2020y/August/Tuesday[5]).ok());
78 }