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