File: ctor.pass.cpp

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 1,998,492 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (171 lines) | stat: -rw-r--r-- 6,732 bytes parent folder | download | duplicates (7)
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
//===----------------------------------------------------------------------===//
//
// 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 ambiguous_local_time
//
//  template<class Duration>
//    ambiguous_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::ambiguous_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"
  // overlap 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::ambiguous,
           std::chrono::sys_info{
               std::chrono::sys_days{std::chrono::January / 1 / 1970},
               std::chrono::sys_days{std::chrono::March / 1 / 1970},
               1h,
               60min,
               "PREV"},

           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,
               "NEXT"}

       },
       R"(1969-12-31 23:59:59.999999999 is ambiguous.  It could be
1969-12-31 23:59:59.999999999 PREV == 1969-12-31 22:59:59.999999999 UTC or
1969-12-31 23:59:59.999999999 NEXT == 1969-12-31 23:59:59.999999999 UTC)");

  test(std::chrono::local_time<std::chrono::microseconds>{0us},
       std::chrono::local_info{
           std::chrono::local_info::ambiguous,
           std::chrono::sys_info{
               std::chrono::sys_days{std::chrono::January / 1 / 1970},
               std::chrono::sys_days{std::chrono::March / 1 / 1970},
               1h,
               60min,
               "PREV"},

           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,
               "NEXT"}},
       R"(1970-01-01 00:00:00.000000 is ambiguous.  It could be
1970-01-01 00:00:00.000000 PREV == 1969-12-31 23:00:00.000000 UTC or
1970-01-01 00:00:00.000000 NEXT == 1970-01-01 00:00:00.000000 UTC)");

  test(std::chrono::local_time<std::chrono::milliseconds>{1ms},
       std::chrono::local_info{
           std::chrono::local_info::ambiguous,
           std::chrono::sys_info{
               std::chrono::sys_days{std::chrono::January / 1 / 1970},
               std::chrono::sys_days{std::chrono::March / 1 / 1970},
               1h,
               60min,
               "PREV"},

           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,
               "NEXT"}},
       R"(1970-01-01 00:00:00.001 is ambiguous.  It could be
1970-01-01 00:00:00.001 PREV == 1969-12-31 23:00:00.001 UTC or
1970-01-01 00:00:00.001 NEXT == 1970-01-01 00:00:00.001 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::ambiguous,
           std::chrono::sys_info{
               std::chrono::sys_days{std::chrono::September / 1 / -21969},
               std::chrono::sys_days{std::chrono::December / 31 / -21969},
               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} + 23h,
               1h,
               60min,
               "NEXT"}},
       R"(-21970-01-01 00:00:00 is ambiguous.  It could be
-21970-01-01 00:00:00 PREV == -21970-01-01 00:00:00 UTC or
-21970-01-01 00:00:00 NEXT == -21971-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::ambiguous,
          std::chrono::sys_info{
              std::chrono::sys_days{std::chrono::September / 1 / 21969},
              std::chrono::sys_days{std::chrono::December / 31 / 21969},
              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} + 23h,
              1h,
              60min,
              "NEXT"}},
      R"(21970-01-01 is ambiguous.  It could be
21970-01-01 PREV == 21970-01-01 00:00:00 UTC or
21970-01-01 NEXT == 21969-12-31 23:00:00 UTC)");

  test(std::chrono::local_time<std::chrono::weeks>{},
       std::chrono::local_info{
           std::chrono::local_info::ambiguous,
           std::chrono::sys_info{
               std::chrono::sys_days{std::chrono::September / 1 / 1969},
               std::chrono::sys_days{std::chrono::December / 31 / 1969},
               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} + 23h,
               1h,
               60min,
               "NEXT"}},
       R"(1970-01-01 is ambiguous.  It could be
1970-01-01 PREV == 1970-01-01 00:00:00 UTC or
1970-01-01 NEXT == 1969-12-31 23:00:00 UTC)");

  // Note months and years can not be streamed.

  return 0;
}