libcxx

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

ctor.local_days.pass.cpp (4335B)


      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 //  explicit constexpr year_month_weekday(const local_days& dp) noexcept;
     15 //
     16 //
     17 //  Effects:  Constructs an object of type year_month_weekday 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 days               = std::chrono::days;
     37     using local_days         = std::chrono::local_days;
     38     using weekday_indexed    = std::chrono::weekday_indexed;
     39     using year_month_weekday = std::chrono::year_month_weekday;
     40 
     41     ASSERT_NOEXCEPT(year_month_weekday{std::declval<const local_days>()});
     42 
     43     {
     44     constexpr local_days sd{}; // 1-Jan-1970 was a Thursday
     45     constexpr year_month_weekday ymwd{sd};
     46 
     47     static_assert( ymwd.ok(),                                                            "");
     48     static_assert( ymwd.year()            == year{1970},                                 "");
     49     static_assert( ymwd.month()           == std::chrono::January,                       "");
     50     static_assert( ymwd.weekday()         == std::chrono::Thursday,                      "");
     51     static_assert( ymwd.index()           == 1,                                          "");
     52     static_assert( ymwd.weekday_indexed() == weekday_indexed{std::chrono::Thursday, 1},  "");
     53     static_assert( ymwd                   == year_month_weekday{local_days{ymwd}},       ""); // round trip
     54     }
     55 
     56     {
     57     constexpr local_days sd{days{10957+32}}; // 2-Feb-2000 was a Wednesday
     58     constexpr year_month_weekday ymwd{sd};
     59 
     60     static_assert( ymwd.ok(),                                                            "");
     61     static_assert( ymwd.year()            == year{2000},                                 "");
     62     static_assert( ymwd.month()           == std::chrono::February,                      "");
     63     static_assert( ymwd.weekday()         == std::chrono::Wednesday,                     "");
     64     static_assert( ymwd.index()           == 1,                                          "");
     65     static_assert( ymwd.weekday_indexed() == weekday_indexed{std::chrono::Wednesday, 1}, "");
     66     static_assert( ymwd                   == year_month_weekday{local_days{ymwd}},       ""); // round trip
     67     }
     68 
     69 
     70     {
     71     constexpr local_days sd{days{-10957}}; // 2-Jan-1940 was a Tuesday
     72     constexpr year_month_weekday ymwd{sd};
     73 
     74     static_assert( ymwd.ok(),                                                            "");
     75     static_assert( ymwd.year()            == year{1940},                                 "");
     76     static_assert( ymwd.month()           == std::chrono::January,                       "");
     77     static_assert( ymwd.weekday()         == std::chrono::Tuesday,                       "");
     78     static_assert( ymwd.index()           == 1,                                          "");
     79     static_assert( ymwd.weekday_indexed() == weekday_indexed{std::chrono::Tuesday, 1},   "");
     80     static_assert( ymwd                   == year_month_weekday{local_days{ymwd}},       ""); // round trip
     81     }
     82 
     83     {
     84     local_days sd{days{-(10957+34)}}; // 29-Nov-1939 was a Wednesday
     85     year_month_weekday ymwd{sd};
     86 
     87     assert( ymwd.ok());
     88     assert( ymwd.year()            == year{1939});
     89     assert( ymwd.month()           == std::chrono::November);
     90     assert( ymwd.weekday()         == std::chrono::Wednesday);
     91     assert( ymwd.index()           == 5);
     92     assert((ymwd.weekday_indexed() == weekday_indexed{std::chrono::Wednesday, 5}));
     93     assert( ymwd                   == year_month_weekday{local_days{ymwd}}); // round trip
     94     }
     95 }