Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:29

0001 // Copyright 2016 Google Inc. All Rights Reserved.
0002 //
0003 // Licensed under the Apache License, Version 2.0 (the "License");
0004 // you may not use this file except in compliance with the License.
0005 // You may obtain a copy of the License at
0006 //
0007 //   https://www.apache.org/licenses/LICENSE-2.0
0008 //
0009 //   Unless required by applicable law or agreed to in writing, software
0010 //   distributed under the License is distributed on an "AS IS" BASIS,
0011 //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0012 //   See the License for the specific language governing permissions and
0013 //   limitations under the License.
0014 
0015 // Parsing of a POSIX zone spec as described in the TZ part of section 8.3 in
0016 // http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html.
0017 //
0018 // The current POSIX spec for America/Los_Angeles is "PST8PDT,M3.2.0,M11.1.0",
0019 // which would be broken down as ...
0020 //
0021 //   PosixTimeZone {
0022 //     std_abbr = "PST"
0023 //     std_offset = -28800
0024 //     dst_abbr = "PDT"
0025 //     dst_offset = -25200
0026 //     dst_start = PosixTransition {
0027 //       date {
0028 //         m {
0029 //           month = 3
0030 //           week = 2
0031 //           weekday = 0
0032 //         }
0033 //       }
0034 //       time {
0035 //         offset = 7200
0036 //       }
0037 //     }
0038 //     dst_end = PosixTransition {
0039 //       date {
0040 //         m {
0041 //           month = 11
0042 //           week = 1
0043 //           weekday = 0
0044 //         }
0045 //       }
0046 //       time {
0047 //         offset = 7200
0048 //       }
0049 //     }
0050 //   }
0051 
0052 #ifndef ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_POSIX_H_
0053 #define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_POSIX_H_
0054 
0055 #include <cstdint>
0056 #include <string>
0057 
0058 #include "absl/base/config.h"
0059 
0060 namespace absl {
0061 ABSL_NAMESPACE_BEGIN
0062 namespace time_internal {
0063 namespace cctz {
0064 
0065 // The date/time of the transition. The date is specified as either:
0066 // (J) the Nth day of the year (1 <= N <= 365), excluding leap days, or
0067 // (N) the Nth day of the year (0 <= N <= 365), including leap days, or
0068 // (M) the Nth weekday of a month (e.g., the 2nd Sunday in March).
0069 // The time, specified as a day offset, identifies the particular moment
0070 // of the transition, and may be negative or >= 24h, and in which case
0071 // it would take us to another day, and perhaps week, or even month.
0072 struct PosixTransition {
0073   enum DateFormat { J, N, M };
0074 
0075   struct Date {
0076     struct NonLeapDay {
0077       std::int_fast16_t day;  // day of non-leap year [1:365]
0078     };
0079     struct Day {
0080       std::int_fast16_t day;  // day of year [0:365]
0081     };
0082     struct MonthWeekWeekday {
0083       std::int_fast8_t month;    // month of year [1:12]
0084       std::int_fast8_t week;     // week of month [1:5] (5==last)
0085       std::int_fast8_t weekday;  // 0==Sun, ..., 6=Sat
0086     };
0087 
0088     DateFormat fmt;
0089 
0090     union {
0091       NonLeapDay j;
0092       Day n;
0093       MonthWeekWeekday m;
0094     };
0095   };
0096 
0097   struct Time {
0098     std::int_fast32_t offset;  // seconds before/after 00:00:00
0099   };
0100 
0101   Date date;
0102   Time time;
0103 };
0104 
0105 // The entirety of a POSIX-string specified time-zone rule. The standard
0106 // abbreviation and offset are always given. If the time zone includes
0107 // daylight saving, then the daylight abbreviation is non-empty and the
0108 // remaining fields are also valid. Note that the start/end transitions
0109 // are not ordered---in the southern hemisphere the transition to end
0110 // daylight time occurs first in any particular year.
0111 struct PosixTimeZone {
0112   std::string std_abbr;
0113   std::int_fast32_t std_offset;
0114 
0115   std::string dst_abbr;
0116   std::int_fast32_t dst_offset;
0117   PosixTransition dst_start;
0118   PosixTransition dst_end;
0119 };
0120 
0121 // Breaks down a POSIX time-zone specification into its constituent pieces,
0122 // filling in any missing values (DST offset, or start/end transition times)
0123 // with the standard-defined defaults. Returns false if the specification
0124 // could not be parsed (although some fields of *res may have been altered).
0125 bool ParsePosixSpec(const std::string& spec, PosixTimeZone* res);
0126 
0127 }  // namespace cctz
0128 }  // namespace time_internal
0129 ABSL_NAMESPACE_END
0130 }  // namespace absl
0131 
0132 #endif  // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_POSIX_H_