Debian Codegraph @

libcxx/test/std/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/op_sys_days.pass.cpp

raw
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_last;
12
13 // constexpr operator sys_days() const noexcept;
14 // Returns: If ok() == true, returns a sys_days that represents the last weekday()
15 // of year()/month(). Otherwise the returned value is unspecified.
16
17 #include <chrono>
18 #include <type_traits>
19 #include <cassert>
20
21 #include "test_macros.h"
22
23
24 int main(int, char**)
25 {
26 using year = std::chrono::year;
27 using month = std::chrono::month;
28 using year_month_weekday_last = std::chrono::year_month_weekday_last;
29 using sys_days = std::chrono::sys_days;
30 using days = std::chrono::days;
31 using weekday = std::chrono::weekday;
32 using weekday_last = std::chrono::weekday_last;
33
34 ASSERT_NOEXCEPT( static_cast<sys_days>(std::declval<const year_month_weekday_last>()));
35 ASSERT_SAME_TYPE(sys_days, decltype(static_cast<sys_days>(std::declval<const year_month_weekday_last>())));
36
37 constexpr month January = std::chrono::January;
38 constexpr weekday Tuesday = std::chrono::Tuesday;
39
40 { // Last Tuesday in Jan 1970 was the 27th
41 constexpr year_month_weekday_last ymwdl{year{1970}, January, weekday_last{Tuesday}};
42 constexpr sys_days sd{ymwdl};
43
44 static_assert(sd.time_since_epoch() == days{26}, "");
45 }
46
47 { // Last Tuesday in Jan 2000 was the 25th
48 constexpr year_month_weekday_last ymwdl{year{2000}, January, weekday_last{Tuesday}};
49 constexpr sys_days sd{ymwdl};
50
51 static_assert(sd.time_since_epoch() == days{10957+24}, "");
52 }
53
54 { // Last Tuesday in Jan 1940 was the 30th
55 constexpr year_month_weekday_last ymwdl{year{1940}, January, weekday_last{Tuesday}};
56 constexpr sys_days sd{ymwdl};
57
58 static_assert(sd.time_since_epoch() == days{-10958+29}, "");
59 }
60
61 { // Last Tuesday in Nov 1939 was the 28th
62 year_month_weekday_last ymdl{year{1939}, std::chrono::November, weekday_last{Tuesday}};
63 sys_days sd{ymdl};
64
65 assert(sd.time_since_epoch() == days{-(10957+35)});
66 }
67
68 return 0;
69 }