• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_LIBC_H_
16 #define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_LIBC_H_
17 
18 #include <memory>
19 #include <string>
20 
21 #include "absl/base/config.h"
22 #include "time_zone_if.h"
23 
24 namespace absl {
25 ABSL_NAMESPACE_BEGIN
26 namespace time_internal {
27 namespace cctz {
28 
29 // A time zone backed by gmtime_r(3), localtime_r(3), and mktime(3),
30 // and which therefore only supports UTC and the local time zone.
31 class TimeZoneLibC : public TimeZoneIf {
32  public:
33   // Factory.
34   static std::unique_ptr<TimeZoneLibC> Make(const std::string& name);
35 
36   // TimeZoneIf implementations.
37   time_zone::absolute_lookup BreakTime(
38       const time_point<seconds>& tp) const override;
39   time_zone::civil_lookup MakeTime(const civil_second& cs) const override;
40   bool NextTransition(const time_point<seconds>& tp,
41                       time_zone::civil_transition* trans) const override;
42   bool PrevTransition(const time_point<seconds>& tp,
43                       time_zone::civil_transition* trans) const override;
44   std::string Version() const override;
45   std::string Description() const override;
46 
47  private:
48   explicit TimeZoneLibC(const std::string& name);
49   TimeZoneLibC(const TimeZoneLibC&) = delete;
50   TimeZoneLibC& operator=(const TimeZoneLibC&) = delete;
51 
52   const bool local_;  // localtime or UTC
53 };
54 
55 }  // namespace cctz
56 }  // namespace time_internal
57 ABSL_NAMESPACE_END
58 }  // namespace absl
59 
60 #endif  // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_LIBC_H_
61