libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

ctor.sys_days.pass.cpp (4331B)


      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_weekday;
     13 
     14 //  constexpr year_month_weekday(const sys_days& dp) noexcept;
     15 //
     16 //  Effects:  Constructs an object of type year_month_weekday that corresponds
     17 //                to the date represented by dp
     18 //
     19 //  Remarks: For any value ymd of type year_month_weekday for which ymd.ok() is true,
     20 //                ymd == year_month_weekday{sys_days{ymd}} is true.
     21 //
     22 //  constexpr chrono::year   year() const noexcept;
     23 //  constexpr chrono::month month() const noexcept;
     24 //  constexpr bool             ok() const noexcept;
     25 
     26 #include <chrono>
     27 #include <type_traits>
     28 #include <cassert>
     29 
     30 #include "test_macros.h"
     31 
     32 int main()
     33 {
     34     using year               = std::chrono::year;
     35     using days               = std::chrono::days;
     36     using sys_days           = std::chrono::sys_days;
     37     using weekday_indexed    = std::chrono::weekday_indexed;
     38     using year_month_weekday = std::chrono::year_month_weekday;
     39 
     40     ASSERT_NOEXCEPT(year_month_weekday{std::declval<const sys_days>()});
     41 
     42     {
     43     constexpr sys_days sd{}; // 1-Jan-1970 was a Thursday
     44     constexpr year_month_weekday ymwd{sd};
     45 
     46     static_assert( ymwd.ok(),                                                            "");
     47     static_assert( ymwd.year()            == year{1970},                                 "");
     48     static_assert( ymwd.month()           == std::chrono::January,                       "");
     49     static_assert( ymwd.weekday()         == std::chrono::Thursday,                      "");
     50     static_assert( ymwd.index()           == 1,                                          "");
     51     static_assert( ymwd.weekday_indexed() == weekday_indexed{std::chrono::Thursday, 1},  "");
     52     static_assert( ymwd                   == year_month_weekday{sys_days{ymwd}},         ""); // round trip
     53     }
     54 
     55     {
     56     constexpr sys_days sd{days{10957+32}}; // 2-Feb-2000 was a Wednesday
     57     constexpr year_month_weekday ymwd{sd};
     58 
     59     static_assert( ymwd.ok(),                                                            "");
     60     static_assert( ymwd.year()            == year{2000},                                 "");
     61     static_assert( ymwd.month()           == std::chrono::February,                      "");
     62     static_assert( ymwd.weekday()         == std::chrono::Wednesday,                     "");
     63     static_assert( ymwd.index()           == 1,                                          "");
     64     static_assert( ymwd.weekday_indexed() == weekday_indexed{std::chrono::Wednesday, 1}, "");
     65     static_assert( ymwd                   == year_month_weekday{sys_days{ymwd}},         ""); // round trip
     66     }
     67 
     68 
     69     {
     70     constexpr sys_days sd{days{-10957}}; // 2-Jan-1940 was a Tuesday
     71     constexpr year_month_weekday ymwd{sd};
     72 
     73     static_assert( ymwd.ok(),                                                            "");
     74     static_assert( ymwd.year()            == year{1940},                                 "");
     75     static_assert( ymwd.month()           == std::chrono::January,                       "");
     76     static_assert( ymwd.weekday()         == std::chrono::Tuesday,                       "");
     77     static_assert( ymwd.index()           == 1,                                          "");
     78     static_assert( ymwd.weekday_indexed() == weekday_indexed{std::chrono::Tuesday, 1},   "");
     79     static_assert( ymwd                   == year_month_weekday{sys_days{ymwd}},         ""); // round trip
     80     }
     81 
     82     {
     83     sys_days sd{days{-(10957+34)}}; // 29-Nov-1939 was a Wednesday
     84     year_month_weekday ymwd{sd};
     85 
     86     assert( ymwd.ok());
     87     assert( ymwd.year()            == year{1939});
     88     assert( ymwd.month()           == std::chrono::November);
     89     assert( ymwd.weekday()         == std::chrono::Wednesday);
     90     assert( ymwd.index()           == 5);
     91     assert((ymwd.weekday_indexed() == weekday_indexed{std::chrono::Wednesday, 5}));
     92     assert( ymwd                   == year_month_weekday{sys_days{ymwd}}); // round trip
     93     }
     94 }