time_zone_if.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_IF_H_
16 #define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IF_H_
17 
18 #include <chrono>
19 #include <cstdint>
20 #include <memory>
21 #include <string>
22 
25 
26 namespace absl {
27 namespace time_internal {
28 namespace cctz {
29 
30 // A simple interface used to hide time-zone complexities from time_zone::Impl.
31 // Subclasses implement the functions for civil-time conversions in the zone.
32 class TimeZoneIf {
33  public:
34  // A factory function for TimeZoneIf implementations.
35  static std::unique_ptr<TimeZoneIf> Load(const std::string& name);
36 
37  virtual ~TimeZoneIf();
38 
40  const time_point<seconds>& tp) const = 0;
42  const civil_second& cs) const = 0;
43 
44  virtual bool NextTransition(const time_point<seconds>& tp,
45  time_zone::civil_transition* trans) const = 0;
46  virtual bool PrevTransition(const time_point<seconds>& tp,
47  time_zone::civil_transition* trans) const = 0;
48 
49  virtual std::string Version() const = 0;
50  virtual std::string Description() const = 0;
51 
52  protected:
54 };
55 
56 // Convert between time_point<seconds> and a count of seconds since the
57 // Unix epoch. We assume that the std::chrono::system_clock and the
58 // Unix clock are second aligned, but not that they share an epoch.
59 inline std::int_fast64_t ToUnixSeconds(const time_point<seconds>& tp) {
60  return (tp - std::chrono::time_point_cast<seconds>(
61  std::chrono::system_clock::from_time_t(0))).count();
62 }
63 inline time_point<seconds> FromUnixSeconds(std::int_fast64_t t) {
64  return std::chrono::time_point_cast<seconds>(
65  std::chrono::system_clock::from_time_t(0)) + seconds(t);
66 }
67 
68 } // namespace cctz
69 } // namespace time_internal
70 } // namespace absl
71 
72 #endif // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IF_H_
virtual bool PrevTransition(const time_point< seconds > &tp, time_zone::civil_transition *trans) const =0
virtual time_zone::civil_lookup MakeTime(const civil_second &cs) const =0
time_point< seconds > FromUnixSeconds(std::int_fast64_t t)
Definition: time_zone_if.h:63
std::chrono::duration< std::int_fast64_t > seconds
Definition: time_zone.h:37
Definition: algorithm.h:29
virtual time_zone::absolute_lookup BreakTime(const time_point< seconds > &tp) const =0
virtual bool NextTransition(const time_point< seconds > &tp, time_zone::civil_transition *trans) const =0
char name[1]
Definition: mutex.cc:296
virtual std::string Version() const =0
static std::unique_ptr< TimeZoneIf > Load(const std::string &name)
Definition: time_zone_if.cc:23
std::chrono::time_point< std::chrono::system_clock, D > time_point
Definition: time_zone.h:36
virtual std::string Description() const =0
std::int_fast64_t ToUnixSeconds(const time_point< seconds > &tp)
Definition: time_zone_if.h:59


abseil_cpp
Author(s):
autogenerated on Mon Feb 28 2022 21:31:21