1,033 changes: 1,032 additions & 1 deletion libcxx/include/chrono

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions libcxx/test/std/utilities/time/days.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>

// using days = duration<signed integer type of at least 25 bits, ratio_multiply<ratio<24>, hours::period>>;

#include <chrono>
#include <type_traits>
#include <limits>

int main()
{
typedef std::chrono::days D;
typedef D::rep Rep;
typedef D::period Period;
static_assert(std::is_signed<Rep>::value, "");
static_assert(std::is_integral<Rep>::value, "");
static_assert(std::numeric_limits<Rep>::digits >= 25, "");
static_assert(std::is_same_v<Period, std::ratio_multiply<std::ratio<24>, std::chrono::hours::period>>, "");
}
29 changes: 29 additions & 0 deletions libcxx/test/std/utilities/time/months.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>

// using months = duration<signed integer type of at least 20 bits, ratio_divide<years::period, ratio<12>>>;


#include <chrono>
#include <type_traits>
#include <limits>

int main()
{
typedef std::chrono::months D;
typedef D::rep Rep;
typedef D::period Period;
static_assert(std::is_signed<Rep>::value, "");
static_assert(std::is_integral<Rep>::value, "");
static_assert(std::numeric_limits<Rep>::digits >= 20, "");
static_assert(std::is_same_v<Period, std::ratio_divide<std::chrono::years::period, std::ratio<12>>>, "");
}
40 changes: 40 additions & 0 deletions libcxx/test/std/utilities/time/time.cal/euclidian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//


// Assumption: minValue < maxValue
// Assumption: minValue <= rhs <= maxValue
// Assumption: minValue <= lhs <= maxValue
// Assumption: minValue >= 0
template <typename T, T minValue, T maxValue>
T euclidian_addition(T rhs, T lhs)
{
const T modulus = maxValue - minValue + 1;
T ret = rhs + lhs;
if (ret > maxValue)
ret -= modulus;
return ret;
}

// Assumption: minValue < maxValue
// Assumption: minValue <= rhs <= maxValue
// Assumption: minValue <= lhs <= maxValue
// Assumption: minValue >= 0
template <typename T, T minValue, T maxValue>
T euclidian_subtraction(T lhs, T rhs)
{
const T modulus = maxValue - minValue + 1;
T ret = lhs - rhs;
if (ret < minValue)
ret += modulus;
if (ret > maxValue) // this can happen if T is unsigned
ret += modulus;
return ret;
}

12 changes: 12 additions & 0 deletions libcxx/test/std/utilities/time/time.cal/nothing_to_do.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

int main()
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class day;

// day() = default;
// explicit constexpr day(unsigned d) noexcept;
// explicit constexpr operator unsigned() const noexcept;

// Effects: Constructs an object of type day by initializing d_ with d.
// The value held is unspecified if d is not in the range [0, 255].

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using day = std::chrono::day;

ASSERT_NOEXCEPT(day{});
ASSERT_NOEXCEPT(day(0U));
ASSERT_NOEXCEPT(static_cast<unsigned>(day(0U)));

constexpr day d0{};
static_assert(static_cast<unsigned>(d0) == 0, "");

constexpr day d1{1};
static_assert(static_cast<unsigned>(d1) == 1, "");

