summaryrefslogtreecommitdiff
path: root/test/test_tz_info.cc
blob: 962f903a3d6996ab12e358c097ea2691d9008b19 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "common.hh"

#include "file_test.hh"
#include "logger.hh"
#include "tz_info.hh"

#include <gtest/gtest.h>

namespace {

class TzInfoTest : public FileTest {
public:
  void Load(char const* data, size_t size) {
    write(std::string_view(data, size));
    close();
    tz_info_ = TzInfo::create(logger_, path().parent_path());
  }

  std::optional<time_t> get_local_time(time_t utc) {
    if (!tz_info_)
      return std::nullopt;
    return tz_info_->get_local_time(path().filename().c_str(), utc);
  }

private:
  std::shared_ptr<Logger> logger_{Logger::create_null()};
  std::unique_ptr<TzInfo> tz_info_;
};

constexpr const time_t kHour = 60 * 60;

}  // namespace

TEST_F(TzInfoTest, v2_honolulu) {
  char data[] =
    "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
    "\0\0\0\x6"
    "\0\0\0\x6"
    "\0\0\0\0"
    "\0\0\0\x7"
    "\0\0\0\x6"
    "\0\0\0\x14"
    "\x80\0\0\0"
    "\xbb\x05\x43\x48"
    "\xbb\x21\x71\x58"
    "\xcb\x89\x3d\xc8"
    "\xd2\x23\xf4\x70"
    "\xd2\x61\x49\x38"
    "\xd5\x8d\x73\x48"
    "\1\2\1\3\4\1\5"
    "\xff\xff\x6c\x02\0\x00"
    "\xff\xff\x6c\x58\0\x04"
    "\xff\xff\x7a\x68\1\x08"
    "\xff\xff\x7a\x68\1\x0c"
    "\xff\xff\x7a\x68\1\x10"
    "\xff\xff\x73\x60\0\x04"
    "LMT\0"
    "HST\0"
    "HDT\0"
    "HWT\0"
    "HPT\0"
    "\0\0\0\0\1\0"
    "\0\0\0\0\1\0"

    "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
    "\0\0\0\x6"
    "\0\0\0\x6"
    "\0\0\0\0"
    "\0\0\0\x7"
    "\0\0\0\x6"
    "\0\0\0\x14"
    "\xff\xff\xff\xff"
    "\x74\xe0\x70\xbe"
    "\xff\xff\xff\xff"
    "\xbb\x05\x43\x48"
    "\xff\xff\xff\xff"
    "\xbb\x21\x71\x58"
    "\xff\xff\xff\xff"
    "\xcb\x89\x3d\xc8"
    "\xff\xff\xff\xff"
    "\xd2\x23\xf4\x70"
    "\xff\xff\xff\xff"
    "\xd2\x61\x49\x38"
    "\xff\xff\xff\xff"
    "\xd5\x8d\x73\x48"
    "\1\2\1\3\4\1\5"
    "\xff\xff\x6c\x02\0\x00"
    "\xff\xff\x6c\x58\0\x04"
    "\xff\xff\x7a\x68\1\x08"
    "\xff\xff\x7a\x68\1\x0c"
    "\xff\xff\x7a\x68\1\x10"
    "\xff\xff\x73\x60\0\x04"
    "LMT\0"
    "HST\0"
    "HDT\0"
    "HWT\0"
    "HPT\0"
    "\0\0\0\0\1\0"
    "\0\0\0\0\1\0"
    "\nHST10\n";
  Load(data, sizeof(data) - 1);

  auto ret = get_local_time(-1156939200);  // 1933-05-04T12:00:00Z
  EXPECT_TRUE(ret.has_value());
  if (ret.has_value()) {
    EXPECT_EQ(-1156939200 - 9.5 * kHour, ret.value());
  }

  ret = get_local_time(1546300800);  // 2019-01-01T00:00:00Z
  EXPECT_TRUE(ret.has_value());
  if (ret.has_value()) {
    EXPECT_EQ(1546300800 - 10 * kHour, ret.value());
  }
}