| 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 chrono::day day() const noexcept; |
| 14 | // Returns: wd_ |
| 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 = std::chrono::month; |
| 27 | using day = std::chrono::day; |
| 28 | using month_day_last = std::chrono::month_day_last; |
| 29 | using year_month_day_last = std::chrono::year_month_day_last; |
| 30 | |
| 31 | ASSERT_NOEXCEPT( std::declval<const year_month_day_last>().day()); |
| 32 | ASSERT_SAME_TYPE(day, decltype(std::declval<const year_month_day_last>().day())); |
| 33 | |
| 34 | // Some months have a 31st |
| 35 | static_assert( year_month_day_last{year{2020}, month_day_last{month{ 1}}}.day() == day{31}, "" ); |
| 36 | static_assert( year_month_day_last{year{2020}, month_day_last{month{ 2}}}.day() == day{29}, "" ); |
| 37 | static_assert( year_month_day_last{year{2020}, month_day_last{month{ 3}}}.day() == day{31}, "" ); |
| 38 | static_assert( year_month_day_last{year{2020}, month_day_last{month{ 4}}}.day() == day{30}, "" ); |
| 39 | static_assert( year_month_day_last{year{2020}, month_day_last{month{ 5}}}.day() == day{31}, "" ); |
| 40 | static_assert( year_month_day_last{year{2020}, month_day_last{month{ 6}}}.day() == day{30}, "" ); |
| 41 | static_assert( year_month_day_last{year{2020}, month_day_last{month{ 7}}}.day() == day{31}, "" ); |
| 42 | static_assert( year_month_day_last{year{2020}, month_day_last{month{ 8}}}.day() == day{31}, "" ); |
| 43 | static_assert( year_month_day_last{year{2020}, month_day_last{month{ 9}}}.day() == day{30}, "" ); |
| 44 | static_assert( year_month_day_last{year{2020}, month_day_last{month{10}}}.day() == day{31}, "" ); |
| 45 | static_assert( year_month_day_last{year{2020}, month_day_last{month{11}}}.day() == day{30}, "" ); |
| 46 | static_assert( year_month_day_last{year{2020}, month_day_last{month{12}}}.day() == day{31}, "" ); |
| 47 | |
| 48 | assert((year_month_day_last{year{2019}, month_day_last{month{ 2}}}.day() == day{28})); |
| 49 | assert((year_month_day_last{year{2020}, month_day_last{month{ 2}}}.day() == day{29})); |
| 50 | assert((year_month_day_last{year{2021}, month_day_last{month{ 2}}}.day() == day{28})); |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |