blob: 6c8b86125937134148fed3f84179ec611f47c24a (
plain) (
blame)
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
|
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TIMEZONE_HH
#define TIMEZONE_HH
// This file is for timezone routines.
#include "Adaptor.hh"
#include <memory>
#include <stdexcept>
#include <stdint.h>
#include <string>
#include <vector>
namespace orc {
static const int64_t SECONDS_PER_HOUR = 60 * 60;
static const int64_t SECONDS_PER_DAY = SECONDS_PER_HOUR * 24;
/**
* A variant (eg. PST or PDT) of a timezone (eg. America/Los_Angeles).
*/
struct TimezoneVariant {
int64_t gmtOffset;
bool isDst;
std::string name;
bool hasSameTzRule(const TimezoneVariant& other) const {
return gmtOffset == other.gmtOffset && isDst == other.isDst;
}
std::string toString() const;
};
/**
* A region that shares the same legal rules for wall clock time and
* day light savings transitions. They are typically named for the largest
* city in the region (eg. America/Los_Angeles or America/Mexico_City).
*/
class Timezone {
public:
virtual ~Timezone();
/**
* Get the variant for the given time (time_t).
*/
virtual const TimezoneVariant& getVariant(int64_t clk) const = 0;
/**
* Get the number of seconds between the ORC epoch in this timezone
* and Unix epoch.
* ORC epoch is 1 Jan 2015 00:00:00 local.
* Unix epoch is 1 Jan 1970 00:00:00 UTC.
*/
virtual int64_t getEpoch() const = 0;
/**
* Print the timezone to the stream.
*/
virtual void print(std::ostream&) const = 0;
/**
* Get the version of the zone file.
*/
virtual uint64_t getVersion() const =0;
/**
* Convert wall clock time of current timezone to UTC timezone
*/
virtual int64_t convertToUTC(int64_t clk) const = 0;
};
/**
* Get the local timezone.
* Results are cached.
*/
const Timezone& getLocalTimezone();
/**
* Get a timezone by name (eg. America/Los_Angeles).
* Results are cached.
*/
const Timezone& getTimezoneByName(const std::string& zone);
/**
* Parse a set of bytes as a timezone file as if they came from filename.
*/
std::unique_ptr<Timezone> getTimezone(const std::string& filename,
const std::vector<unsigned char>& b);
class TimezoneError: public std::runtime_error {
public:
TimezoneError(const std::string& what);
TimezoneError(const TimezoneError&);
virtual ~TimezoneError() ORC_NOEXCEPT;
};
/**
* Represents the parsed POSIX timezone rule strings that are used to
* describe the future transitions, because they can go arbitrarily far into
* the future.
*/
class FutureRule {
public:
virtual ~FutureRule();
virtual bool isDefined() const = 0;
virtual const TimezoneVariant& getVariant(int64_t clk) const = 0;
virtual void print(std::ostream& out) const = 0;
};
/**
* Parse the POSIX TZ string.
*/
std::shared_ptr<FutureRule> parseFutureRule(const std::string& ruleString);
}
#endif
|