summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/std/time/exceptions.cc
blob: 650b1fe7a374974ee554a7aab6298e9e17eb2a07 (plain)
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
// { dg-options "-std=gnu++20" }
// { dg-do run { target c++20 } }
// { dg-require-effective-target tzdb }

#include <chrono>
#include <testsuite_hooks.h>

void
test_nonexistent()
{
    std::string expected
      = "2016-03-13 02:30:00 is in a gap between\n"
	"2016-03-13 02:00:00 EST and\n"
	"2016-03-13 03:00:00 EDT which are both equivalent to\n"
	"2016-03-13 07:00:00 UTC";

  using namespace std::chrono;
  try {
    auto zt = zoned_time{"America/New_York",
			 local_days{Sunday[2]/March/2016} + 2h + 30min};
    VERIFY(false);
  } catch (const nonexistent_local_time& e) {
    VERIFY( e.what() == expected );
  }
}

void
test_ambiguous()
{
    std::string expected
      = "2016-11-06 01:30:00 is ambiguous.  It could be\n"
	"2016-11-06 01:30:00 EDT == 2016-11-06 05:30:00 UTC or\n"
	"2016-11-06 01:30:00 EST == 2016-11-06 06:30:00 UTC";

  using namespace std::chrono;
  try {
    auto zt = zoned_time{"America/New_York",
			 local_days{Sunday[1]/November/2016} + 1h + 30min};
    VERIFY(false);
  } catch (const ambiguous_local_time& e) {
    VERIFY( e.what() == expected );
  }
}

int main()
{
  test_nonexistent();
  test_ambiguous();
}