libcxx

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

op_local_days.pass.cpp (1996B)


      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_last;
     13 
     14 // constexpr operator local_days() const noexcept;
     15 //  Returns: local_days{sys_days{*this}.time_since_epoch()}.
     16 
     17 #include <chrono>
     18 #include <type_traits>
     19 #include <cassert>
     20 
     21 #include "test_macros.h"
     22 
     23 int main()
     24 {
     25     using year                = std::chrono::year;
     26     using month_day_last      = std::chrono::month_day_last;
     27     using year_month_day_last = std::chrono::year_month_day_last;
     28     using local_days          = std::chrono::local_days;
     29     using days                = std::chrono::days;
     30 
     31     ASSERT_NOEXCEPT(                      static_cast<local_days>(std::declval<const year_month_day_last>()));
     32     ASSERT_SAME_TYPE(local_days, decltype(static_cast<local_days>(std::declval<const year_month_day_last>())));
     33 
     34     { // Last day in Jan 1970 was the 31st
     35     constexpr year_month_day_last ymdl{year{1970}, month_day_last{std::chrono::January}};
     36     constexpr local_days sd{ymdl};
     37     
     38     static_assert(sd.time_since_epoch() == days{30}, "");
     39     }
     40 
     41     {
     42     constexpr year_month_day_last ymdl{year{2000}, month_day_last{std::chrono::January}};
     43     constexpr local_days sd{ymdl};
     44 
     45     static_assert(sd.time_since_epoch() == days{10957+30}, "");
     46     }
     47 
     48     {
     49     constexpr year_month_day_last ymdl{year{1940}, month_day_last{std::chrono::January}};
     50     constexpr local_days sd{ymdl};
     51 
     52     static_assert(sd.time_since_epoch() == days{-10957+29}, "");
     53     }
     54 
     55     {
     56     year_month_day_last ymdl{year{1939}, month_day_last{std::chrono::November}};
     57     local_days sd{ymdl};
     58 
     59     assert(sd.time_since_epoch() == days{-(10957+33)});
     60     }
     61 }