libcxx

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

ctor.sys_days.pass.cpp (2027B)


      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 weekday;
     13 
     14 //  constexpr weekday(const sys_days& dp) noexcept;
     15 //
     16 //  Effects:  Constructs an object of type weekday by computing what day
     17 //              of the week  corresponds to the sys_days dp, and representing
     18 //              that day of the week in wd_ 
     19 //
     20 //  Remarks: For any value ymd of type year_month_day for which ymd.ok() is true,
     21 //                ymd == year_month_day{sys_days{ymd}} is true.
     22 // 
     23 // [Example: 
     24 //  If dp represents 1970-01-01, the constructed weekday represents Thursday by storing 4 in wd_.
     25 // —end example]
     26 
     27 #include <chrono>
     28 #include <type_traits>
     29 #include <cassert>
     30 
     31 #include "test_macros.h"
     32 
     33 int main()
     34 {
     35     using sys_days  = std::chrono::sys_days;
     36     using days      = std::chrono::days;
     37     using weekday   = std::chrono::weekday;
     38 
     39     ASSERT_NOEXCEPT(weekday{std::declval<sys_days>()});
     40 
     41     {
     42     constexpr sys_days sd{}; // 1-Jan-1970 was a Thursday
     43     constexpr weekday wd{sd};
     44 
     45     static_assert( wd.ok(), "");
     46     static_assert(static_cast<unsigned>(wd) == 4, "");
     47     }
     48 
     49     {
     50     constexpr sys_days sd{days{10957+32}}; // 2-Feb-2000 was a Wednesday
     51     constexpr weekday wd{sd};
     52 
     53     static_assert( wd.ok(), "");
     54     static_assert(static_cast<unsigned>(wd) == 3, "");
     55     }
     56 
     57 
     58     {
     59     constexpr sys_days sd{days{-10957}}; // 2-Jan-1940 was a Tuesday
     60     constexpr weekday wd{sd};
     61 
     62     static_assert( wd.ok(), "");
     63     static_assert(static_cast<unsigned>(wd) == 2, "");
     64     }
     65 
     66     {
     67     sys_days sd{days{-(10957+34)}}; // 29-Nov-1939 was a Wednesday
     68     weekday wd{sd};
     69 
     70     assert( wd.ok());
     71     assert(static_cast<unsigned>(wd) == 3);
     72     }
     73 }