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

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