/src/cctz/src/time_zone_impl.h
Line | Count | Source |
1 | | // Copyright 2016 Google Inc. All Rights Reserved. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #ifndef CCTZ_TIME_ZONE_IMPL_H_ |
16 | | #define CCTZ_TIME_ZONE_IMPL_H_ |
17 | | |
18 | | #include <memory> |
19 | | #include <string> |
20 | | |
21 | | #include "cctz/civil_time.h" |
22 | | #include "cctz/time_zone.h" |
23 | | #include "time_zone_if.h" |
24 | | #include "time_zone_info.h" |
25 | | |
26 | | namespace cctz { |
27 | | |
28 | | // time_zone::Impl is the internal object referenced by a cctz::time_zone. |
29 | | class time_zone::Impl { |
30 | | public: |
31 | | // The UTC time zone. Also used for other time zones that fail to load. |
32 | | static time_zone UTC(); |
33 | | |
34 | | // Load a named time zone. Returns false if the name is invalid, or if |
35 | | // some other kind of error occurs. Note that loading "UTC" never fails. |
36 | | static bool LoadTimeZone(const std::string& name, time_zone* tz); |
37 | | |
38 | | // Clears the map of cached time zones. Primarily for use in benchmarks |
39 | | // that gauge the performance of loading/parsing the time-zone data. |
40 | | static void ClearTimeZoneMapTestOnly(); |
41 | | |
42 | | // The primary key is the time-zone ID (e.g., "America/New_York"). |
43 | 0 | const std::string& Name() const { |
44 | | // TODO: It would nice if the zoneinfo data included the zone name. |
45 | 0 | return name_; |
46 | 0 | } |
47 | | |
48 | | // Breaks a time_point down to civil-time components in this time zone. |
49 | 8.45k | time_zone::absolute_lookup BreakTime(const time_point<seconds>& tp) const { |
50 | 8.45k | return zone_->BreakTime(tp); |
51 | 8.45k | } |
52 | | |
53 | | // Converts the civil-time components in this time zone into a time_point. |
54 | | // That is, the opposite of BreakTime(). The requested civil time may be |
55 | | // ambiguous or illegal due to a change of UTC offset. |
56 | 12.7k | time_zone::civil_lookup MakeTime(const civil_second& cs) const { |
57 | 12.7k | return zone_->MakeTime(cs); |
58 | 12.7k | } |
59 | | |
60 | | // Finds the time of the next/previous offset change in this time zone. |
61 | | bool NextTransition(const time_point<seconds>& tp, |
62 | 0 | time_zone::civil_transition* trans) const { |
63 | 0 | return zone_->NextTransition(tp, trans); |
64 | 0 | } |
65 | | bool PrevTransition(const time_point<seconds>& tp, |
66 | 0 | time_zone::civil_transition* trans) const { |
67 | 0 | return zone_->PrevTransition(tp, trans); |
68 | 0 | } |
69 | | |
70 | | // Returns an implementation-defined version string for this time zone. |
71 | 0 | std::string Version() const { return zone_->Version(); } |
72 | | |
73 | | // Returns an implementation-defined description of this time zone. |
74 | 0 | std::string Description() const { return zone_->Description(); } |
75 | | |
76 | | private: |
77 | | Impl(); |
78 | | explicit Impl(const std::string& name); |
79 | | Impl(const Impl&) = delete; |
80 | | Impl& operator=(const Impl&) = delete; |
81 | | |
82 | | static const Impl* UTCImpl(); |
83 | | |
84 | | const std::string name_; |
85 | | std::unique_ptr<TimeZoneIf> zone_; |
86 | | }; |
87 | | |
88 | | } // namespace cctz |
89 | | |
90 | | #endif // CCTZ_TIME_ZONE_IMPL_H_ |