File indexing completed on 2025-01-18 09:27:29
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_INFO_H_
0016 #define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_INFO_H_
0017
0018 #include <atomic>
0019 #include <cstddef>
0020 #include <cstdint>
0021 #include <memory>
0022 #include <string>
0023 #include <vector>
0024
0025 #include "absl/base/config.h"
0026 #include "absl/time/internal/cctz/include/cctz/civil_time.h"
0027 #include "absl/time/internal/cctz/include/cctz/time_zone.h"
0028 #include "absl/time/internal/cctz/include/cctz/zone_info_source.h"
0029 #include "time_zone_if.h"
0030 #include "tzfile.h"
0031
0032 namespace absl {
0033 ABSL_NAMESPACE_BEGIN
0034 namespace time_internal {
0035 namespace cctz {
0036
0037
0038 struct Transition {
0039 std::int_least64_t unix_time;
0040 std::uint_least8_t type_index;
0041 civil_second civil_sec;
0042 civil_second prev_civil_sec;
0043
0044 struct ByUnixTime {
0045 inline bool operator()(const Transition& lhs, const Transition& rhs) const {
0046 return lhs.unix_time < rhs.unix_time;
0047 }
0048 };
0049 struct ByCivilTime {
0050 inline bool operator()(const Transition& lhs, const Transition& rhs) const {
0051 return lhs.civil_sec < rhs.civil_sec;
0052 }
0053 };
0054 };
0055
0056
0057 struct TransitionType {
0058 std::int_least32_t utc_offset;
0059 civil_second civil_max;
0060 civil_second civil_min;
0061 bool is_dst;
0062 std::uint_least8_t abbr_index;
0063 };
0064
0065
0066 class TimeZoneInfo : public TimeZoneIf {
0067 public:
0068
0069 static std::unique_ptr<TimeZoneInfo> UTC();
0070 static std::unique_ptr<TimeZoneInfo> Make(const std::string& name);
0071
0072
0073 time_zone::absolute_lookup BreakTime(
0074 const time_point<seconds>& tp) const override;
0075 time_zone::civil_lookup MakeTime(const civil_second& cs) const override;
0076 bool NextTransition(const time_point<seconds>& tp,
0077 time_zone::civil_transition* trans) const override;
0078 bool PrevTransition(const time_point<seconds>& tp,
0079 time_zone::civil_transition* trans) const override;
0080 std::string Version() const override;
0081 std::string Description() const override;
0082
0083 private:
0084 TimeZoneInfo() = default;
0085 TimeZoneInfo(const TimeZoneInfo&) = delete;
0086 TimeZoneInfo& operator=(const TimeZoneInfo&) = delete;
0087
0088 bool GetTransitionType(std::int_fast32_t utc_offset, bool is_dst,
0089 const std::string& abbr, std::uint_least8_t* index);
0090 bool EquivTransitions(std::uint_fast8_t tt1_index,
0091 std::uint_fast8_t tt2_index) const;
0092 bool ExtendTransitions();
0093
0094 bool ResetToBuiltinUTC(const seconds& offset);
0095 bool Load(const std::string& name);
0096 bool Load(ZoneInfoSource* zip);
0097
0098
0099 time_zone::absolute_lookup LocalTime(std::int_fast64_t unix_time,
0100 const TransitionType& tt) const;
0101 time_zone::absolute_lookup LocalTime(std::int_fast64_t unix_time,
0102 const Transition& tr) const;
0103 time_zone::civil_lookup TimeLocal(const civil_second& cs,
0104 year_t c4_shift) const;
0105
0106 std::vector<Transition> transitions_;
0107 std::vector<TransitionType> transition_types_;
0108 std::uint_fast8_t default_transition_type_;
0109 std::string abbreviations_;
0110
0111 std::string version_;
0112 std::string future_spec_;
0113 bool extended_;
0114 year_t last_year_;
0115
0116
0117
0118
0119 mutable std::atomic<std::size_t> local_time_hint_ = {};
0120 mutable std::atomic<std::size_t> time_local_hint_ = {};
0121 };
0122
0123 }
0124 }
0125 ABSL_NAMESPACE_END
0126 }
0127
0128 #endif