]>
Commit | Line | Data |
---|---|---|
41cd9d4d | 1 | // { dg-do compile { target c++20 } } |
03d5044b | 2 | |
a945c346 | 3 | // Copyright (C) 2020-2024 Free Software Foundation, Inc. |
03d5044b PP |
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 year_month [time.cal.year_month] | |
21 | ||
22 | #include <chrono> | |
23 | ||
24 | constexpr void | |
25 | constexpr_year_month() | |
26 | { | |
27 | using namespace std::chrono; | |
28 | using ym = year_month; | |
29 | ||
30 | ym ym0 = 2015y/April; | |
31 | ym0 += years{100}; | |
32 | ym0 -= years{100}; | |
33 | ym0 += months{50}; | |
34 | ym0 -= months{50}; | |
35 | ||
36 | constexpr ym ym1 = {2015y, June}; | |
37 | static_assert(ym1.year() == year{2015}); | |
38 | static_assert(ym1.month() == June); | |
39 | static_assert(ym1.ok()); | |
40 | ||
41 | constexpr ym ym2 = {2016y, May}; | |
42 | static_assert(ym2.year() == year{2016}); | |
43 | static_assert(ym2.month() == May); | |
44 | static_assert(ym2.ok()); | |
45 | ||
46 | static_assert(ym1 == ym1); | |
47 | static_assert(ym1 != ym2); | |
48 | static_assert(ym1 < ym2); | |
49 | static_assert(ym1 <= ym2); | |
50 | static_assert(ym2 > ym1); | |
51 | static_assert(ym2 >= ym2); | |
52 | ||
53 | static_assert(ym1 <=> ym1 == std::strong_ordering::equal); | |
54 | static_assert(ym1 <=> ym2 == std::strong_ordering::less); | |
55 | static_assert(ym2 <=> ym1 == std::strong_ordering::greater); | |
56 | ||
57 | static_assert(2015y/August == ym{year{2015}, August}); | |
58 | static_assert(2015y/8 == ym{year{2015}, August}); | |
59 | ||
60 | static_assert(ym1 + months{6} == 2015y/December); | |
61 | static_assert(ym1 + months{7} == 2016y/January); | |
62 | static_assert(months{24} + ym1 == 2017y/June); | |
63 | static_assert(months{25} + ym1 == 2017y/July); | |
64 | ||
65 | static_assert(ym1 + months{-5} == 2015y/January); | |
66 | static_assert(ym1 + months{-6} == 2014y/December); | |
67 | static_assert(ym1 + months{-24} == 2013y/June); | |
68 | static_assert(ym1 + months{-25} == 2013y/May); | |
69 | ||
70 | static_assert(ym1 - months{5} == 2015y/January); | |
71 | static_assert(ym1 - months{6} == 2014y/December); | |
72 | static_assert(ym1 - months{24} == 2013y/June); | |
73 | static_assert(ym1 - months{25} == 2013y/May); | |
74 | ||
75 | static_assert(ym2 - ym1 == months{11}); | |
76 | static_assert(ym1 - ym2 == -months{11}); | |
77 | ||
78 | static_assert(ym2 + years{1} == 2017y/May); | |
79 | static_assert(ym2 + years{-1} == 2015y/May); | |
80 | static_assert(ym2 - years{1} == 2015y/May); | |
81 | ||
82 | static_assert(2017y/33 + months{0} == 2019y/9); | |
83 | ||
84 | static_assert(2010y/January + months{-12} == 2009y/January); | |
71e97161 PP |
85 | |
86 | static_assert(2010y/month{0} + months{-1} == 2009y/November); | |
87 | static_assert(2010y/month{0} + months{0} == 2009y/December); | |
88 | static_assert(2010y/month{0} + months{1} == 2010y/January); | |
89 | static_assert(2010y/month{0} + months{2} == 2010y/February); | |
90 | static_assert(2010y/month{0} + months{11} == 2010y/November); | |
91 | static_assert(2010y/month{0} + months{12} == 2010y/December); | |
92 | static_assert(2010y/month{0} + months{13} == 2011y/January); | |
93 | ||
94 | static_assert(months{-1} + 2010y/month{37} == 2012y/December); | |
95 | static_assert(months{0} + 2010y/month{37} == 2013y/January); | |
96 | static_assert(months{1} + 2010y/month{37} == 2013y/February); | |
03d5044b | 97 | } |