time_zone_impl.h
Go to the documentation of this file.
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 ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IMPL_H_
16 #define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IMPL_H_
17 
18 #include <memory>
19 #include <string>
20 
23 #include "time_zone_if.h"
24 #include "time_zone_info.h"
25 
26 namespace absl {
27 namespace time_internal {
28 namespace cctz {
29 
30 // time_zone::Impl is the internal object referenced by a cctz::time_zone.
32  public:
33  // The UTC time zone. Also used for other time zones that fail to load.
34  static time_zone UTC();
35 
36  // Load a named time zone. Returns false if the name is invalid, or if
37  // some other kind of error occurs. Note that loading "UTC" never fails.
38  static bool LoadTimeZone(const std::string& name, time_zone* tz);
39 
40  // Clears the map of cached time zones. Primarily for use in benchmarks
41  // that gauge the performance of loading/parsing the time-zone data.
42  static void ClearTimeZoneMapTestOnly();
43 
44  // The primary key is the time-zone ID (e.g., "America/New_York").
45  const std::string& Name() const {
46  // TODO: It would nice if the zoneinfo data included the zone name.
47  return name_;
48  }
49 
50  // Breaks a time_point down to civil-time components in this time zone.
52  return zone_->BreakTime(tp);
53  }
54 
55  // Converts the civil-time components in this time zone into a time_point.
56  // That is, the opposite of BreakTime(). The requested civil time may be
57  // ambiguous or illegal due to a change of UTC offset.
59  return zone_->MakeTime(cs);
60  }
61 
62  // Finds the time of the next/previous offset change in this time zone.
64  time_zone::civil_transition* trans) const {
65  return zone_->NextTransition(tp, trans);
66  }
68  time_zone::civil_transition* trans) const {
69  return zone_->PrevTransition(tp, trans);
70  }
71 
72  // Returns an implementation-defined version std::string for this time zone.
73  std::string Version() const { return zone_->Version(); }
74 
75  // Returns an implementation-defined description of this time zone.
76  std::string Description() const { return zone_->Description(); }
77 
78  private:
79  explicit Impl(const std::string& name);
80  static const Impl* UTCImpl();
81 
82  const std::string name_;
83  std::unique_ptr<TimeZoneIf> zone_;
84 };
85 
86 } // namespace cctz
87 } // namespace time_internal
88 } // namespace absl
89 
90 #endif // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IMPL_H_
static bool LoadTimeZone(const std::string &name, time_zone *tz)
bool NextTransition(const time_point< seconds > &tp, time_zone::civil_transition *trans) const
Definition: algorithm.h:29
std::unique_ptr< TimeZoneIf > zone_
time_zone::absolute_lookup BreakTime(const time_point< seconds > &tp) const
time_zone::civil_lookup MakeTime(const civil_second &cs) const
std::chrono::time_point< std::chrono::system_clock, D > time_point
Definition: time_zone.h:36
const std::string & Name() const
bool PrevTransition(const time_point< seconds > &tp, time_zone::civil_transition *trans) const


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:19:58