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