1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // class year_month_day;
13 // constexpr year_month_day& operator+=(const months& m) noexcept;
14 // constexpr year_month_day& operator-=(const months& m) noexcept;
17 #include <type_traits>
20 #include "test_macros.h"
22 using year
= std::chrono::year
;
23 using month
= std::chrono::month
;
24 using day
= std::chrono::day
;
25 using year_month_day
= std::chrono::year_month_day
;
26 using months
= std::chrono::months
;
28 constexpr bool test() {
29 for (unsigned i
= 0; i
<= 10; ++i
) {
32 year_month_day
ymd(y
, month
{i
}, d
);
35 assert(ymd
.year() == y
);
36 assert(ymd
.day() == d
);
37 assert(static_cast<unsigned>((ymd
).month()) == i
+ 2);
40 assert(ymd
.year() == y
);
41 assert(ymd
.day() == d
);
42 assert(static_cast<unsigned>((ymd
).month()) == i
+ 1);
45 { // Validate the ok status when the day is not present in the new month.
46 year_month_day ymd
{year
{2020}, month
{3}, day
{31}};
48 assert((ymd
== year_month_day
{year
{2020}, month
{4}, day
{31}}));
52 assert((ymd
== year_month_day
{year
{2020}, month
{3}, day
{31}}));
56 { // Validate the ok status when the day becomes present in the new month.
57 year_month_day ymd
{year
{2020}, month
{4}, day
{31}};
61 assert((ymd
== year_month_day
{year
{2020}, month
{5}, day
{31}}));
65 assert((ymd
== year_month_day
{year
{2020}, month
{3}, day
{31}}));
69 { // Test year wrapping
70 year_month_day ymd
{year
{2020}, month
{4}, day
{31}};
73 assert((ymd
== year_month_day
{year
{2021}, month
{4}, day
{31}}));
76 assert((ymd
== year_month_day
{year
{2020}, month
{4}, day
{31}}));
82 int main(int, char**) {
83 ASSERT_NOEXCEPT(std::declval
<year_month_day
&>() += std::declval
<months
>());
84 ASSERT_NOEXCEPT(std::declval
<year_month_day
&>() -= std::declval
<months
>());
86 ASSERT_SAME_TYPE(year_month_day
&, decltype(std::declval
<year_month_day
&>() += std::declval
<months
>()));
87 ASSERT_SAME_TYPE(year_month_day
&, decltype(std::declval
<year_month_day
&>() -= std::declval
<months
>()));
90 static_assert(test());