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 operator local_days() const noexcept;
14 // Returns: local_days{sys_days{*this}.time_since_epoch()}.
15
16 #include <chrono>
17 #include <type_traits>
18 #include <cassert>
19
20 #include "test_macros.h"
21
main(int,char **)22 int main(int, char**)
23 {
24 using year = std::chrono::year;
25 using month_day_last = std::chrono::month_day_last;
26 using year_month_day_last = std::chrono::year_month_day_last;
27 using local_days = std::chrono::local_days;
28 using days = std::chrono::days;
29
30 ASSERT_NOEXCEPT( static_cast<local_days>(std::declval<const year_month_day_last>()));
31 ASSERT_SAME_TYPE(local_days, decltype(static_cast<local_days>(std::declval<const year_month_day_last>())));
32
33 { // Last day in Jan 1970 was the 31st
34 constexpr year_month_day_last ymdl{year{1970}, month_day_last{std::chrono::January}};
35 constexpr local_days sd{ymdl};
36
37 static_assert(sd.time_since_epoch() == days{30}, "");
38 }
39
40 {
41 constexpr year_month_day_last ymdl{year{2000}, month_day_last{std::chrono::January}};
42 constexpr local_days sd{ymdl};
43
44 static_assert(sd.time_since_epoch() == days{10957+30}, "");
45 }
46
47 {
48 constexpr year_month_day_last ymdl{year{1940}, month_day_last{std::chrono::January}};
49 constexpr local_days sd{ymdl};
50
51 static_assert(sd.time_since_epoch() == days{-10957+29}, "");
52 }
53
54 {
55 year_month_day_last ymdl{year{1939}, month_day_last{std::chrono::November}};
56 local_days sd{ymdl};
57
58 assert(sd.time_since_epoch() == days{-(10957+33)});
59 }
60
61 return 0;
62 }
63