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_FIXED_H_
16#define CCTZ_TIME_ZONE_FIXED_H_
17
18#include <string>
19
20#include "cctz/time_zone.h"
21
22namespace cctz {
23
24// Helper functions for dealing with the names and abbreviations
25// of time zones that are a fixed offset (seconds east) from UTC.
26// FixedOffsetFromName() extracts the offset from a valid fixed-offset
27// name, while FixedOffsetToName() and FixedOffsetToAbbr() generate
28// the canonical zone name and abbreviation respectively for the given
29// offset.
30//
31// A fixed-offset name looks like "Fixed/UTC<+-><hours>:<mins>:<secs>".
32// Its abbreviation is of the form "UTC(<+->H?H(MM(SS)?)?)?" where the
33// optional pieces are omitted when their values are zero. (Note that
34// the sign is the opposite of that used in a POSIX TZ specification.)
35//
36// Note: FixedOffsetFromName() fails on syntax errors or when the parsed
37// offset exceeds 24 hours. FixedOffsetToName() and FixedOffsetToAbbr()
38// both produce "UTC" when the argument offset exceeds 24 hours.
39bool FixedOffsetFromName(const std::string& name, sys_seconds* offset);
40std::string FixedOffsetToName(const sys_seconds& offset);
41std::string FixedOffsetToAbbr(const sys_seconds& offset);
42
43} // namespace cctz
44
45#endif // CCTZ_TIME_ZONE_FIXED_H_
46