| 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-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
// UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 9 |
|
| 10 |
// <chrono> |
| 11 |
// class month_day; |
| 12 |
|
| 13 |
// constexpr bool ok() const noexcept; |
| 14 |
// Returns: true if m_.ok() is true, 1d <= d_, and d_ is less than or equal to the |
| 15 |
// number of days in month m_; otherwise returns false. |
| 16 |
// When m_ == February, the number of days is considered to be 29. |
| 17 |
|
| 18 |
#include <chrono> |
| 19 |
#include <type_traits> |
| 20 |
#include <cassert> |
| 21 |
|
| 22 |
#include "test_macros.h" |
| 23 |
|
| 24 |
int main(int, char**) |
| 25 |
{ |
| 26 |
using day = std::chrono::day; |
| 27 |
using month = std::chrono::month; |
| 28 |
using month_day = std::chrono::month_day; |
| 29 |
|
| 30 |
ASSERT_NOEXCEPT( std::declval<const month_day>().ok()); |
| 31 |
ASSERT_SAME_TYPE(bool, decltype(std::declval<const month_day>().ok())); |
| 32 |
|
| 33 |
static_assert(!month_day{}.ok(), ""); |
| 34 |
static_assert( month_day{std::chrono::May, day{2}}.ok(), ""); |
| 35 |
|
| 36 |
assert(!(month_day(std::chrono::April, day{0}).ok())); |
| 37 |
|
| 38 |
assert( (month_day{std::chrono::March, day{1}}.ok())); |
| 39 |
for (unsigned i = 1; i <= 12; ++i) |
| 40 |
{ |
| 41 |
const bool is31 = i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12; |
| 42 |
assert(!(month_day{month{i}, day{ 0}}.ok())); |
| 43 |
assert( (month_day{month{i}, day{ 1}}.ok())); |
| 44 |
assert( (month_day{month{i}, day{10}}.ok())); |
| 45 |
assert( (month_day{month{i}, day{29}}.ok())); |
| 46 |
assert( (month_day{month{i}, day{30}}.ok()) == (i != 2)); |
| 47 |
assert( (month_day{month{i}, day{31}}.ok()) == is31); |
| 48 |
assert(!(month_day{month{i}, day{32}}.ok())); |
| 49 |
} |
| 50 |
|
| 51 |
// If the month is not ok, all the days are bad |
| 52 |
for (unsigned i = 1; i <= 35; ++i) |
| 53 |
assert(!(month_day{month{13}, day{i}}.ok())); |
| 54 |
|
| 55 |
return 0; |
| 56 |
} |