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_IF_H_
0016 #define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IF_H_
0017 
0018 #include <chrono>
0019 #include <cstdint>
0020 #include <memory>
0021 #include <string>
0022 
0023 #include "absl/base/config.h"
0024 #include "absl/time/internal/cctz/include/cctz/civil_time.h"
0025 #include "absl/time/internal/cctz/include/cctz/time_zone.h"
0026 
0027 namespace absl {
0028 ABSL_NAMESPACE_BEGIN
0029 namespace time_internal {
0030 namespace cctz {
0031 
0032 // A simple interface used to hide time-zone complexities from time_zone::Impl.
0033 // Subclasses implement the functions for civil-time conversions in the zone.
0034 class TimeZoneIf {
0035  public:
0036   // Factory functions for TimeZoneIf implementations.
0037   static std::unique_ptr<TimeZoneIf> UTC();  // never fails
0038   static std::unique_ptr<TimeZoneIf> Make(const std::string& name);
0039 
0040   virtual ~TimeZoneIf();
0041 
0042   virtual time_zone::absolute_lookup BreakTime(
0043       const time_point<seconds>& tp) const = 0;
0044   virtual time_zone::civil_lookup MakeTime(const civil_second& cs) const = 0;
0045 
0046   virtual bool NextTransition(const time_point<seconds>& tp,
0047                               time_zone::civil_transition* trans) const = 0;
0048   virtual bool PrevTransition(const time_point<seconds>& tp,
0049                               time_zone::civil_transition* trans) const = 0;
0050 
0051   virtual std::string Version() const = 0;
0052   virtual std::string Description() const = 0;
0053 
0054  protected:
0055   TimeZoneIf() = default;
0056   TimeZoneIf(const TimeZoneIf&) = delete;
0057   TimeZoneIf& operator=(const TimeZoneIf&) = delete;
0058 };
0059 
0060 // Convert between time_point<seconds> and a count of seconds since the
0061 // Unix epoch.  We assume that the std::chrono::system_clock and the
0062 // Unix clock are second aligned, and that the results are representable.
0063 // (That is, that they share an epoch, which is required since C++20.)
0064 inline std::int_fast64_t ToUnixSeconds(const time_point<seconds>& tp) {
0065   return (tp - std::chrono::time_point_cast<seconds>(
0066                    std::chrono::system_clock::from_time_t(0)))
0067       .count();
0068 }
0069 inline time_point<seconds> FromUnixSeconds(std::int_fast64_t t) {
0070   return std::chrono::time_point_cast<seconds>(
0071              std::chrono::system_clock::from_time_t(0)) +
0072          seconds(t);
0073 }
0074 
0075 }  // namespace cctz
0076 }  // namespace time_internal
0077 ABSL_NAMESPACE_END
0078 }  // namespace absl
0079 
0080 #endif  // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IF_H_