]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/time/month/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / std / time / month / 1.cc
1 // { dg-options "-std=gnu++2a" }
2 // { dg-do compile { target c++2a } }
3
4 // Copyright (C) 2020-2023 Free Software Foundation, Inc.
5 //
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)
10 // any later version.
11
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.
16
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/>.
20
21 // Class template day [time.cal.month]
22
23 #include <chrono>
24
25 constexpr void
26 constexpr_month()
27 {
28 using namespace std::chrono;
29
30 month dm{};
31 ++(++dm);
32 dm++;
33 --(--dm);
34 dm--;
35 dm += months{3};
36 dm -= months{3};
37
38 static_assert(February + months{11} == January);
39 static_assert(January + months{1200} == January);
40 static_assert(January + months{1201} == February);
41 static_assert(months{-1200} + January == January);
42 static_assert(months{-1201} + January == December);
43 static_assert(January - months{1200} == January);
44 static_assert(January - months{-1200} == January);
45 static_assert(January - months{1201} == December);
46
47 static_assert(January - February == months{11});
48 static_assert(February - January == months{1});
49 static_assert(June - June == months{});
50
51 static_assert(++month{4} == month{5});
52 static_assert(month{4}++ == month{4});
53 static_assert(--month{4} == month{3});
54 static_assert(month{4}-- == month{4});
55 static_assert((month{4} += months{3}) == month{7});
56 static_assert((month{4} -= months{3}) == month{1});
57
58 static_assert(!month{}.ok());
59 static_assert(month{1}.ok());
60 static_assert(month{12}.ok());
61 static_assert(!month{13}.ok());
62
63 static_assert(unsigned{month{7}} == 7);
64
65 static_assert(!(month{0} == month{1}));
66 static_assert( (month{0} != month{2}));
67 static_assert( (month{0} < month{3}));
68 static_assert(!(month{0} > month{4}));
69 static_assert( (month{0} <= month{5}));
70 static_assert(!(month{0} >= month{6}));
71
72 static_assert(month{0} <=> month{1} == std::strong_ordering::less);
73 static_assert(month{3} <=> month{3} == std::strong_ordering::equal);
74 static_assert(month{5} <=> month{2} == std::strong_ordering::greater);
75 }