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 #ifndef ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IMPL_H_
0016 #define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IMPL_H_
0017 
0018 #include <memory>
0019 #include <string>
0020 
0021 #include "absl/base/config.h"
0022 #include "absl/time/internal/cctz/include/cctz/civil_time.h"
0023 #include "absl/time/internal/cctz/include/cctz/time_zone.h"
0024 #include "time_zone_if.h"
0025 #include "time_zone_info.h"
0026 
0027 namespace absl {
0028 ABSL_NAMESPACE_BEGIN
0029 namespace time_internal {
0030 namespace cctz {
0031 
0032 // time_zone::Impl is the internal object referenced by a cctz::time_zone.
0033 class time_zone::Impl {
0034  public:
0035   // The UTC time zone. Also used for other time zones that fail to load.
0036   static time_zone UTC();
0037 
0038   // Load a named time zone. Returns false if the name is invalid, or if
0039   // some other kind of error occurs. Note that loading "UTC" never fails.
0040   static bool LoadTimeZone(const std::string& name, time_zone* tz);
0041 
0042   // Clears the map of cached time zones.  Primarily for use in benchmarks
0043   // that gauge the performance of loading/parsing the time-zone data.
0044   static void ClearTimeZoneMapTestOnly();
0045 
0046   // The primary key is the time-zone ID (e.g., "America/New_York").
0047   const std::string& Name() const {
0048     // TODO: It would nice if the zoneinfo data included the zone name.
0049     return name_;
0050   }
0051 
0052   // Breaks a time_point down to civil-time components in this time zone.
0053   time_zone::absolute_lookup BreakTime(const time_point<seconds>& tp) const {
0054     return zone_->BreakTime(tp);
0055   }
0056 
0057   // Converts the civil-time components in this time zone into a time_point.
0058   // That is, the opposite of BreakTime(). The requested civil time may be
0059   // ambiguous or illegal due to a change of UTC offset.
0060   time_zone::civil_lookup MakeTime(const civil_second& cs) const {
0061     return zone_->MakeTime(cs);
0062   }
0063 
0064   // Finds the time of the next/previous offset change in this time zone.
0065   bool NextTransition(const time_point<seconds>& tp,
0066                       time_zone::civil_transition* trans) const {
0067     return zone_->NextTransition(tp, trans);
0068   }
0069   bool PrevTransition(const time_point<seconds>& tp,
0070                       time_zone::civil_transition* trans) const {
0071     return zone_->PrevTransition(tp, trans);
0072   }
0073 
0074   // Returns an implementation-defined version string for this time zone.
0075   std::string Version() const { return zone_->Version(); }
0076 
0077   // Returns an implementation-defined description of this time zone.
0078   std::string Description() const { return zone_->Description(); }
0079 
0080  private:
0081   Impl();
0082   explicit Impl(const std::string& name);
0083   Impl(const Impl&) = delete;
0084   Impl& operator=(const Impl&) = delete;
0085 
0086   static const Impl* UTCImpl();
0087 
0088   const std::string name_;
0089   std::unique_ptr<TimeZoneIf> zone_;
0090 };
0091 
0092 }  // namespace cctz
0093 }  // namespace time_internal
0094 ABSL_NAMESPACE_END
0095 }  // namespace absl
0096 
0097 #endif  // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IMPL_H_