libcxx

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

op_sys_days.pass.cpp (2503B)


      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_last;
     13 
     14 // constexpr operator sys_days() const noexcept;
     15 //  Returns: If ok() == true, returns a sys_days that represents the last weekday() 
     16 //             of year()/month(). Otherwise the returned value is unspecified.
     17 
     18 #include <chrono>
     19 #include <type_traits>
     20 #include <cassert>
     21 
     22 #include "test_macros.h"
     23 
     24 #include <iostream>
     25 
     26 int main()
     27 {
     28     using year                    = std::chrono::year;
     29     using month                   = std::chrono::month;
     30     using year_month_weekday_last = std::chrono::year_month_weekday_last;
     31     using sys_days                = std::chrono::sys_days;
     32     using days                    = std::chrono::days;
     33     using weekday                 = std::chrono::weekday;
     34     using weekday_last            = std::chrono::weekday_last;
     35 
     36     ASSERT_NOEXCEPT(                    static_cast<sys_days>(std::declval<const year_month_weekday_last>()));
     37     ASSERT_SAME_TYPE(sys_days, decltype(static_cast<sys_days>(std::declval<const year_month_weekday_last>())));
     38 
     39     constexpr month   January = std::chrono::January;
     40     constexpr weekday Tuesday = std::chrono::Tuesday;
     41 
     42     { // Last Tuesday in Jan 1970 was the 27th
     43     constexpr year_month_weekday_last ymwdl{year{1970}, January, weekday_last{Tuesday}};
     44     constexpr sys_days sd{ymwdl};
     45     
     46     static_assert(sd.time_since_epoch() == days{26}, "");
     47     }
     48 
     49     { // Last Tuesday in Jan 2000 was the 25th
     50     constexpr year_month_weekday_last ymwdl{year{2000}, January, weekday_last{Tuesday}};
     51     constexpr sys_days sd{ymwdl};
     52     
     53     static_assert(sd.time_since_epoch() == days{10957+24}, "");
     54     }
     55 
     56     { // Last Tuesday in Jan 1940 was the 30th
     57     constexpr year_month_weekday_last ymwdl{year{1940}, January, weekday_last{Tuesday}};
     58     constexpr sys_days sd{ymwdl};
     59     
     60     static_assert(sd.time_since_epoch() == days{-10958+29}, "");
     61     }
     62 
     63     { // Last Tuesday in Nov 1939 was the 28th
     64     year_month_weekday_last ymdl{year{1939}, std::chrono::November, weekday_last{Tuesday}};
     65     sys_days sd{ymdl};
     66 
     67     assert(sd.time_since_epoch() == days{-(10957+35)});
     68     }
     69 }