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 <cassert>
20#include <type_traits>
21#include <utility>
22
23#include "test_macros.h"
24
25int main(int, char**)
26{
27 using day = std::chrono::day;
28 using month = std::chrono::month;
29 using month_day = std::chrono::month_day;
30
31 ASSERT_NOEXCEPT( std::declval<const month_day>().ok());
32 ASSERT_SAME_TYPE(bool, decltype(std::declval<const month_day>().ok()));
33
34 static_assert(!month_day{}.ok(), "");
35 static_assert( month_day{std::chrono::May, day{2}}.ok(), "");
36
37 assert(!(month_day(std::chrono::April, day{0}).ok()));
38
39 assert( (month_day{std::chrono::March, day{1}}.ok()));
40 for (unsigned i = 1; i <= 12; ++i)
41 {
42 const bool is31 = i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12;
43 assert(!(month_day{month{i}, day{ 0}}.ok()));
44 assert( (month_day{month{i}, day{ 1}}.ok()));
45 assert( (month_day{month{i}, day{10}}.ok()));
46 assert( (month_day{month{i}, day{29}}.ok()));
47 assert( (month_day{month{i}, day{30}}.ok()) == (i != 2));
48 assert( (month_day{month{i}, day{31}}.ok()) == is31);
49 assert(!(month_day{month{i}, day{32}}.ok()));
50 }
51
52 // If the month is not ok, all the days are bad
53 for (unsigned i = 1; i <= 35; ++i)
54 assert(!(month_day{month{13}, day{i}}.ok()));
55
56 return 0;
57}
58

source code of libcxx/test/std/time/time.cal/time.cal.md/time.cal.md.members/ok.pass.cpp