summaryrefslogtreecommitdiff
path: root/test/test_tz_str.cc
blob: a96c4eaea37e5232fd2bfbc7a9b4580ec06666de (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
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
#include "common.hh"

#include "tz_str.hh"

#include <gtest/gtest.h>

namespace {

constexpr const time_t kMin = 60;
constexpr const time_t kHour = 60 * kMin;
constexpr const time_t kDay = 24 * kHour;

}  // namespace

TEST(tz_str, get_local_time_no_dst) {
  auto ret = tz::get_local_time("HST10", 0);
  EXPECT_TRUE(ret.has_value());
  if (ret.has_value()) {
    EXPECT_EQ(0 - 10 * kHour, ret.value());
  }

  ret = tz::get_local_time("HST10", kDay * 180);
  EXPECT_TRUE(ret.has_value());
  if (ret.has_value()) {
    EXPECT_EQ(kDay * 180 - 10 * kHour, ret.value());
  }
}

TEST(tz_str, get_local_time_quote) {
  auto ret = tz::get_local_time("<HST-FOO>10", 0);
  EXPECT_TRUE(ret.has_value());
  if (ret.has_value()) {
    EXPECT_EQ(0 - 10 * kHour, ret.value());
  }
}

TEST(tz_str, get_local_time_dst) {
  auto ret = tz::get_local_time("IST-1GMT0,M10.5.0,M3.5.0/1", 0);
  EXPECT_TRUE(ret.has_value());
  if (ret.has_value()) {
    EXPECT_EQ(0 * kHour, ret.value());
  }

  ret = tz::get_local_time("IST-1GMT0,M10.5.0,M3.5.0/1", kDay * 180);
  EXPECT_TRUE(ret.has_value());
  if (ret.has_value()) {
    EXPECT_EQ(kDay * 180 + 1 * kHour, ret.value());
  }

  ret = tz::get_local_time("GMT0IST,M3.5.0/1,M10.5.0", 0);
  EXPECT_TRUE(ret.has_value());
  if (ret.has_value()) {
    EXPECT_EQ(0 * kHour, ret.value());
  }

  ret = tz::get_local_time("GMT0IST,M3.5.0/1,M10.5.0", kDay * 180);
  EXPECT_TRUE(ret.has_value());
  if (ret.has_value()) {
    EXPECT_EQ(kDay * 180 + 1 * kHour, ret.value());
  }

  ret = tz::get_local_time("NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0", 0);
  EXPECT_TRUE(ret.has_value());
  if (ret.has_value()) {
    EXPECT_EQ(13 * kHour, ret.value());
  }

  ret = tz::get_local_time("NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0",
                           kDay * 180);
  EXPECT_TRUE(ret.has_value());
  if (ret.has_value()) {
    EXPECT_EQ(kDay * 180 + 12 * kHour, ret.value());
  }
}

TEST(tz_str, get_local_time_bad) {
  auto ret = tz::get_local_time("<HST-", 0);
  EXPECT_FALSE(ret.has_value());

  ret = tz::get_local_time("< >1", 0);
  EXPECT_FALSE(ret.has_value());

  ret = tz::get_local_time("HS10", 0);
  EXPECT_FALSE(ret.has_value());

  ret = tz::get_local_time("HST", 0);
  EXPECT_FALSE(ret.has_value());

  ret = tz::get_local_time("HST-300", 0);
  EXPECT_FALSE(ret.has_value());

  ret = tz::get_local_time("HST-10:300", 0);
  EXPECT_FALSE(ret.has_value());

  ret = tz::get_local_time("HST-10:00:300", 0);
  EXPECT_FALSE(ret.has_value());
}