for (unsigned i = 0; i <= 255; ++i)
{
day day(i);
assert(static_cast<unsigned>(day) == i);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class day;

// constexpr day& operator--() noexcept;
// constexpr day operator--(int) noexcept;


#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

template <typename D>
constexpr bool testConstexpr()
{
D d1{10};
if (static_cast<unsigned>(--d1) != 9) return false;
if (static_cast<unsigned>(d1--) != 9) return false;
if (static_cast<unsigned>(d1) != 8) return false;
return true;
}

int main()
{
using day = std::chrono::day;
ASSERT_NOEXCEPT(--(std::declval<day&>()) );
ASSERT_NOEXCEPT( (std::declval<day&>())--);

ASSERT_SAME_TYPE(day , decltype( std::declval<day&>()--));
ASSERT_SAME_TYPE(day&, decltype(--std::declval<day&>() ));

static_assert(testConstexpr<day>(), "");

for (unsigned i = 10; i <= 20; ++i)
{
day day(i);
assert(static_cast<unsigned>(--day) == i - 1);
assert(static_cast<unsigned>(day--) == i - 1);
assert(static_cast<unsigned>(day) == i - 2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class day;

// constexpr day& operator++() noexcept;
// constexpr day operator++(int) noexcept;


#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

template <typename D>
constexpr bool testConstexpr()
{
D d1{1};
if (static_cast<unsigned>(++d1) != 2) return false;
if (static_cast<unsigned>(d1++) != 2) return false;
if (static_cast<unsigned>(d1) != 3) return false;
return true;
}

int main()
{
using day = std::chrono::day;
ASSERT_NOEXCEPT(++(std::declval<day&>()) );
ASSERT_NOEXCEPT( (std::declval<day&>())++);

ASSERT_SAME_TYPE(day , decltype( std::declval<day&>()++));
ASSERT_SAME_TYPE(day&, decltype(++std::declval<day&>() ));

static_assert(testConstexpr<day>(), "");

for (unsigned i = 10; i <= 20; ++i)
{
day day(i);
assert(static_cast<unsigned>(++day) == i + 1);
assert(static_cast<unsigned>(day++) == i + 1);
assert(static_cast<unsigned>(day) == i + 2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class day;

// constexpr bool ok() const noexcept;
// Returns: 1 <= d_ && d_ <= 31

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using day = std::chrono::day;
ASSERT_NOEXCEPT( std::declval<const day>().ok());
ASSERT_SAME_TYPE(bool, decltype(std::declval<const day>().ok()));

static_assert(!day{0}.ok(), "");
static_assert( day{1}.ok(), "");

assert(!day{0}.ok());
for (unsigned i = 1; i <= 31; ++i)
assert(day{i}.ok());
for (unsigned i = 32; i <= 255; ++i)
assert(!day{i}.ok());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class day;

// constexpr day& operator+=(const days& d) noexcept;
// constexpr day& operator-=(const days& d) noexcept;

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

template <typename D, typename Ds>
constexpr bool testConstexpr()
{
D d1{1};
if (static_cast<unsigned>(d1 += Ds{ 1}) != 2) return false;
if (static_cast<unsigned>(d1 += Ds{ 2}) != 4) return false;
if (static_cast<unsigned>(d1 += Ds{22}) != 26) return false;
if (static_cast<unsigned>(d1 -= Ds{ 1}) != 25) return false;
if (static_cast<unsigned>(d1 -= Ds{ 2}) != 23) return false;
if (static_cast<unsigned>(d1 -= Ds{22}) != 1) return false;
return true;
}

int main()
{
using day = std::chrono::day;
using days = std::chrono::days;

ASSERT_NOEXCEPT(std::declval<day&>() += std::declval<days>());
ASSERT_NOEXCEPT(std::declval<day&>() -= std::declval<days>());

ASSERT_SAME_TYPE(day&, decltype(std::declval<day&>() += std::declval<days>()));
ASSERT_SAME_TYPE(day&, decltype(std::declval<day&>() -= std::declval<days>()));

static_assert(testConstexpr<day, days>(), "");

for (unsigned i = 0; i <= 10; ++i)
{
day day(i);
assert(static_cast<unsigned>(day += days{22}) == i + 22);
assert(static_cast<unsigned>(day) == i + 22);
assert(static_cast<unsigned>(day -= days{12}) == i + 10);
assert(static_cast<unsigned>(day) == i + 10);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class day;

// constexpr bool operator==(const day& x, const day& y) noexcept;
// Returns: unsigned{x} == unsigned{y}.
// constexpr bool operator<(const day& x, const day& y) noexcept;
// Returns: unsigned{x} < unsigned{y}.


#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"
#include "test_comparisons.h"

int main()
{
using day = std::chrono::day;

AssertComparisons6AreNoexcept<day>();
AssertComparisons6ReturnBool<day>();

static_assert(testComparisons6Values<day>(0U, 0U), "");
static_assert(testComparisons6Values<day>(0U, 1U), "");

// Some 'ok' values as well
static_assert(testComparisons6Values<day>( 5U, 5U), "");
static_assert(testComparisons6Values<day>( 5U, 10U), "");

for (unsigned i = 1; i < 10; ++i)
for (unsigned j = 1; j < 10; ++j)
assert(testComparisons6Values<day>(i, j));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: clang-5, clang-6
// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8, apple-clang-9

// <chrono>
// class day;

// constexpr day operator""d(unsigned long long d) noexcept;

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using day = std::chrono::day;
day d1 = 4d; // expected-error-re {{no matching literal operator for call to 'operator""d' {{.*}}}}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: clang-5, clang-6
// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8, apple-clang-9

// <chrono>
// class day;

// constexpr day operator""d(unsigned long long d) noexcept;

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
{
using namespace std::chrono;
ASSERT_NOEXCEPT( 4d);
ASSERT_SAME_TYPE(day, decltype(4d));

static_assert( 7d == day(7), "");
day d1 = 4d;
assert (d1 == day(4));
}

{
using namespace std::literals;
ASSERT_NOEXCEPT( 4d);
ASSERT_SAME_TYPE(std::chrono::day, decltype(4d));

static_assert( 7d == std::chrono::day(7), "");

std::chrono::day d1 = 4d;
assert (d1 == std::chrono::day(4));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class day;

// constexpr day operator-(const day& x, const days& y) noexcept;
// Returns: x + -y.
//
// constexpr days operator-(const day& x, const day& y) noexcept;
// Returns: days{int(unsigned{x}) - int(unsigned{y}).


#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

template <typename D, typename Ds>
constexpr bool testConstexpr()
{
D d{23};
Ds offset{6};
if (d - offset != D{17}) return false;
if (d - D{17} != offset) return false;
return true;
}

int main()
{
using day = std::chrono::day;
using days = std::chrono::days;

ASSERT_NOEXCEPT(std::declval<day>() - std::declval<days>());
ASSERT_NOEXCEPT(std::declval<day>() - std::declval<day>());

ASSERT_SAME_TYPE(day, decltype(std::declval<day>() - std::declval<days>()));
ASSERT_SAME_TYPE(days, decltype(std::declval<day>() - std::declval<day>()));

static_assert(testConstexpr<day, days>(), "");

day dy{12};
for (unsigned i = 0; i <= 10; ++i)
{
day d1 = dy - days{i};
days off = dy - day {i};
assert(static_cast<unsigned>(d1) == 12 - i);
assert(off.count() == static_cast<int>(12 - i)); // days is signed
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class day;

// constexpr day operator+(const day& x, const days& y) noexcept;
// Returns: day(unsigned{x} + y.count()).
//
// constexpr day operator+(const days& x, const day& y) noexcept;
// Returns: y + x.


#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

template <typename D, typename Ds>
constexpr bool testConstexpr()
{
D d{1};
Ds offset{23};
if (d + offset != D{24}) return false;
if (offset + d != D{24}) return false;
return true;
}

int main()
{
using day = std::chrono::day;
using days = std::chrono::days;

ASSERT_NOEXCEPT(std::declval<day>() + std::declval<days>());
ASSERT_NOEXCEPT(std::declval<days>() + std::declval<day>());

ASSERT_SAME_TYPE(day, decltype(std::declval<day>() + std::declval<days>()));
ASSERT_SAME_TYPE(day, decltype(std::declval<days>() + std::declval<day>()));

static_assert(testConstexpr<day, days>(), "");

day dy{12};
for (unsigned i = 0; i <= 10; ++i)
{
day d1 = dy + days{i};
day d2 = days{i} + dy;
assert(d1 == d2);
assert(static_cast<unsigned>(d1) == i + 12);
assert(static_cast<unsigned>(d2) == i + 12);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// XFAIL: *

// <chrono>
// class day;

// template<class charT, class traits>
// basic_ostream<charT, traits>&
// operator<<(basic_ostream<charT, traits>& os, const day& d);
//
// Effects: Inserts format(fmt, d) where fmt is "%d" widened to charT.
// If !d.ok(), appends with " is not a valid day".
//
// template<class charT, class traits>
// basic_ostream<charT, traits>&
// to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const day& d);
//
// Effects: Streams d into os using the format specified by the NTCTS fmt.
// fmt encoding follows the rules specified in 25.11.
//
// template<class charT, class traits, class Alloc = allocator<charT>>
// basic_istream<charT, traits>&
// from_stream(basic_istream<charT, traits>& is, const charT* fmt,
// day& d, basic_string<charT, traits, Alloc>* abbrev = nullptr,
// minutes* offset = nullptr);
//
// Effects: Attempts to parse the input stream is into the day d using the format flags
// given in the NTCTS fmt as specified in 25.12.
// If the parse fails to decode a valid day, is.setstate(ios_base::failbit)
// shall be called and d shall not be modified.
// If %Z is used and successfully parsed, that value will be assigned to *abbrev
// if abbrev is non-null. If %z (or a modified variant) is used and
// successfully parsed, that value will be assigned to *offset if offset is non-null.
//


#include <chrono>
#include <type_traits>
#include <cassert>
#include <iostream>

#include "test_macros.h"

int main()
{
using day = std::chrono::day;
std::cout << day{1};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class day;

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using day = std::chrono::day;

static_assert(std::is_trivially_copyable_v<day>, "");
static_assert(std::is_standard_layout_v<day>, "");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>

// struct last_spec {
// explicit last_spec() = default;
// };
//
// inline constexpr last_spec last{};

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using last_spec = std::chrono::last_spec;

ASSERT_SAME_TYPE(const last_spec, decltype(std::chrono::last));

static_assert(std::is_trivially_copyable_v<last_spec>, "");
static_assert(std::is_standard_layout_v<last_spec>, "");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_day;

// month_day() = default;
// constexpr month_day(const chrono::month& m, const chrono::day& d) noexcept;
//
// Effects: Constructs an object of type month_day by initializing m_ with m, and d_ with d.
//
// constexpr chrono::month month() const noexcept;
// constexpr chrono::day day() const noexcept;
// constexpr bool ok() const noexcept;

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using day = std::chrono::day;
using month = std::chrono::month;
using month_day = std::chrono::month_day;

ASSERT_NOEXCEPT(month_day{});
ASSERT_NOEXCEPT(month_day{month{1}, day{1}});

constexpr month_day md0{};
static_assert( md0.month() == month{}, "");
static_assert( md0.day() == day{}, "");
static_assert(!md0.ok(), "");

constexpr month_day md1{std::chrono::January, day{4}};
static_assert( md1.month() == std::chrono::January, "");
static_assert( md1.day() == day{4}, "");
static_assert( md1.ok(), "");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_day;

// constexpr chrono::day day() const noexcept;
// Returns: d_

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using day = std::chrono::day;
using month = std::chrono::month;
using month_day = std::chrono::month_day;

ASSERT_NOEXCEPT( std::declval<const month_day>().day());
ASSERT_SAME_TYPE(day, decltype(std::declval<const month_day>().day()));

static_assert( month_day{}.day() == day{}, "");

for (unsigned i = 1; i <= 50; ++i)
{
month_day md(std::chrono::March, day{i});
assert( static_cast<unsigned>(md.day()) == i);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_day;

// constexpr chrono::month month() const noexcept;
// Returns: wd_

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using day = std::chrono::day;
using month = std::chrono::month;
using month_day = std::chrono::month_day;

ASSERT_NOEXCEPT( std::declval<const month_day>().month());
ASSERT_SAME_TYPE(month, decltype(std::declval<const month_day>().month()));

static_assert( month_day{}.month() == month{}, "");

for (unsigned i = 1; i <= 50; ++i)
{
month_day md(month{i}, day{1});
assert( static_cast<unsigned>(md.month()) == i);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_day;

// constexpr bool ok() const noexcept;
// Returns: true if m_.ok() is true, 1d <= d_, and d_ is less than or equal to the
// number of days in month m_; otherwise returns false.
// When m_ == February, the number of days is considered to be 29.

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using day = std::chrono::day;
using month = std::chrono::month;
using month_day = std::chrono::month_day;

ASSERT_NOEXCEPT( std::declval<const month_day>().ok());
ASSERT_SAME_TYPE(bool, decltype(std::declval<const month_day>().ok()));

static_assert(!month_day{}.ok(), "");
static_assert( month_day{std::chrono::May, day{2}}.ok(), "");

assert(!(month_day(std::chrono::April, day{0}).ok()));

assert( (month_day{std::chrono::March, day{1}}.ok()));
for (unsigned i = 1; i <= 12; ++i)
{
const bool is31 = i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12;
assert(!(month_day{month{i}, day{ 0}}.ok()));
assert( (month_day{month{i}, day{ 1}}.ok()));
assert( (month_day{month{i}, day{10}}.ok()));
assert( (month_day{month{i}, day{29}}.ok()));
assert( (month_day{month{i}, day{30}}.ok()) == (i != 2));
assert( (month_day{month{i}, day{31}}.ok()) == is31);
assert(!(month_day{month{i}, day{32}}.ok()));
}

// If the month is not ok, all the days are bad
for (unsigned i = 1; i <= 35; ++i)
assert(!(month_day{month{13}, day{i}}.ok()));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_day;

// constexpr bool operator==(const month_day& x, const month_day& y) noexcept;
// Returns: x.month() == y.month() && x.day() == y.day().
//
// constexpr bool operator< (const month_day& x, const month_day& y) noexcept;
// Returns:
// If x.month() < y.month() returns true.
// Otherwise, if x.month() > y.month() returns false.
// Otherwise, returns x.day() < y.day().

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"
#include "test_comparisons.h"

int main()
{
using day = std::chrono::day;
using month = std::chrono::month;
using month_day = std::chrono::month_day;

AssertComparisons6AreNoexcept<month_day>();
AssertComparisons6ReturnBool<month_day>();

static_assert( testComparisons6(
month_day{std::chrono::January, day{1}},
month_day{std::chrono::January, day{1}},
true, false), "");

static_assert( testComparisons6(
month_day{std::chrono::January, day{1}},
month_day{std::chrono::January, day{2}},
false, true), "");

static_assert( testComparisons6(
month_day{std::chrono::January, day{1}},
month_day{std::chrono::February, day{1}},
false, true), "");

// same day, different months
for (unsigned i = 1; i < 12; ++i)
for (unsigned j = 1; j < 12; ++j)
assert((testComparisons6(
month_day{month{i}, day{1}},
month_day{month{j}, day{1}},
i == j, i < j )));

// same month, different days
for (unsigned i = 1; i < 31; ++i)
for (unsigned j = 1; j < 31; ++j)
assert((testComparisons6(
month_day{month{2}, day{i}},
month_day{month{2}, day{j}},
i == j, i < j )));

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// XFAIL: *

// <chrono>
// class month_day;

// template<class charT, class traits>
// basic_ostream<charT, traits>&
// operator<<(basic_ostream<charT, traits>& os, const month_day& md);
//
// Returns: os << md.month() << '/' << md.day().
//
// template<class charT, class traits>
// basic_ostream<charT, traits>&
// to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const month_day& md);
//
// Effects: Streams md into os using the format specified by the NTCTS fmt.
// fmt encoding follows the rules specified in 25.11.


#include <chrono>
#include <type_traits>
#include <cassert>
#include <iostream>
#include "test_macros.h"

int main()
{
using month_day = std::chrono::month_day;
using month = std::chrono::month;
using day = std::chrono::day;
std::cout << month_day{month{1}, day{1}};
}
26 changes: 26 additions & 0 deletions libcxx/test/std/utilities/time/time.cal/time.cal.md/types.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_day;

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month_day = std::chrono::month_day;

static_assert(std::is_trivially_copyable_v<month_day>, "");
static_assert(std::is_standard_layout_v<month_day>, "");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_day_last;

// constexpr bool operator==(const month_day& x, const month_day& y) noexcept;
// Returns: x.month() == y.month()
//
// constexpr bool operator< (const month_day& x, const month_day& y) noexcept;
// Returns: x.month() < y.month()


#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"
#include "test_comparisons.h"

int main()
{
using month = std::chrono::month;
using month_day_last = std::chrono::month_day_last;

AssertComparisons6AreNoexcept<month_day_last>();
AssertComparisons6ReturnBool<month_day_last>();

static_assert( testComparisons6Values<month_day_last>(month{1}, month{1}), "");
static_assert( testComparisons6Values<month_day_last>(month{1}, month{2}), "");

// same day, different months
for (unsigned i = 1; i < 12; ++i)
for (unsigned j = 1; j < 12; ++j)
assert((testComparisons6Values<month_day_last>(month{i}, month{j})));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_day_last;

// constexpr month_day_last(const chrono::month& m) noexcept;
//
// Effects: Constructs an object of type month_day_last by initializing m_ with m
//
// constexpr chrono::month month() const noexcept;
// constexpr bool ok() const noexcept;

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month = std::chrono::month;
using month_day_last = std::chrono::month_day_last;

ASSERT_NOEXCEPT(month_day_last{month{1}});

constexpr month_day_last md0{month{}};
static_assert( md0.month() == month{}, "");
static_assert(!md0.ok(), "");

constexpr month_day_last md1{std::chrono::January};
static_assert( md1.month() == std::chrono::January, "");
static_assert( md1.ok(), "");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_day_last;

// constexpr chrono::month month() const noexcept;
// Returns: m_

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month = std::chrono::month;
using month_day_last = std::chrono::month_day_last;

ASSERT_NOEXCEPT( std::declval<const month_day_last>().month());
ASSERT_SAME_TYPE(month, decltype(std::declval<const month_day_last>().month()));

static_assert( month_day_last{month{}}.month() == month{}, "");

for (unsigned i = 1; i <= 50; ++i)
{
month_day_last mdl(month{i});
assert( static_cast<unsigned>(mdl.month()) == i);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_day_last;

// constexpr bool ok() const noexcept;
// Returns: m_.ok()

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month = std::chrono::month;
using month_day_last = std::chrono::month_day_last;

ASSERT_NOEXCEPT( std::declval<const month_day_last>().ok());
ASSERT_SAME_TYPE(bool, decltype(std::declval<const month_day_last>().ok()));

static_assert(!month_day_last{month{}}.ok(), "");
static_assert( month_day_last{std::chrono::May}.ok(), "");

for (unsigned i = 1; i <= 12; ++i)
{
month_day_last mdl{month{i}};
assert( mdl.ok());
}

// If the month is not ok, all the days are bad
for (unsigned i = 13; i <= 50; ++i)
{
month_day_last mdl{month{i}};
assert(!mdl.ok());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// XFAIL: *

// <chrono>
// class month_day_last;
//
// template<class charT, class traits>
// basic_ostream<charT, traits>&
// operator<<(basic_ostream<charT, traits>& os, const month_day_last& mdl);
//
// Returns: os << mdl.month() << "/last".


#include <chrono>
#include <type_traits>
#include <cassert>
#include <iostream>

#include "test_macros.h"

int main()
{
using month_day_last = std::chrono::month_day_last;
using month = std::chrono::month;
std::cout << month_day_last{month{1}};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>

// class month_day_last;

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month_day_last = std::chrono::month_day_last;

static_assert(std::is_trivially_copyable_v<month_day_last>, "");
static_assert(std::is_standard_layout_v<month_day_last>, "");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month;

// month() = default;
// explicit constexpr month(int m) noexcept;
// explicit constexpr operator int() const noexcept;

// Effects: Constructs an object of type month by initializing m_ with m.
// The value held is unspecified if d is not in the range [0, 255].

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month = std::chrono::month;

ASSERT_NOEXCEPT(month{});
ASSERT_NOEXCEPT(month(1));
ASSERT_NOEXCEPT(static_cast<unsigned>(month(1)));

constexpr month m0{};
static_assert(static_cast<unsigned>(m0) == 0, "");

constexpr month m1{1};
static_assert(static_cast<unsigned>(m1) == 1, "");

for (unsigned i = 0; i <= 255; ++i)
{
month m(i);
assert(static_cast<unsigned>(m) == i);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month;

// constexpr month& operator--() noexcept;
// constexpr month operator--(int) noexcept;


#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

template <typename M>
constexpr bool testConstexpr()
{
M m1{10};
if (static_cast<unsigned>(--m1) != 9) return false;
if (static_cast<unsigned>(m1--) != 9) return false;
if (static_cast<unsigned>(m1) != 8) return false;
return true;
}

int main()
{
using month = std::chrono::month;

ASSERT_NOEXCEPT(--(std::declval<month&>()) );
ASSERT_NOEXCEPT( (std::declval<month&>())--);

ASSERT_SAME_TYPE(month , decltype( std::declval<month&>()--));
ASSERT_SAME_TYPE(month&, decltype(--std::declval<month&>() ));

static_assert(testConstexpr<month>(), "");

for (unsigned i = 10; i <= 20; ++i)
{
month month(i);
assert(static_cast<unsigned>(--month) == i - 1);
assert(static_cast<unsigned>(month--) == i - 1);
assert(static_cast<unsigned>(month) == i - 2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month;

// constexpr month& operator++() noexcept;
// constexpr month operator++(int) noexcept;


#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

template <typename M>
constexpr bool testConstexpr()
{
M m1{1};
if (static_cast<unsigned>(++m1) != 2) return false;
if (static_cast<unsigned>(m1++) != 2) return false;
if (static_cast<unsigned>(m1) != 3) return false;
return true;
}

int main()
{
using month = std::chrono::month;
ASSERT_NOEXCEPT(++(std::declval<month&>()) );
ASSERT_NOEXCEPT( (std::declval<month&>())++);

ASSERT_SAME_TYPE(month , decltype( std::declval<month&>()++));
ASSERT_SAME_TYPE(month&, decltype(++std::declval<month&>() ));

static_assert(testConstexpr<month>(), "");

for (unsigned i = 0; i <= 10; ++i)
{
month month(i);
assert(static_cast<unsigned>(++month) == i + 1);
assert(static_cast<unsigned>(month++) == i + 1);
assert(static_cast<unsigned>(month) == i + 2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month;

// constexpr bool ok() const noexcept;
// Returns: 1 <= d_ && d_ <= 12

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month = std::chrono::month;

ASSERT_NOEXCEPT( std::declval<const month>().ok());
ASSERT_SAME_TYPE(bool, decltype(std::declval<const month>().ok()));

static_assert(!month{0}.ok(), "");
static_assert( month{1}.ok(), "");

assert(!month{0}.ok());
for (unsigned i = 1; i <= 12; ++i)
assert(month{i}.ok());
for (unsigned i = 13; i <= 255; ++i)
assert(!month{i}.ok());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month;

// constexpr month& operator+=(const month& d) noexcept;
// constexpr month& operator-=(const month& d) noexcept;

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

template <typename M, typename Ms>
constexpr bool testConstexpr()
{
M m1{1};
if (static_cast<unsigned>(m1 += Ms{ 1}) != 2) return false;
if (static_cast<unsigned>(m1 += Ms{ 2}) != 4) return false;
if (static_cast<unsigned>(m1 += Ms{ 8}) != 12) return false;
if (static_cast<unsigned>(m1 -= Ms{ 1}) != 11) return false;
if (static_cast<unsigned>(m1 -= Ms{ 2}) != 9) return false;
if (static_cast<unsigned>(m1 -= Ms{ 8}) != 1) return false;
return true;
}

int main()
{
using month = std::chrono::month;
using months = std::chrono::months;

ASSERT_NOEXCEPT(std::declval<month&>() += std::declval<months&>());
ASSERT_NOEXCEPT(std::declval<month&>() -= std::declval<months&>());
ASSERT_SAME_TYPE(month&, decltype(std::declval<month&>() += std::declval<months&>()));
ASSERT_SAME_TYPE(month&, decltype(std::declval<month&>() -= std::declval<months&>()));

static_assert(testConstexpr<month, months>(), "");

for (unsigned i = 1; i <= 10; ++i)
{
month month(i);
int exp = i + 10;
while (exp > 12)
exp -= 12;
assert(static_cast<unsigned>(month += months{10}) == static_cast<unsigned>(exp));
assert(static_cast<unsigned>(month) == static_cast<unsigned>(exp));
}

for (unsigned i = 1; i <= 10; ++i)
{
month month(i);
int exp = i - 9;
while (exp < 1)
exp += 12;
assert(static_cast<unsigned>(month -= months{ 9}) == static_cast<unsigned>(exp));
assert(static_cast<unsigned>(month) == static_cast<unsigned>(exp));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month;

// constexpr bool operator==(const month& x, const month& y) noexcept;
// constexpr bool operator!=(const month& x, const month& y) noexcept;
// constexpr bool operator< (const month& x, const month& y) noexcept;
// constexpr bool operator> (const month& x, const month& y) noexcept;
// constexpr bool operator<=(const month& x, const month& y) noexcept;
// constexpr bool operator>=(const month& x, const month& y) noexcept;


#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"
#include "test_comparisons.h"


int main()
{
using month = std::chrono::month;

AssertComparisons6AreNoexcept<month>();
AssertComparisons6ReturnBool<month>();

static_assert(testComparisons6Values<month>(0U ,0U), "");
static_assert(testComparisons6Values<month>(0U, 1U), "");

// Some 'ok' values as well
static_assert(testComparisons6Values<month>( 5U, 5U), "");
static_assert(testComparisons6Values<month>( 5U, 10U), "");

for (unsigned i = 1; i < 10; ++i)
for (unsigned j = 10; j < 10; ++j)
assert(testComparisons6Values<month>(i, j));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>

// inline constexpr month January{1};
// inline constexpr month February{2};
// inline constexpr month March{3};
// inline constexpr month April{4};
// inline constexpr month May{5};
// inline constexpr month June{6};
// inline constexpr month July{7};
// inline constexpr month August{8};
// inline constexpr month September{9};
// inline constexpr month October{10};
// inline constexpr month November{11};
// inline constexpr month December{12};


#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{

ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::January));
ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::February));
ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::March));
ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::April));
ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::May));
ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::June));
ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::July));
ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::August));
ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::September));
ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::October));
ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::November));
ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::December));

static_assert( std::chrono::January == std::chrono::month(1), "");
static_assert( std::chrono::February == std::chrono::month(2), "");
static_assert( std::chrono::March == std::chrono::month(3), "");
static_assert( std::chrono::April == std::chrono::month(4), "");
static_assert( std::chrono::May == std::chrono::month(5), "");
static_assert( std::chrono::June == std::chrono::month(6), "");
static_assert( std::chrono::July == std::chrono::month(7), "");
static_assert( std::chrono::August == std::chrono::month(8), "");
static_assert( std::chrono::September == std::chrono::month(9), "");
static_assert( std::chrono::October == std::chrono::month(10), "");
static_assert( std::chrono::November == std::chrono::month(11), "");
static_assert( std::chrono::December == std::chrono::month(12), "");

assert(std::chrono::January == std::chrono::month(1));
assert(std::chrono::February == std::chrono::month(2));
assert(std::chrono::March == std::chrono::month(3));
assert(std::chrono::April == std::chrono::month(4));
assert(std::chrono::May == std::chrono::month(5));
assert(std::chrono::June == std::chrono::month(6));
assert(std::chrono::July == std::chrono::month(7));
assert(std::chrono::August == std::chrono::month(8));
assert(std::chrono::September == std::chrono::month(9));
assert(std::chrono::October == std::chrono::month(10));
assert(std::chrono::November == std::chrono::month(11));
assert(std::chrono::December == std::chrono::month(12));

assert(static_cast<unsigned>(std::chrono::January) == 1);
assert(static_cast<unsigned>(std::chrono::February) == 2);
assert(static_cast<unsigned>(std::chrono::March) == 3);
assert(static_cast<unsigned>(std::chrono::April) == 4);
assert(static_cast<unsigned>(std::chrono::May) == 5);
assert(static_cast<unsigned>(std::chrono::June) == 6);
assert(static_cast<unsigned>(std::chrono::July) == 7);
assert(static_cast<unsigned>(std::chrono::August) == 8);
assert(static_cast<unsigned>(std::chrono::September) == 9);
assert(static_cast<unsigned>(std::chrono::October) == 10);
assert(static_cast<unsigned>(std::chrono::November) == 11);
assert(static_cast<unsigned>(std::chrono::December) == 12);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month;

// constexpr month operator-(const month& x, const months& y) noexcept;
// Returns: x + -y.
//
// constexpr months operator-(const month& x, const month& y) noexcept;
// Returns: If x.ok() == true and y.ok() == true, returns a value m in the range
// [months{0}, months{11}] satisfying y + m == x.
// Otherwise the value returned is unspecified.
// [Example: January - February == months{11}. —end example]

extern "C" int printf(const char *, ...);

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

template <typename M, typename Ms>
constexpr bool testConstexpr()
{
{
M m{5};
Ms offset{3};
if (m - offset != M{2}) return false;
if (m - M{2} != offset) return false;
}

// Check the example
if (M{1} - M{2} != Ms{11}) return false;
return true;
}

#include <iostream>

int main()
{
using month = std::chrono::month;
using months = std::chrono::months;

ASSERT_NOEXCEPT(std::declval<month>() - std::declval<months>());
ASSERT_NOEXCEPT(std::declval<month>() - std::declval<month>());

ASSERT_SAME_TYPE(month , decltype(std::declval<month>() - std::declval<months>()));
ASSERT_SAME_TYPE(months, decltype(std::declval<month>() - std::declval<month> ()));

static_assert(testConstexpr<month, months>(), "");

month m{6};
for (unsigned i = 1; i <= 12; ++i)
{
month m1 = m - months{i};
// months off = m - month {i};
int exp = 6 - i;
if (exp < 1)
exp += 12;
assert(static_cast<unsigned>(m1) == static_cast<unsigned>(exp));
// assert(off.count() == static_cast<unsigned>(exp));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month;

// constexpr month operator+(const month& x, const months& y) noexcept;
// Returns: month(int{x} + y.count()).
//
// constexpr month operator+(const months& x, const month& y) noexcept;
// Returns:
// month{modulo(static_cast<long long>(int{x}) + (y.count() - 1), 12) + 1}
// where modulo(n, 12) computes the remainder of n divided by 12 using Euclidean division.
// [Note: Given a divisor of 12, Euclidean division truncates towards negative infinity
// and always produces a remainder in the range of [0, 11].
// Assuming no overflow in the signed summation, this operation results in a month
// holding a value in the range [1, 12] even if !x.ok(). —end note]
// [Example: February + months{11} == January. —end example]



#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

template <typename M, typename Ms>
constexpr bool testConstexpr()
{
M m{1};
Ms offset{4};
if (m + offset != M{5}) return false;
if (offset + m != M{5}) return false;
// Check the example
if (M{2} + Ms{11} != M{1}) return false;
return true;
}

int main()
{
using month = std::chrono::month;
using months = std::chrono::months;

ASSERT_NOEXCEPT(std::declval<month>() + std::declval<months>());
ASSERT_NOEXCEPT(std::declval<months>() + std::declval<month>());

ASSERT_SAME_TYPE(month, decltype(std::declval<month>() + std::declval<months>()));
ASSERT_SAME_TYPE(month, decltype(std::declval<months>() + std::declval<month>() ));

static_assert(testConstexpr<month, months>(), "");

month my{2};
for (unsigned i = 0; i <= 15; ++i)
{
month m1 = my + months{i};
month m2 = months{i} + my;
assert(m1 == m2);
unsigned exp = i + 2;
while (exp > 12)
exp -= 12;
assert(static_cast<unsigned>(m1) == exp);
assert(static_cast<unsigned>(m2) == exp);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// XFAIL: *

// <chrono>
// class month;

// template<class charT, class traits>
// basic_ostream<charT, traits>&
// operator<<(basic_ostream<charT, traits>& os, const month& m);
//
// Effects: If m.ok() == true inserts format(os.getloc(), fmt, m) where fmt is "%b" widened to charT.
// Otherwise inserts int{m} << " is not a valid month".
//
// template<class charT, class traits>
// basic_ostream<charT, traits>&
// to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const month& m);
//
// Effects: Streams m into os using the format specified by the NTCTS fmt.
// fmt encoding follows the rules specified in 25.11.
//
// template<class charT, class traits, class Alloc = allocator<charT>>
// basic_istream<charT, traits>&
// from_stream(basic_istream<charT, traits>& is, const charT* fmt,
// month& m, basic_string<charT, traits, Alloc>* abbrev = nullptr,
// minutes* offset = nullptr);
//
// Effects: Attempts to parse the input stream is into the month m using the format flags
// given in the NTCTS fmt as specified in 25.12. If the parse fails to decode a valid month,
// is.setstate(ios_- base::failbit) shall be called and m shall not be modified.
// If %Z is used and successfully parsed, that value will be assigned to *abbrev if
// abbrev is non-null. If %z (or a modified variant) is used and successfully parsed,
// that value will be assigned to *offset if offset is non-null.

#include <chrono>
#include <type_traits>
#include <cassert>
#include <iostream>

#include "test_macros.h"

int main()
{
using month = std::chrono::month;
std::cout << month{1};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month;

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month = std::chrono::month;

static_assert(std::is_trivially_copyable_v<month>, "");
static_assert(std::is_standard_layout_v<month>, "");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_weekday;
// month_weekday represents the nth weekday of a month, of an as yet unspecified year.

// constexpr month_weekday(const chrono::month& m, const chrono::weekday_indexed& wdi) noexcept;
// Effects: Constructs an object of type month_weekday by initializing m_ with m, and wdi_ with wdi.
//
// constexpr chrono::month month() const noexcept;
// constexpr chrono::weekday_indexed weekday_indexed() const noexcept;
// constexpr bool ok() const noexcept;

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month_weekday = std::chrono::month_weekday;
using month = std::chrono::month;
using weekday = std::chrono::weekday;
using weekday_indexed = std::chrono::weekday_indexed;

ASSERT_NOEXCEPT(month_weekday{month{1}, weekday_indexed{weekday{}, 1}});

constexpr month_weekday md0{month{}, weekday_indexed{}};
static_assert( md0.month() == month{}, "");
static_assert( md0.weekday_indexed() == weekday_indexed{}, "");
static_assert(!md0.ok(), "");

constexpr month_weekday md1{std::chrono::January, weekday_indexed{std::chrono::Friday, 4}};
static_assert( md1.month() == std::chrono::January, "");
static_assert( md1.weekday_indexed() == weekday_indexed{std::chrono::Friday, 4}, "");
static_assert( md1.ok(), "");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_weekday;

// constexpr chrono::month month() const noexcept;
// Returns: wd_

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month_weekday = std::chrono::month_weekday;
using month = std::chrono::month;
using weekday = std::chrono::weekday;
using weekday_indexed = std::chrono::weekday_indexed;

constexpr weekday Sunday = std::chrono::Sunday;

ASSERT_NOEXCEPT( std::declval<const month_weekday>().month());
ASSERT_SAME_TYPE(month, decltype(std::declval<const month_weekday>().month()));

static_assert( month_weekday{}.month() == month{}, "");

for (unsigned i = 1; i <= 50; ++i)
{
month_weekday md(month{i}, weekday_indexed{Sunday, 1});
assert( static_cast<unsigned>(md.month()) == i);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_weekday;

// constexpr bool ok() const noexcept;
// Returns: m_.ok() && wdi_.ok().

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month_weekday = std::chrono::month_weekday;
using month = std::chrono::month;
using weekday = std::chrono::weekday;
using weekday_indexed = std::chrono::weekday_indexed;

constexpr weekday Sunday = std::chrono::Sunday;

ASSERT_NOEXCEPT( std::declval<const month_weekday>().ok());
ASSERT_SAME_TYPE(bool, decltype(std::declval<const month_weekday>().ok()));

static_assert(!month_weekday{month{}, weekday_indexed{}}.ok(), "");
static_assert( month_weekday{std::chrono::May, weekday_indexed{Sunday, 2}}.ok(), "");

assert(!(month_weekday(std::chrono::April, weekday_indexed{Sunday, 0}).ok()));
assert( (month_weekday{std::chrono::March, weekday_indexed{Sunday, 1}}.ok()));

for (unsigned i = 1; i <= 12; ++i)
for (unsigned j = 0; j <= 6; ++j)
{
month_weekday mwd{month{i}, weekday_indexed{Sunday, j}};
assert(mwd.ok() == (j >= 1 && j <= 5));
}

// If the month is not ok, all the weekday_indexed are bad
for (unsigned i = 1; i <= 10; ++i)
assert(!(month_weekday{month{13}, weekday_indexed{Sunday, i}}.ok()));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_weekday;

// constexpr chrono::weekday_indexed weekday_indexed() const noexcept;
// Returns: wdi_

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month_weekday = std::chrono::month_weekday;
using month = std::chrono::month;
using weekday = std::chrono::weekday;
using weekday_indexed = std::chrono::weekday_indexed;

constexpr weekday Sunday = std::chrono::Sunday;

ASSERT_NOEXCEPT( std::declval<const month_weekday>().weekday_indexed());
ASSERT_SAME_TYPE(weekday_indexed, decltype(std::declval<const month_weekday>().weekday_indexed()));

static_assert( month_weekday{month{}, weekday_indexed{}}.weekday_indexed() == weekday_indexed{}, "");

for (unsigned i = 1; i <= 10; ++i)
{
month_weekday md(std::chrono::March, weekday_indexed{Sunday, i});
assert( static_cast<unsigned>(md.weekday_indexed().weekday() == Sunday));
assert( static_cast<unsigned>(md.weekday_indexed().index() == i));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_weekday;

// constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept;
// Returns: x.month() == y.month() && x.day() == y.day().
//

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"
#include "test_comparisons.h"

int main()
{
using month_weekday = std::chrono::month_weekday;
using month = std::chrono::month;
using weekday_indexed = std::chrono::weekday_indexed;
using weekday = std::chrono::weekday;

constexpr weekday Sunday = std::chrono::Sunday;
constexpr weekday Monday = std::chrono::Monday;

AssertComparisons2AreNoexcept<month_weekday>();
AssertComparisons2ReturnBool<month_weekday>();

static_assert( testComparisons2(
month_weekday{std::chrono::January, weekday_indexed{Sunday, 1}},
month_weekday{std::chrono::January, weekday_indexed{Sunday, 1}},
true), "");

static_assert( testComparisons2(
month_weekday{std::chrono::January, weekday_indexed{Sunday, 1}},
month_weekday{std::chrono::January, weekday_indexed{Sunday, 2}},
false), "");

static_assert( testComparisons2(
month_weekday{std::chrono::January, weekday_indexed{Sunday, 1}},
month_weekday{std::chrono::February, weekday_indexed{Sunday, 1}},
false), "");

static_assert( testComparisons2(
month_weekday{std::chrono::January, weekday_indexed{Monday, 1}},
month_weekday{std::chrono::January, weekday_indexed{Sunday, 2}},
false), "");

static_assert( testComparisons2(
month_weekday{std::chrono::January, weekday_indexed{Monday, 1}},
month_weekday{std::chrono::February, weekday_indexed{Sunday, 1}},
false), "");

// same day, different months
for (unsigned i = 1; i < 12; ++i)
for (unsigned j = 1; j < 12; ++j)
assert((testComparisons2(
month_weekday{month{i}, weekday_indexed{Sunday, 1}},
month_weekday{month{j}, weekday_indexed{Sunday, 1}},
i == j)));

// same month, different weeks
for (unsigned i = 1; i < 5; ++i)
for (unsigned j = 1; j < 5; ++j)
assert((testComparisons2(
month_weekday{month{2}, weekday_indexed{Sunday, i}},
month_weekday{month{2}, weekday_indexed{Sunday, j}},
i == j)));

// same month, different days
for (unsigned i = 0; i < 6; ++i)
for (unsigned j = 0; j < 6; ++j)
assert((testComparisons2(
month_weekday{month{2}, weekday_indexed{weekday{i}, 2}},
month_weekday{month{2}, weekday_indexed{weekday{j}, 2}},
i == j)));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// XFAIL: *

// <chrono>
// class month_weekday;

// template<class charT, class traits>
// basic_ostream<charT, traits>&
// operator<<(basic_ostream<charT, traits>& os, const month_weekday& mwd);
//
// Returns: os << mwd.month() << '/' << mwd.weekday_indexed().

#include <chrono>
#include <type_traits>
#include <cassert>
#include <iostream>

#include "test_macros.h"

int main()
{
using month_weekday = std::chrono::month_weekday;
using month = std::chrono::month;
using weekday_indexed = std::chrono::weekday_indexed;
using weekday = std::chrono::weekday;

std::cout << month_weekday{month{1}, weekday_indexed{weekday{3}, 3}};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_weekday;

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month_weekday = std::chrono::month_weekday;

static_assert(std::is_trivially_copyable_v<month_weekday>, "");
static_assert(std::is_standard_layout_v<month_weekday>, "");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_weekday_last;

// constexpr month_weekday_last(const chrono::month& m,
// const chrono::weekday_last& wdl) noexcept;
//
// Effects: Constructs an object of type month_weekday_last by
// initializing m_ with m, and wdl_ with wdl.
//
// constexpr chrono::month month() const noexcept;
// constexpr chrono::weekday_last weekday_last() const noexcept;
// constexpr bool ok() const noexcept;


#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month = std::chrono::month;
using weekday = std::chrono::weekday;
using weekday_last = std::chrono::weekday_last;
using month_weekday_last = std::chrono::month_weekday_last;

constexpr month January = std::chrono::January;
constexpr weekday Tuesday = std::chrono::Tuesday;

ASSERT_NOEXCEPT(month_weekday_last{January, weekday_last{Tuesday}});

// bad month
constexpr month_weekday_last mwdl1{month{}, weekday_last{Tuesday}};
static_assert( mwdl1.month() == month{}, "");
static_assert( mwdl1.weekday_last() == weekday_last{Tuesday}, "");
static_assert(!mwdl1.ok(), "");

// bad weekday_last
constexpr month_weekday_last mwdl2{January, weekday_last{weekday{16}}};
static_assert( mwdl2.month() == January, "");
static_assert( mwdl2.weekday_last() == weekday_last{weekday{16}}, "");
static_assert(!mwdl2.ok(), "");

// Good month and weekday_last
constexpr month_weekday_last mwdl3{January, weekday_last{weekday{4}}};
static_assert( mwdl3.month() == January, "");
static_assert( mwdl3.weekday_last() == weekday_last{weekday{4}}, "");
static_assert( mwdl3.ok(), "");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_weekday_last;

// constexpr chrono::month month() const noexcept;
// Returns: m_

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month = std::chrono::month;
using weekday = std::chrono::weekday;
using weekday_last = std::chrono::weekday_last;
using month_weekday_last = std::chrono::month_weekday_last;

constexpr weekday Tuesday = std::chrono::Tuesday;

ASSERT_NOEXCEPT( std::declval<const month_weekday_last>().month());
ASSERT_SAME_TYPE(month, decltype(std::declval<const month_weekday_last>().month()));

static_assert( month_weekday_last{month{}, weekday_last{Tuesday}}.month() == month{}, "");

for (unsigned i = 1; i <= 50; ++i)
{
month_weekday_last mdl(month{i}, weekday_last{Tuesday});
assert( static_cast<unsigned>(mdl.month()) == i);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_weekday_last;

// constexpr bool ok() const noexcept;
// Returns: m_.ok() && wdl_.ok().

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month = std::chrono::month;
using weekday = std::chrono::weekday;
using weekday_last = std::chrono::weekday_last;
using month_weekday_last = std::chrono::month_weekday_last;

constexpr month January = std::chrono::January;
constexpr weekday Tuesday = std::chrono::Tuesday;
constexpr weekday_last lastTuesday = weekday_last{Tuesday};

ASSERT_NOEXCEPT( std::declval<const month_weekday_last>().ok());
ASSERT_SAME_TYPE(bool, decltype(std::declval<const month_weekday_last>().ok()));

static_assert(!month_weekday_last{month{}, lastTuesday}.ok(), ""); // Bad month
static_assert(!month_weekday_last{January, weekday_last{weekday{12}}}.ok(), ""); // Bad month
static_assert( month_weekday_last{January, lastTuesday}.ok(), ""); // Both OK

for (unsigned i = 0; i <= 50; ++i)
{
month_weekday_last mwdl{month{i}, lastTuesday};
assert( mwdl.ok() == month{i}.ok());
}

for (unsigned i = 0; i <= 50; ++i)
{
month_weekday_last mwdl{January, weekday_last{weekday{i}}};
assert( mwdl.ok() == weekday_last{weekday{i}}.ok());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_weekday_last;

// constexpr chrono::weekday_last weekday_last() const noexcept;
// Returns: wdl_

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month = std::chrono::month;
using weekday = std::chrono::weekday;
using weekday_last = std::chrono::weekday_last;
using month_weekday_last = std::chrono::month_weekday_last;

constexpr month January = std::chrono::January;
constexpr weekday Tuesday = std::chrono::Tuesday;
constexpr weekday_last lastTuesday = weekday_last{Tuesday};

ASSERT_NOEXCEPT( std::declval<const month_weekday_last>().weekday_last());
ASSERT_SAME_TYPE(weekday_last, decltype(std::declval<const month_weekday_last>().weekday_last()));

static_assert( month_weekday_last{month{}, lastTuesday}.weekday_last() == lastTuesday, "");

for (unsigned i = 1; i <= 50; ++i)
{
month_weekday_last mdl(January, weekday_last{weekday{i}});
assert( static_cast<unsigned>(mdl.weekday_last().weekday()) == i);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_weekday_last;

// constexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept;
// Returns: x.month() == y.month()
//
// constexpr bool operator< (const month_weekday_last& x, const month_weekday_last& y) noexcept;
// Returns: x.month() < y.month()


#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"
#include "test_comparisons.h"

int main()
{
using month = std::chrono::month;
using weekday_last = std::chrono::weekday_last;
using weekday = std::chrono::weekday;
using month_weekday_last = std::chrono::month_weekday_last;

constexpr month January = std::chrono::January;
constexpr weekday Tuesday = std::chrono::Tuesday;
constexpr weekday Wednesday = std::chrono::Wednesday;

AssertComparisons2AreNoexcept<month_weekday_last>();
AssertComparisons2ReturnBool<month_weekday_last>();

static_assert( testComparisons2(
month_weekday_last{std::chrono::January, weekday_last{Tuesday}},
month_weekday_last{std::chrono::January, weekday_last{Tuesday}},
true), "");

static_assert( testComparisons2(
month_weekday_last{std::chrono::January, weekday_last{Tuesday}},
month_weekday_last{std::chrono::January, weekday_last{Wednesday}},
false), "");

// vary the months
for (unsigned i = 1; i < 12; ++i)
for (unsigned j = 1; j < 12; ++j)
assert((testComparisons2(
month_weekday_last{month{i}, weekday_last{Tuesday}},
month_weekday_last{month{j}, weekday_last{Tuesday}},
i == j)));

// vary the weekday
for (unsigned i = 0; i < 6; ++i)
for (unsigned j = 0; j < 6; ++j)
assert((testComparisons2(
month_weekday_last{January, weekday_last{weekday{i}}},
month_weekday_last{January, weekday_last{weekday{j}}},
i == j)));

// both different
assert((testComparisons2(
month_weekday_last{month{1}, weekday_last{weekday{1}}},
month_weekday_last{month{2}, weekday_last{weekday{2}}},
false)));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// XFAIL: *

// <chrono>
// class month_weekday_last;
//
// template<class charT, class traits>
// basic_ostream<charT, traits>&
// operator<<(basic_ostream<charT, traits>& os, const month_weekday_last& mdl);
//
// Returns: os << mdl.month() << "/last".


#include <chrono>
#include <type_traits>
#include <cassert>
#include <iostream>

#include "test_macros.h"

int main()
{
using month_weekday_last = std::chrono::month_weekday_last;
using month = std::chrono::month;
using weekday = std::chrono::weekday;
using weekday_last = std::chrono::weekday_last;

std::cout << month_weekday_last{month{1}, weekday_last{weekday{3}}};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>

// class month_weekday_last;

#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"

int main()
{
using month_weekday_last = std::chrono::month_weekday_last;

static_assert(std::is_trivially_copyable_v<month_weekday_last>, "");
static_assert(std::is_standard_layout_v<month_weekday_last>, "");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_day;

// constexpr month_day
// operator/(const month& m, const day& d) noexcept;
// Returns: {m, d}.
//
// constexpr month_day
// operator/(const day& d, const month& m) noexcept;
// Returns: m / d.

// constexpr month_day
// operator/(const month& m, int d) noexcept;
// Returns: m / day(d).
//
// constexpr month_day
// operator/(int m, const day& d) noexcept;
// Returns: month(m) / d.
//
// constexpr month_day
// operator/(const day& d, int m) noexcept;
// Returns: month(m) / d.


#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"
#include "test_comparisons.h"

int main()
{
using month_day = std::chrono::month_day;
using month = std::chrono::month;
using day = std::chrono::day;

constexpr month February = std::chrono::February;

{ // operator/(const month& m, const day& d) (and switched)
ASSERT_NOEXCEPT ( February/day{1});
ASSERT_SAME_TYPE(month_day, decltype(February/day{1}));
ASSERT_NOEXCEPT ( day{1}/February);
ASSERT_SAME_TYPE(month_day, decltype(day{1}/February));

for (int i = 1; i <= 12; ++i)
for (unsigned j = 0; j <= 30; ++j)
{
month m(i);
day d{j};
month_day md1 = m/d;
month_day md2 = d/m;
assert(md1.month() == m);
assert(md1.day() == d);
assert(md2.month() == m);
assert(md2.day() == d);
assert(md1 == md2);
}
}


{ // operator/(const month& m, int d) (NOT switched)
ASSERT_NOEXCEPT ( February/2);
ASSERT_SAME_TYPE(month_day, decltype(February/2));

for (int i = 1; i <= 12; ++i)
for (unsigned j = 0; j <= 30; ++j)
{
month m(i);
day d(j);
month_day md1 = m/j;
assert(md1.month() == m);
assert(md1.day() == d);
}
}


{ // operator/(const day& d, int m) (and switched)
ASSERT_NOEXCEPT ( day{2}/2);
ASSERT_SAME_TYPE(month_day, decltype(day{2}/2));
ASSERT_NOEXCEPT ( 2/day{2});
ASSERT_SAME_TYPE(month_day, decltype(2/day{2}));

for (int i = 1; i <= 12; ++i)
for (unsigned j = 0; j <= 30; ++j)
{
month m(i);
day d(j);
month_day md1 = d/i;
month_day md2 = i/d;
assert(md1.month() == m);
assert(md1.day() == d);
assert(md2.month() == m);
assert(md2.day() == d);
assert(md1 == md2);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_day_last;

// constexpr month_day_last
// operator/(const month& m, last_spec) noexcept;
// Returns: month_day_last{m}.
//
// constexpr month_day_last
// operator/(int m, last_spec) noexcept;
// Returns: month(m) / last.
//
// constexpr month_day_last
// operator/(last_spec, const month& m) noexcept;
// Returns: m / last.
//
// constexpr month_day_last
// operator/(last_spec, int m) noexcept;
// Returns: month(m) / last.
//
//
// [Note: A month_day_last object can be constructed using the expression m/last or last/m,
// where m is an expression of type month. — end note]
// [Example:
// constexpr auto mdl = February/last; // mdl is the last day of February of an as yet unspecified year
// static_assert(mdl.month() == February);
// --end example]






#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"
#include "test_comparisons.h"

int main()
{
using month = std::chrono::month;
using month_day_last = std::chrono::month_day_last;

constexpr month February = std::chrono::February;
constexpr std::chrono::last_spec last = std::chrono::last;

ASSERT_SAME_TYPE(month_day_last, decltype(last/February));
ASSERT_SAME_TYPE(month_day_last, decltype(February/last));

// Run the example
{
constexpr auto mdl = February/std::chrono::last;
static_assert(mdl.month() == February, "");
}

{ // operator/(const month& m, last_spec) and switched
ASSERT_NOEXCEPT ( last/February);
ASSERT_SAME_TYPE(month_day_last, decltype(last/February));
ASSERT_NOEXCEPT ( February/last);
ASSERT_SAME_TYPE(month_day_last, decltype(February/last));

static_assert((last/February).month() == February, "");
static_assert((February/last).month() == February, "");

for (unsigned i = 1; i < 12; ++i)
{
month m{i};
month_day_last mdl1 = last/m;
month_day_last mdl2 = m/last;
assert(mdl1.month() == m);
assert(mdl2.month() == m);
assert(mdl1 == mdl2);
}
}

{ // operator/(int, last_spec) and switched
ASSERT_NOEXCEPT ( last/2);
ASSERT_SAME_TYPE(month_day_last, decltype(last/2));
ASSERT_NOEXCEPT ( 2/last);
ASSERT_SAME_TYPE(month_day_last, decltype(2/last));

static_assert((last/2).month() == February, "");
static_assert((2/last).month() == February, "");

for (unsigned i = 1; i < 12; ++i)
{
month m{i};
month_day_last mdl1 = last/i;
month_day_last mdl2 = i/last;
assert(mdl1.month() == m);
assert(mdl2.month() == m);
assert(mdl1 == mdl2);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17

// <chrono>
// class month_weekday;

// constexpr month_weekday
// operator/(const month& m, const weekday_indexed& wdi) noexcept;
// Returns: {m, wdi}.
//
// constexpr month_weekday
// operator/(int m, const weekday_indexed& wdi) noexcept;
// Returns: month(m) / wdi.
//
// constexpr month_weekday
// operator/(const weekday_indexed& wdi, const month& m) noexcept;
// Returns: m / wdi. constexpr month_weekday
//
// constexpr month_weekday
// operator/(const weekday_indexed& wdi, int m) noexcept;
// Returns: month(m) / wdi.


//
// [Example:
// constexpr auto mwd = February/Tuesday[3]; // mwd is the third Tuesday of February of an as yet unspecified year
// static_assert(mwd.month() == February);
// static_assert(mwd.weekday_indexed() == Tuesday[3]);
// —end example]




#include <chrono>
#include <type_traits>
#include <cassert>

#include "test_macros.h"
#include "test_comparisons.h"

int main()
{
using month_weekday = std::chrono::month_weekday;
using month = std::chrono::month;
using weekday = std::chrono::weekday;
using weekday_indexed = std::chrono::weekday_indexed;

constexpr weekday Tuesday = std::chrono::Tuesday;
constexpr month February = std::chrono::February;

{ // operator/(const month& m, const weekday_indexed& wdi) (and switched)
ASSERT_NOEXCEPT (February/Tuesday[2]);
ASSERT_SAME_TYPE(month_weekday, decltype(February/Tuesday[2]));
ASSERT_NOEXCEPT (Tuesday[2]/February);
ASSERT_SAME_TYPE(month_weekday, decltype(Tuesday[2]/February));

// Run the example
{
constexpr month_weekday wdi = February/Tuesday[3];
static_assert(wdi.month() == February, "");
static_assert(wdi.weekday_indexed() == Tuesday[3], "");
}

for (int i = 1; i <= 12; ++i)
for (unsigned j = 0; j <= 6; ++j)
for (unsigned k = 1; k <= 5; ++k)
{
month m(i);
weekday_indexed wdi = weekday{j}[k];
month_weekday mwd1 = m/wdi;
month_weekday mwd2 = wdi/m;
assert(mwd1.month() == m);
assert(mwd1.weekday_indexed() == wdi);
assert(mwd2.month() == m);
assert(mwd2.weekday_indexed() == wdi);
assert(mwd1 == mwd2);
}
}


{ // operator/(int m, const weekday_indexed& wdi) (and switched)
ASSERT_NOEXCEPT (2/Tuesday[2]);
ASSERT_SAME_TYPE(month_weekday, decltype(2/Tuesday[2]));
ASSERT_NOEXCEPT (Tuesday[2]/2);
ASSERT_SAME_TYPE(month_weekday, decltype(Tuesday[2]/2));

// Run the example
{
constexpr month_weekday wdi = 2/Tuesday[3];
static_assert(wdi.month() == February, "");
static_assert(wdi.weekday_indexed() == Tuesday[3], "");
}

for (int i = 1; i <= 12; ++i)
for (unsigned j = 0; j <= 6; ++j)
for (unsigned k = 1; k <= 5; ++k)
{
weekday_indexed wdi = weekday{j}[k];
month_weekday mwd1 = i/wdi;
month_weekday mwd2 = wdi/i;
assert(mwd1.month() == month(i));
assert(mwd1.weekday_indexed() == wdi);
assert(mwd2.month() == month(i));
assert(mwd2.weekday_indexed() == wdi);
assert(mwd1 == mwd2);
}
}
}
Loading