brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 2f68fb4 Raw
88 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8// UNSUPPORTED: c++03, c++11, c++14, c++179 10// <chrono>11// class year_month_day;12 13//  explicit constexpr year_month_day(const local_days& dp) noexcept;14//15//16//  Effects:  Constructs an object of type year_month_day that corresponds17//                to the date represented by dp18//19//  Remarks: Equivalent to constructing with sys_days{dp.time_since_epoch()}.20//21//  constexpr chrono::year   year() const noexcept;22//  constexpr chrono::month month() const noexcept;23//  constexpr chrono::day     day() const noexcept;24//  constexpr bool             ok() const noexcept;25 26#include <chrono>27#include <cassert>28#include <type_traits>29#include <utility>30 31#include "test_macros.h"32 33int main(int, char**)34{35    using year           = std::chrono::year;36    using day            = std::chrono::day;37    using local_days     = std::chrono::local_days;38    using days           = std::chrono::days;39    using year_month_day = std::chrono::year_month_day;40 41    ASSERT_NOEXCEPT(year_month_day{std::declval<local_days>()});42 43    {44    constexpr local_days sd{};45    constexpr year_month_day ymd{sd};46 47    static_assert( ymd.ok(),                            "");48    static_assert( ymd.year()  == year{1970},           "");49    static_assert( ymd.month() == std::chrono::January, "");50    static_assert( ymd.day()   == day{1},               "");51    }52 53    {54    constexpr local_days sd{days{10957+32}};55    constexpr year_month_day ymd{sd};56 57    static_assert( ymd.ok(),                             "");58    static_assert( ymd.year()  == year{2000},            "");59    static_assert( ymd.month() == std::chrono::February, "");60    static_assert( ymd.day()   == day{2},                "");61    }62 63 64//  There's one more leap day between 1/1/40 and 1/1/7065//  when compared to 1/1/70 -> 1/1/200066    {67    constexpr local_days sd{days{-10957}};68    constexpr year_month_day ymd{sd};69 70    static_assert( ymd.ok(),                            "");71    static_assert( ymd.year()  == year{1940},           "");72    static_assert( ymd.month() == std::chrono::January, "");73    static_assert( ymd.day()   == day{2},               "");74    }75 76    {77    local_days sd{days{-(10957+34)}};78    year_month_day ymd{sd};79 80    assert( ymd.ok());81    assert( ymd.year()  == year{1939});82    assert( ymd.month() == std::chrono::November);83    assert( ymd.day()   == day{29});84    }85 86  return 0;87}88