• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <type_traits>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 
main(int,char **)22 int main(int, char**)
23 {
24     using year                = std::chrono::year;
25     using month               = std::chrono::month;
26     using day                 = std::chrono::day;
27     using month_day_last      = std::chrono::month_day_last;
28     using year_month_day_last = std::chrono::year_month_day_last;
29 
30     ASSERT_NOEXCEPT(               std::declval<const year_month_day_last>().day());
31     ASSERT_SAME_TYPE(day, decltype(std::declval<const year_month_day_last>().day()));
32 
33 //  Some months have a 31st
34     static_assert( year_month_day_last{year{2020}, month_day_last{month{ 1}}}.day() == day{31}, "");
35     static_assert( year_month_day_last{year{2020}, month_day_last{month{ 2}}}.day() == day{29}, "");
36     static_assert( year_month_day_last{year{2020}, month_day_last{month{ 3}}}.day() == day{31}, "");
37     static_assert( year_month_day_last{year{2020}, month_day_last{month{ 4}}}.day() == day{30}, "");
38     static_assert( year_month_day_last{year{2020}, month_day_last{month{ 5}}}.day() == day{31}, "");
39     static_assert( year_month_day_last{year{2020}, month_day_last{month{ 6}}}.day() == day{30}, "");
40     static_assert( year_month_day_last{year{2020}, month_day_last{month{ 7}}}.day() == day{31}, "");
41     static_assert( year_month_day_last{year{2020}, month_day_last{month{ 8}}}.day() == day{31}, "");
42     static_assert( year_month_day_last{year{2020}, month_day_last{month{ 9}}}.day() == day{30}, "");
43     static_assert( year_month_day_last{year{2020}, month_day_last{month{10}}}.day() == day{31}, "");
44     static_assert( year_month_day_last{year{2020}, month_day_last{month{11}}}.day() == day{30}, "");
45     static_assert( year_month_day_last{year{2020}, month_day_last{month{12}}}.day() == day{31}, "");
46 
47     assert((year_month_day_last{year{2019}, month_day_last{month{ 2}}}.day() == day{28}));
48     assert((year_month_day_last{year{2020}, month_day_last{month{ 2}}}.day() == day{29}));
49     assert((year_month_day_last{year{2021}, month_day_last{month{ 2}}}.day() == day{28}));
50 
51   return 0;
52 }
53