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// http://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_LIBC_H_
16#define CCTZ_TIME_ZONE_LIBC_H_
17
18#include <string>
19
20#include "time_zone_if.h"
21
22namespace cctz {
23
24// A time zone backed by gmtime_r(3), localtime_r(3), and mktime(3),
25// and which therefore only supports UTC and the local time zone.
26// TODO: Add support for fixed offsets from UTC.
27class TimeZoneLibC : public TimeZoneIf {
28 public:
29 explicit TimeZoneLibC(const std::string& name);
30
31 // TimeZoneIf implementations.
32 time_zone::absolute_lookup BreakTime(
33 const time_point<sys_seconds>& tp) const override;
34 time_zone::civil_lookup MakeTime(
35 const civil_second& cs) const override;
36 std::string Description() const override;
37 bool NextTransition(time_point<sys_seconds>* tp) const override;
38 bool PrevTransition(time_point<sys_seconds>* tp) const override;
39
40 private:
41 const bool local_; // localtime or UTC
42};
43
44} // namespace cctz
45
46#endif // CCTZ_TIME_ZONE_LIBC_H_
47