time_zone_if.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_IF_H_
00016 #define ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IF_H_
00017 
00018 #include <chrono>
00019 #include <cstdint>
00020 #include <memory>
00021 #include <string>
00022 
00023 #include "absl/time/internal/cctz/include/cctz/civil_time.h"
00024 #include "absl/time/internal/cctz/include/cctz/time_zone.h"
00025 
00026 namespace absl {
00027 namespace time_internal {
00028 namespace cctz {
00029 
00030 // A simple interface used to hide time-zone complexities from time_zone::Impl.
00031 // Subclasses implement the functions for civil-time conversions in the zone.
00032 class TimeZoneIf {
00033  public:
00034   // A factory function for TimeZoneIf implementations.
00035   static std::unique_ptr<TimeZoneIf> Load(const std::string& name);
00036 
00037   virtual ~TimeZoneIf();
00038 
00039   virtual time_zone::absolute_lookup BreakTime(
00040       const time_point<seconds>& tp) const = 0;
00041   virtual time_zone::civil_lookup MakeTime(
00042       const civil_second& cs) const = 0;
00043 
00044   virtual bool NextTransition(const time_point<seconds>& tp,
00045                               time_zone::civil_transition* trans) const = 0;
00046   virtual bool PrevTransition(const time_point<seconds>& tp,
00047                               time_zone::civil_transition* trans) const = 0;
00048 
00049   virtual std::string Version() const = 0;
00050   virtual std::string Description() const = 0;
00051 
00052  protected:
00053   TimeZoneIf() {}
00054 };
00055 
00056 // Convert between time_point<seconds> and a count of seconds since the
00057 // Unix epoch.  We assume that the std::chrono::system_clock and the
00058 // Unix clock are second aligned, but not that they share an epoch.
00059 inline std::int_fast64_t ToUnixSeconds(const time_point<seconds>& tp) {
00060   return (tp - std::chrono::time_point_cast<seconds>(
00061                    std::chrono::system_clock::from_time_t(0))).count();
00062 }
00063 inline time_point<seconds> FromUnixSeconds(std::int_fast64_t t) {
00064   return std::chrono::time_point_cast<seconds>(
00065              std::chrono::system_clock::from_time_t(0)) + seconds(t);
00066 }
00067 
00068 }  // namespace cctz
00069 }  // namespace time_internal
00070 }  // namespace absl
00071 
00072 #endif  // ABSL_TIME_INTERNAL_CCTZ_TIME_ZONE_IF_H_


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