1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
10
11 // <chrono>
12 // class year_month_day_last;
13
14 // constexpr chrono::day day() const noexcept;
15 // Returns: wd_
16
17 #include <chrono>
18 #include <type_traits>
19 #include <cassert>
20
21 #include "test_macros.h"
22
main()23 int main()
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