Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_INFO_H_
00016 #define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_INFO_H_
00017
00018 #include <atomic>
00019 #include <cstddef>
00020 #include <cstdint>
00021 #include <string>
00022 #include <vector>
00023
00024 #include "absl/time/internal/cctz/include/cctz/civil_time.h"
00025 #include "absl/time/internal/cctz/include/cctz/time_zone.h"
00026 #include "absl/time/internal/cctz/include/cctz/zone_info_source.h"
00027 #include "time_zone_if.h"
00028 #include "tzfile.h"
00029
00030 namespace absl {
00031 namespace time_internal {
00032 namespace cctz {
00033
00034
00035 struct Transition {
00036 std::int_least64_t unix_time;
00037 std::uint_least8_t type_index;
00038 civil_second civil_sec;
00039 civil_second prev_civil_sec;
00040
00041 struct ByUnixTime {
00042 inline bool operator()(const Transition& lhs, const Transition& rhs) const {
00043 return lhs.unix_time < rhs.unix_time;
00044 }
00045 };
00046 struct ByCivilTime {
00047 inline bool operator()(const Transition& lhs, const Transition& rhs) const {
00048 return lhs.civil_sec < rhs.civil_sec;
00049 }
00050 };
00051 };
00052
00053
00054 struct TransitionType {
00055 std::int_least32_t utc_offset;
00056 civil_second civil_max;
00057 civil_second civil_min;
00058 bool is_dst;
00059 std::uint_least8_t abbr_index;
00060 };
00061
00062
00063 class TimeZoneInfo : public TimeZoneIf {
00064 public:
00065 TimeZoneInfo() = default;
00066 TimeZoneInfo(const TimeZoneInfo&) = delete;
00067 TimeZoneInfo& operator=(const TimeZoneInfo&) = delete;
00068
00069
00070 bool Load(const std::string& name);
00071
00072
00073 time_zone::absolute_lookup BreakTime(
00074 const time_point<seconds>& tp) const override;
00075 time_zone::civil_lookup MakeTime(
00076 const civil_second& cs) const override;
00077 bool NextTransition(const time_point<seconds>& tp,
00078 time_zone::civil_transition* trans) const override;
00079 bool PrevTransition(const time_point<seconds>& tp,
00080 time_zone::civil_transition* trans) const override;
00081 std::string Version() const override;
00082 std::string Description() const override;
00083
00084 private:
00085 struct Header {
00086 std::size_t timecnt;
00087 std::size_t typecnt;
00088 std::size_t charcnt;
00089 std::size_t leapcnt;
00090 std::size_t ttisstdcnt;
00091 std::size_t ttisgmtcnt;
00092
00093 bool Build(const tzhead& tzh);
00094 std::size_t DataLength(std::size_t time_len) const;
00095 };
00096
00097 void CheckTransition(const std::string& name, const TransitionType& tt,
00098 std::int_fast32_t offset, bool is_dst,
00099 const std::string& abbr) const;
00100 bool EquivTransitions(std::uint_fast8_t tt1_index,
00101 std::uint_fast8_t tt2_index) const;
00102 void ExtendTransitions(const std::string& name, const Header& hdr);
00103
00104 bool ResetToBuiltinUTC(const seconds& offset);
00105 bool Load(const std::string& name, ZoneInfoSource* zip);
00106
00107
00108 time_zone::absolute_lookup LocalTime(std::int_fast64_t unix_time,
00109 const TransitionType& tt) const;
00110 time_zone::absolute_lookup LocalTime(std::int_fast64_t unix_time,
00111 const Transition& tr) const;
00112 time_zone::civil_lookup TimeLocal(const civil_second& cs,
00113 year_t c4_shift) const;
00114
00115 std::vector<Transition> transitions_;
00116 std::vector<TransitionType> transition_types_;
00117 std::uint_fast8_t default_transition_type_;
00118 std::string abbreviations_;
00119
00120 std::string version_;
00121 std::string future_spec_;
00122 bool extended_;
00123 year_t last_year_;
00124
00125
00126
00127
00128 mutable std::atomic<std::size_t> local_time_hint_ = {};
00129 mutable std::atomic<std::size_t> time_local_hint_ = {};
00130 };
00131
00132 }
00133 }
00134 }
00135
00136 #endif // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_INFO_H_