time_zone_impl.h
Go to the documentation of this file.
00001 // Copyright 2016 Google Inc. All Rights Reserved.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //   https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 //   Unless required by applicable law or agreed to in writing, software
00010 //   distributed under the License is distributed on an "AS IS" BASIS,
00011 //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 //   See the License for the specific language governing permissions and
00013 //   limitations under the License.
00014 
00015 #ifndef ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IMPL_H_
00016 #define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IMPL_H_
00017 
00018 #include <memory>
00019 #include <string>
00020 
00021 #include "absl/time/internal/cctz/include/cctz/civil_time.h"
00022 #include "absl/time/internal/cctz/include/cctz/time_zone.h"
00023 #include "time_zone_if.h"
00024 #include "time_zone_info.h"
00025 
00026 namespace absl {
00027 namespace time_internal {
00028 namespace cctz {
00029 
00030 // time_zone::Impl is the internal object referenced by a cctz::time_zone.
00031 class time_zone::Impl {
00032  public:
00033   // The UTC time zone. Also used for other time zones that fail to load.
00034   static time_zone UTC();
00035 
00036   // Load a named time zone. Returns false if the name is invalid, or if
00037   // some other kind of error occurs. Note that loading "UTC" never fails.
00038   static bool LoadTimeZone(const std::string& name, time_zone* tz);
00039 
00040   // Clears the map of cached time zones.  Primarily for use in benchmarks
00041   // that gauge the performance of loading/parsing the time-zone data.
00042   static void ClearTimeZoneMapTestOnly();
00043 
00044   // The primary key is the time-zone ID (e.g., "America/New_York").
00045   const std::string& Name() const {
00046     // TODO: It would nice if the zoneinfo data included the zone name.
00047     return name_;
00048   }
00049 
00050   // Breaks a time_point down to civil-time components in this time zone.
00051   time_zone::absolute_lookup BreakTime(const time_point<seconds>& tp) const {
00052     return zone_->BreakTime(tp);
00053   }
00054 
00055   // Converts the civil-time components in this time zone into a time_point.
00056   // That is, the opposite of BreakTime(). The requested civil time may be
00057   // ambiguous or illegal due to a change of UTC offset.
00058   time_zone::civil_lookup MakeTime(const civil_second& cs) const {
00059     return zone_->MakeTime(cs);
00060   }
00061 
00062   // Finds the time of the next/previous offset change in this time zone.
00063   bool NextTransition(const time_point<seconds>& tp,
00064                       time_zone::civil_transition* trans) const {
00065     return zone_->NextTransition(tp, trans);
00066   }
00067   bool PrevTransition(const time_point<seconds>& tp,
00068                       time_zone::civil_transition* trans) const {
00069     return zone_->PrevTransition(tp, trans);
00070   }
00071 
00072   // Returns an implementation-defined version std::string for this time zone.
00073   std::string Version() const { return zone_->Version(); }
00074 
00075   // Returns an implementation-defined description of this time zone.
00076   std::string Description() const { return zone_->Description(); }
00077 
00078  private:
00079   explicit Impl(const std::string& name);
00080   static const Impl* UTCImpl();
00081 
00082   const std::string name_;
00083   std::unique_ptr<TimeZoneIf> zone_;
00084 };
00085 
00086 }  // namespace cctz
00087 }  // namespace time_internal
00088 }  // namespace absl
00089 
00090 #endif  // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IMPL_H_


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:15