1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: no-filesystem, no-localization, no-tzdb
// XFAIL: libcpp-has-no-experimental-tzdb
// XFAIL: availability-tzdb-missing
// <chrono>
// class nonexistent_local_time
//
// template<class Duration>
// nonexistent_local_time(const local_time<Duration>& tp, const local_info& i);
#include <chrono>
#include <string_view>
#include "assert_macros.h"
#include "concat_macros.h"
template <class Duration>
static void
test(const std::chrono::local_time<Duration>& tp, const std::chrono::local_info& i, std::string_view expected) {
std::chrono::nonexistent_local_time exception{tp, i};
std::string_view result = exception.what();
TEST_REQUIRE(result == expected,
TEST_WRITE_CONCATENATED("Expected output\n", expected, "\n\nActual output\n", result, '\n'));
}
// The constructor constructs the runtime_error base class with a specific
// message. This implicitly tests what() too, since that is inherited from
// runtime_error there is no separate test for what().
int main(int, char**) {
using namespace std::literals::chrono_literals;
// There is no requirement on the ordering of PREV and NEXT so an "invalid"
// gap is allowed. All tests with negative dates use the same order as
// positive tests.
test(std::chrono::local_time<std::chrono::nanoseconds>{-1ns},
std::chrono::local_info{
std::chrono::local_info::nonexistent,
std::chrono::sys_info{
std::chrono::sys_days{std::chrono::September / 1 / 1969},
std::chrono::sys_days{std::chrono::December / 31 / 1969} + 23h,
0s,
0min,
"PREV"},
std::chrono::sys_info{
std::chrono::sys_days{std::chrono::January / 1 / 1970},
std::chrono::sys_days{std::chrono::March / 1 / 1970},
1h,
60min,
"NEXT"}},
R"(1969-12-31 23:59:59.999999999 is in a gap between
1969-12-31 23:00:00 PREV and
1970-01-01 01:00:00 NEXT which are both equivalent to
1969-12-31 23:00:00 UTC)");
test(std::chrono::local_time<std::chrono::microseconds>{0us},
std::chrono::local_info{
std::chrono::local_info::nonexistent,
std::chrono::sys_info{
std::chrono::sys_days{std::chrono::September / 1 / 1969},
std::chrono::sys_days{std::chrono::December / 31 / 1969} + 23h,
0s,
0min,
"PREV"},
std::chrono::sys_info{
std::chrono::sys_days{std::chrono::January / 1 / 1970},
std::chrono::sys_days{std::chrono::March / 1 / 1970},
1h,
60min,
"NEXT"}},
R"(1970-01-01 00:00:00.000000 is in a gap between
1969-12-31 23:00:00 PREV and
1970-01-01 01:00:00 NEXT which are both equivalent to
1969-12-31 23:00:00 UTC)");
test(std::chrono::local_time<std::chrono::milliseconds>{1ms},
std::chrono::local_info{
std::chrono::local_info::nonexistent,
std::chrono::sys_info{
std::chrono::sys_days{std::chrono::September / 1 / 1969},
std::chrono::sys_days{std::chrono::December / 31 / 1969} + 23h,
0s,
0min,
"PREV"},
std::chrono::sys_info{
std::chrono::sys_days{std::chrono::January / 1 / 1970},
std::chrono::sys_days{std::chrono::March / 1 / 1970},
1h,
60min,
"NEXT"}},
R"(1970-01-01 00:00:00.001 is in a gap between
1969-12-31 23:00:00 PREV and
1970-01-01 01:00:00 NEXT which are both equivalent to
1969-12-31 23:00:00 UTC)");
test(std::chrono::local_seconds{(std::chrono::sys_days{std::chrono::January / 1 / -21970}).time_since_epoch()},
std::chrono::local_info{
std::chrono::local_info::nonexistent,
std::chrono::sys_info{
std::chrono::sys_days{std::chrono::September / 1 / -21969},
std::chrono::sys_days{std::chrono::December / 31 / -21969} + 23h,
0s,
0min,
"PREV"},
std::chrono::sys_info{
std::chrono::sys_days{std::chrono::January / 1 / -21970},
std::chrono::sys_days{std::chrono::March / 1 / -21970},
1h,
60min,
"NEXT"}},
R"(-21970-01-01 00:00:00 is in a gap between
-21969-12-31 23:00:00 PREV and
-21970-01-01 01:00:00 NEXT which are both equivalent to
-21969-12-31 23:00:00 UTC)");
test(
std::chrono::local_time<std::chrono::days>{
(std::chrono::sys_days{std::chrono::January / 1 / 21970}).time_since_epoch()},
std::chrono::local_info{
std::chrono::local_info::nonexistent,
std::chrono::sys_info{
std::chrono::sys_days{std::chrono::September / 1 / 21969},
std::chrono::sys_days{std::chrono::December / 31 / 21969} + 23h,
0s,
0min,
"PREV"},
std::chrono::sys_info{
std::chrono::sys_days{std::chrono::January / 1 / 21970},
std::chrono::sys_days{std::chrono::March / 1 / 21970},
1h,
60min,
"NEXT"}},
R"(21970-01-01 is in a gap between
21969-12-31 23:00:00 PREV and
21970-01-01 01:00:00 NEXT which are both equivalent to
21969-12-31 23:00:00 UTC)");
test(std::chrono::local_time<std::chrono::weeks>{},
std::chrono::local_info{
std::chrono::local_info::nonexistent,
std::chrono::sys_info{
std::chrono::sys_days{std::chrono::September / 1 / 1969},
std::chrono::sys_days{std::chrono::December / 31 / 1969} + 23h,
0s,
0min,
"PREV"},
std::chrono::sys_info{
std::chrono::sys_days{std::chrono::January / 1 / 1970},
std::chrono::sys_days{std::chrono::March / 1 / 1970},
1h,
60min,
"NEXT"}},
R"(1970-01-01 is in a gap between
1969-12-31 23:00:00 PREV and
1970-01-01 01:00:00 NEXT which are both equivalent to
1969-12-31 23:00:00 UTC)");
// Note months and years can not be streamed.
return 0;
}
|