1 // Copyright 2016 Google Inc. All Rights Reserved.
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
7 // https://www.apache.org/licenses/LICENSE-2.0
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.
15 // Parsing of a POSIX zone spec as described in the TZ part of section 8.3 in
16 // http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html.
18 // The current POSIX spec for America/Los_Angeles is "PST8PDT,M3.2.0,M11.1.0",
19 // which would be broken down as ...
23 // std_offset = -28800
25 // dst_offset = -25200
26 // dst_start = PosixTransition {
38 // dst_end = PosixTransition {
52 #ifndef ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_POSIX_H_
53 #define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_POSIX_H_
59 namespace time_internal {
62 // The date/time of the transition. The date is specified as either:
63 // (J) the Nth day of the year (1 <= N <= 365), excluding leap days, or
64 // (N) the Nth day of the year (0 <= N <= 365), including leap days, or
65 // (M) the Nth weekday of a month (e.g., the 2nd Sunday in March).
66 // The time, specified as a day offset, identifies the particular moment
67 // of the transition, and may be negative or >= 24h, and in which case
68 // it would take us to another day, and perhaps week, or even month.
69 struct PosixTransition {
70 enum DateFormat { J, N, M };
74 std::int_fast16_t day; // day of non-leap year [1:365]
77 std::int_fast16_t day; // day of year [0:365]
79 struct MonthWeekWeekday {
80 std::int_fast8_t month; // month of year [1:12]
81 std::int_fast8_t week; // week of month [1:5] (5==last)
82 std::int_fast8_t weekday; // 0==Sun, ..., 6=Sat
95 std::int_fast32_t offset; // seconds before/after 00:00:00
102 // The entirety of a POSIX-string specified time-zone rule. The standard
103 // abbreviation and offset are always given. If the time zone includes
104 // daylight saving, then the daylight abbrevation is non-empty and the
105 // remaining fields are also valid. Note that the start/end transitions
106 // are not ordered---in the southern hemisphere the transition to end
107 // daylight time occurs first in any particular year.
108 struct PosixTimeZone {
109 std::string std_abbr;
110 std::int_fast32_t std_offset;
112 std::string dst_abbr;
113 std::int_fast32_t dst_offset;
114 PosixTransition dst_start;
115 PosixTransition dst_end;
118 // Breaks down a POSIX time-zone specification into its constituent pieces,
119 // filling in any missing values (DST offset, or start/end transition times)
120 // with the standard-defined defaults. Returns false if the specification
121 // could not be parsed (although some fields of *res may have been altered).
122 bool ParsePosixSpec(const std::string& spec, PosixTimeZone* res);
125 } // namespace time_internal
128 #endif // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_POSIX_H_