1//===----------------------------------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8// UNSUPPORTED: c++03, c++11, c++14, c++17
9
10// <chrono>
11// class year_month_day_last;
12
13// constexpr year_month_day_last
14// operator-(const year_month_day_last& ymdl, const months& dm) noexcept;
15//
16// Returns: ymdl + (-dm).
17//
18// constexpr year_month_day_last
19// operator-(const year_month_day_last& ymdl, const years& dy) noexcept;
20//
21// Returns: ymdl + (-dy).
22
23#include <chrono>
24#include <cassert>
25#include <type_traits>
26#include <utility>
27
28#include "test_macros.h"
29
30using year = std::chrono::year;
31using month = std::chrono::month;
32using month_day_last = std::chrono::month_day_last;
33using year_month_day_last = std::chrono::year_month_day_last;
34using months = std::chrono::months;
35using years = std::chrono::years;
36
37constexpr bool test() {
38 constexpr month December = std::chrono::December;
39
40 { // year_month_day_last - years
41
42 year_month_day_last ymdl{year{1234}, month_day_last{December}};
43 for (int i = 0; i <= 10; ++i) {
44 year_month_day_last ymdl1 = ymdl - years{i};
45 assert(static_cast<int>(ymdl1.year()) == 1234 - i);
46 assert(ymdl1.month() == December);
47 }
48 }
49
50 { // year_month_day_last - months
51
52 year_month_day_last ymdl{year{1234}, month_day_last{December}};
53 for (unsigned i = 0; i <= 10; ++i) {
54 year_month_day_last ymdl1 = ymdl - months{i};
55 assert(static_cast<int>(ymdl1.year()) == 1234);
56 assert(static_cast<unsigned>(ymdl1.month()) == 12U - i);
57 }
58 // Test the year wraps around.
59 for (unsigned i = 12; i <= 15; ++i) {
60 year_month_day_last ymdl1 = ymdl - months{i};
61 assert(static_cast<int>(ymdl1.year()) == 1233);
62 assert(static_cast<unsigned>(ymdl1.month()) == 12U - i + 12);
63 }
64 }
65
66 return true;
67}
68
69int main(int, char**) {
70 // year_month_day_last - years
71 ASSERT_NOEXCEPT(std::declval<year_month_day_last>() - std::declval<years>());
72 ASSERT_SAME_TYPE(year_month_day_last, decltype(std::declval<year_month_day_last>() - std::declval<years>()));
73
74 // year_month_day_last - months
75 ASSERT_NOEXCEPT(std::declval<year_month_day_last>() - std::declval<months>());
76 ASSERT_SAME_TYPE(year_month_day_last, decltype(std::declval<year_month_day_last>() - std::declval<months>()));
77
78 test();
79 static_assert(test());
80
81 return 0;
82}
83

source code of libcxx/test/std/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/minus.pass.cpp