| 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; |
| 12 | |
| 13 | // constexpr year_month_day(const year_month_day_last& ymdl) noexcept; |
| 14 | // |
| 15 | // Effects: Constructs an object of type year_month_day by initializing |
| 16 | // y_ with ymdl.year(), m_ with ymdl.month(), and d_ with ymdl.day(). |
| 17 | // |
| 18 | // constexpr chrono::year year() const noexcept; |
| 19 | // constexpr chrono::month month() const noexcept; |
| 20 | // constexpr chrono::day day() const noexcept; |
| 21 | // constexpr bool ok() const noexcept; |
| 22 | |
| 23 | #include <chrono> |
| 24 | #include <cassert> |
| 25 | #include <type_traits> |
| 26 | #include <utility> |
| 27 | |
| 28 | #include "test_macros.h" |
| 29 | |
| 30 | int main(int, char**) |
| 31 | { |
| 32 | using year = std::chrono::year; |
| 33 | using month = std::chrono::month; |
| 34 | using day = std::chrono::day; |
| 35 | using month_day_last = std::chrono::month_day_last; |
| 36 | using year_month_day_last = std::chrono::year_month_day_last; |
| 37 | using year_month_day = std::chrono::year_month_day; |
| 38 | |
| 39 | ASSERT_NOEXCEPT(year_month_day{std::declval<const year_month_day_last>()}); |
| 40 | |
| 41 | { |
| 42 | constexpr year_month_day_last ymdl{year{2019}, month_day_last{month{1}}}; |
| 43 | constexpr year_month_day ymd{ymdl}; |
| 44 | |
| 45 | static_assert( ymd.year() == year{2019}, "" ); |
| 46 | static_assert( ymd.month() == month{1}, "" ); |
| 47 | static_assert( ymd.day() == day{31}, "" ); |
| 48 | static_assert( ymd.ok(), "" ); |
| 49 | } |
| 50 | |
| 51 | { |
| 52 | constexpr year_month_day_last ymdl{year{1970}, month_day_last{month{4}}}; |
| 53 | constexpr year_month_day ymd{ymdl}; |
| 54 | |
| 55 | static_assert( ymd.year() == year{1970}, "" ); |
| 56 | static_assert( ymd.month() == month{4}, "" ); |
| 57 | static_assert( ymd.day() == day{30}, "" ); |
| 58 | static_assert( ymd.ok(), "" ); |
| 59 | } |
| 60 | |
| 61 | { |
| 62 | constexpr year_month_day_last ymdl{year{2000}, month_day_last{month{2}}}; |
| 63 | constexpr year_month_day ymd{ymdl}; |
| 64 | |
| 65 | static_assert( ymd.year() == year{2000}, "" ); |
| 66 | static_assert( ymd.month() == month{2}, "" ); |
| 67 | static_assert( ymd.day() == day{29}, "" ); |
| 68 | static_assert( ymd.ok(), "" ); |
| 69 | } |
| 70 | |
| 71 | { // Feb 1900 was NOT a leap year. |
| 72 | year_month_day_last ymdl{year{1900}, month_day_last{month{2}}}; |
| 73 | year_month_day ymd{ymdl}; |
| 74 | |
| 75 | assert( ymd.year() == year{1900}); |
| 76 | assert( ymd.month() == month{2}); |
| 77 | assert( ymd.day() == day{28}); |
| 78 | assert( ymd.ok()); |
| 79 | } |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |