Debian Codegraph @

libcxx/test/std/time/time.cal/time.cal.weekday/time.cal.weekday.members/ctor.local_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 weekday;
12
13 // constexpr weekday(const local_days& dp) noexcept;
14 //
15 // Effects: Constructs an object of type weekday by computing what day
16 // of the week corresponds to the local_days dp, and representing
17 // that day of the week in wd_
18 //
19 // Remarks: For any value ymd of type year_month_day for which ymd.ok() is true,
20 // ymd == year_month_day{sys_days{ymd}} is true.
21 //
22 // [Example:
23 // If dp represents 1970-01-01, the constructed weekday represents Thursday by storing 4 in wd_.
24 // -end example]
25
26 #include <chrono>
27 #include <type_traits>
28 #include <cassert>
29
30 #include "test_macros.h"
31
32 int main(int, char**)
33 {
34 using local_days = std::chrono::local_days;
35 using days = std::chrono::days;
36 using weekday = std::chrono::weekday;
37
38 ASSERT_NOEXCEPT(weekday{std::declval<local_days>()});
39
40 {
41 constexpr local_days sd{}; // 1-Jan-1970 was a Thursday
42 constexpr weekday wd{sd};
43
44 static_assert( wd.ok(), "");
45 static_assert( wd.c_encoding() == 4, "");
46 }
47
48 {
49 constexpr local_days sd{days{10957+32}}; // 2-Feb-2000 was a Wednesday
50 constexpr weekday wd{sd};
51
52 static_assert( wd.ok(), "");
53 static_assert( wd.c_encoding() == 3, "");
54 }
55
56
57 {
58 constexpr local_days sd{days{-10957}}; // 2-Jan-1940 was a Tuesday
59 constexpr weekday wd{sd};
60
61 static_assert( wd.ok(), "");
62 static_assert( wd.c_encoding() == 2, "");
63 }
64
65 {
66 local_days sd{days{-(10957+34)}}; // 29-Nov-1939 was a Wednesday
67 weekday wd{sd};
68
69 assert( wd.ok());
70 assert( wd.c_encoding() == 3);
71 }
72
73 return 0;
74 }