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 <cassert>
28#include <type_traits>
29#include <utility>
30
31#include "test_macros.h"
32
33int main(int, char**)
34{
35 using local_days = std::chrono::local_days;
36 using days = std::chrono::days;
37 using weekday = std::chrono::weekday;
38
39 ASSERT_NOEXCEPT(weekday{std::declval<local_days>()});
40
41 {
42 constexpr local_days sd{}; // 1-Jan-1970 was a Thursday
43 constexpr weekday wd{sd};
44
45 static_assert( wd.ok(), "");
46 static_assert( wd.c_encoding() == 4, "");
47 }
48
49 {
50 constexpr local_days sd{days{10957+32}}; // 2-Feb-2000 was a Wednesday
51 constexpr weekday wd{sd};
52
53 static_assert( wd.ok(), "");
54 static_assert( wd.c_encoding() == 3, "");
55 }
56
57
58 {
59 constexpr local_days sd{days{-10957}}; // 2-Jan-1940 was a Tuesday
60 constexpr weekday wd{sd};
61
62 static_assert( wd.ok(), "");
63 static_assert( wd.c_encoding() == 2, "");
64 }
65
66 {
67 local_days sd{days{-(10957+34)}}; // 29-Nov-1939 was a Wednesday
68 weekday wd{sd};
69
70 assert( wd.ok());
71 assert( wd.c_encoding() == 3);
72 }
73
74 return 0;
75}
76

source code of libcxx/test/std/time/time.cal/time.cal.weekday/time.cal.weekday.members/ctor.local_days.pass.cpp