ctor.local_days.pass.cpp (2689B)
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; 13 14 // explicit constexpr year_month_day(const local_days& dp) noexcept; 15 // 16 // 17 // Effects: Constructs an object of type year_month_day that corresponds 18 // to the date represented by dp 19 // 20 // Remarks: Equivalent to constructing with sys_days{dp.time_since_epoch()}. 21 // 22 // constexpr chrono::year year() const noexcept; 23 // constexpr chrono::month month() const noexcept; 24 // constexpr chrono::day day() const noexcept; 25 // constexpr bool ok() const noexcept; 26 27 #include <chrono> 28 #include <type_traits> 29 #include <cassert> 30 31 #include "test_macros.h" 32 33 int main() 34 { 35 using year = std::chrono::year; 36 using day = std::chrono::day; 37 using local_days = std::chrono::local_days; 38 using days = std::chrono::days; 39 using year_month_day = std::chrono::year_month_day; 40 41 ASSERT_NOEXCEPT(year_month_day{std::declval<local_days>()}); 42 43 { 44 constexpr local_days sd{}; 45 constexpr year_month_day ymd{sd}; 46 47 static_assert( ymd.ok(), ""); 48 static_assert( ymd.year() == year{1970}, ""); 49 static_assert( ymd.month() == std::chrono::January, ""); 50 static_assert( ymd.day() == day{1}, ""); 51 } 52 53 { 54 constexpr local_days sd{days{10957+32}}; 55 constexpr year_month_day ymd{sd}; 56 57 static_assert( ymd.ok(), ""); 58 static_assert( ymd.year() == year{2000}, ""); 59 static_assert( ymd.month() == std::chrono::February, ""); 60 static_assert( ymd.day() == day{2}, ""); 61 } 62 63 64 // There's one more leap day between 1/1/40 and 1/1/70 65 // when compared to 1/1/70 -> 1/1/2000 66 { 67 constexpr local_days sd{days{-10957}}; 68 constexpr year_month_day ymd{sd}; 69 70 static_assert( ymd.ok(), ""); 71 static_assert( ymd.year() == year{1940}, ""); 72 static_assert( ymd.month() == std::chrono::January, ""); 73 static_assert( ymd.day() == day{2}, ""); 74 } 75 76 { 77 local_days sd{days{-(10957+34)}}; 78 year_month_day ymd{sd}; 79 80 assert( ymd.ok()); 81 assert( ymd.year() == year{1939}); 82 assert( ymd.month() == std::chrono::November); 83 assert( ymd.day() == day{29}); 84 } 85 }