/src/znc/third_party/cctz/src/time_zone_if.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2016 Google Inc. All Rights Reserved. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #ifndef CCTZ_TIME_ZONE_IF_H_ |
16 | | #define CCTZ_TIME_ZONE_IF_H_ |
17 | | |
18 | | #include <chrono> |
19 | | #include <cstdint> |
20 | | #include <memory> |
21 | | #include <string> |
22 | | |
23 | | #include "cctz/civil_time.h" |
24 | | #include "cctz/time_zone.h" |
25 | | |
26 | | namespace cctz { |
27 | | |
28 | | // A simple interface used to hide time-zone complexities from time_zone::Impl. |
29 | | // Subclasses implement the functions for civil-time conversions in the zone. |
30 | | class TimeZoneIf { |
31 | | public: |
32 | | // A factory function for TimeZoneIf implementations. |
33 | | static std::unique_ptr<TimeZoneIf> Load(const std::string& name); |
34 | | |
35 | | virtual ~TimeZoneIf(); |
36 | | |
37 | | virtual time_zone::absolute_lookup BreakTime( |
38 | | const time_point<seconds>& tp) const = 0; |
39 | | virtual time_zone::civil_lookup MakeTime( |
40 | | const civil_second& cs) const = 0; |
41 | | |
42 | | virtual bool NextTransition(const time_point<seconds>& tp, |
43 | | time_zone::civil_transition* trans) const = 0; |
44 | | virtual bool PrevTransition(const time_point<seconds>& tp, |
45 | | time_zone::civil_transition* trans) const = 0; |
46 | | |
47 | | virtual std::string Version() const = 0; |
48 | | virtual std::string Description() const = 0; |
49 | | |
50 | | protected: |
51 | 0 | TimeZoneIf() {} |
52 | | }; |
53 | | |
54 | | // Convert between time_point<seconds> and a count of seconds since the |
55 | | // Unix epoch. We assume that the std::chrono::system_clock and the |
56 | | // Unix clock are second aligned, and that the results are representable. |
57 | | // (That is, that they share an epoch, which is required since C++20.) |
58 | 0 | inline std::int_fast64_t ToUnixSeconds(const time_point<seconds>& tp) { |
59 | 0 | return (tp - std::chrono::time_point_cast<seconds>( |
60 | 0 | std::chrono::system_clock::from_time_t(0))).count(); |
61 | 0 | } |
62 | 0 | inline time_point<seconds> FromUnixSeconds(std::int_fast64_t t) { |
63 | 0 | return std::chrono::time_point_cast<seconds>( |
64 | 0 | std::chrono::system_clock::from_time_t(0)) + seconds(t); |
65 | 0 | } |
66 | | |
67 | | } // namespace cctz |
68 | | |
69 | | #endif // CCTZ_TIME_ZONE_IF_H_ |