]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/time/year_month/1.cc
1 // { dg-options "-std=gnu++2a" }
2 // { dg-do compile { target c++2a } }
4 // Copyright (C) 2020-2021 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 year_month [time.cal.year_month]
26 constexpr_year_month()
28 using namespace std::chrono
;
29 using ym
= year_month
;
37 constexpr ym ym1
= {2015y
, June
};
38 static_assert(ym1
.year() == year
{2015});
39 static_assert(ym1
.month() == June
);
40 static_assert(ym1
.ok());
42 constexpr ym ym2
= {2016y
, May
};
43 static_assert(ym2
.year() == year
{2016});
44 static_assert(ym2
.month() == May
);
45 static_assert(ym2
.ok());
47 static_assert(ym1
== ym1
);
48 static_assert(ym1
!= ym2
);
49 static_assert(ym1
< ym2
);
50 static_assert(ym1
<= ym2
);
51 static_assert(ym2
> ym1
);
52 static_assert(ym2
>= ym2
);
54 static_assert(ym1
<=> ym1
== std::strong_ordering::equal
);
55 static_assert(ym1
<=> ym2
== std::strong_ordering::less
);
56 static_assert(ym2
<=> ym1
== std::strong_ordering::greater
);
58 static_assert(2015y
/August
== ym
{year
{2015}, August
});
59 static_assert(2015y
/8 == ym
{year
{2015}, August
});
61 static_assert(ym1
+ months
{6} == 2015y
/December
);
62 static_assert(ym1
+ months
{7} == 2016y
/January
);
63 static_assert(months
{24} + ym1
== 2017y
/June
);
64 static_assert(months
{25} + ym1
== 2017y
/July
);
66 static_assert(ym1
+ months
{-5} == 2015y
/January
);
67 static_assert(ym1
+ months
{-6} == 2014y
/December
);
68 static_assert(ym1
+ months
{-24} == 2013y
/June
);
69 static_assert(ym1
+ months
{-25} == 2013y
/May
);
71 static_assert(ym1
- months
{5} == 2015y
/January
);
72 static_assert(ym1
- months
{6} == 2014y
/December
);
73 static_assert(ym1
- months
{24} == 2013y
/June
);
74 static_assert(ym1
- months
{25} == 2013y
/May
);
76 static_assert(ym2
- ym1
== months
{11});
77 static_assert(ym1
- ym2
== -months
{11});
79 static_assert(ym2
+ years
{1} == 2017y
/May
);
80 static_assert(ym2
+ years
{-1} == 2015y
/May
);
81 static_assert(ym2
- years
{1} == 2015y
/May
);
83 static_assert(2017y
/33 + months
{0} == 2019y
/9);
85 static_assert(2010y
/January
+ months
{-12} == 2009y
/January
);
87 static_assert(2010y
/month
{0} + months
{-1} == 2009y
/November
);
88 static_assert(2010y
/month
{0} + months
{0} == 2009y
/December
);
89 static_assert(2010y
/month
{0} + months
{1} == 2010y
/January
);
90 static_assert(2010y
/month
{0} + months
{2} == 2010y
/February
);
91 static_assert(2010y
/month
{0} + months
{11} == 2010y
/November
);
92 static_assert(2010y
/month
{0} + months
{12} == 2010y
/December
);
93 static_assert(2010y
/month
{0} + months
{13} == 2011y
/January
);
95 static_assert(months
{-1} + 2010y
/month
{37} == 2012y
/December
);
96 static_assert(months
{0} + 2010y
/month
{37} == 2013y
/January
);
97 static_assert(months
{1} + 2010y
/month
{37} == 2013y
/February
);