1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 // For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html 11 12 #ifndef __LIBCPP_SRC_INCLUDE_TZDB_TYPES_PRIVATE_H 13 #define __LIBCPP_SRC_INCLUDE_TZDB_TYPES_PRIVATE_H 14 15 #include <chrono> 16 #include <string> 17 #include <utility> 18 #include <variant> 19 #include <vector> 20 21 _LIBCPP_BEGIN_NAMESPACE_STD 22 23 // TODO TZDB 24 // The helper classes in this header have no constructor but are loaded with 25 // dedicated parse functions. In the original design this header was public and 26 // the parsing was done in the dylib. In that design having constructors would 27 // expand the ABI interface. Since this header is now in the dylib that design 28 // should be reconsidered. (For now the design is kept as is, in case this 29 // header needs to be public for unforseen reasons.) 30 31 namespace chrono::__tz { 32 33 // Sun>=8 first Sunday on or after the eighth 34 // Sun<=25 last Sunday on or before the 25th 35 struct __constrained_weekday { 36 /* year_month_day operator()(year __year, month __month);*/ // needed but not implemented 37 38 weekday __weekday; 39 enum __comparison_t { __le, __ge } __comparison; 40 day __day; 41 }; 42 43 // The on field has a few alternative presentations 44 // 5 the fifth of the month 45 // lastSun the last Sunday in the month 46 // lastMon the last Monday in the month 47 // Sun>=8 first Sunday on or after the eighth 48 // Sun<=25 last Sunday on or before the 25th 49 using __on = variant<day, weekday_last, __constrained_weekday>; 50 51 enum class __clock { __local, __standard, __universal }; 52 53 struct __at { 54 seconds __time{0}; 55 __tz::__clock __clock{__tz::__clock::__local}; 56 }; 57 58 struct __save { 59 seconds __time; 60 bool __is_dst; 61 }; 62 63 // The names of the fields match the fields of a Rule. 64 struct __rule { 65 year __from; 66 year __to; 67 month __in; 68 __tz::__on __on; 69 __tz::__at __at; 70 __tz::__save __save; 71 string __letters; 72 }; 73 74 using __rules_storage_type = std::vector<std::pair<string, vector<__tz::__rule>>>; // TODO TZDB use flat_map; 75 76 struct __continuation { 77 // Non-owning link to the RULE entries. 78 __tz::__rules_storage_type* __rule_database_; 79 80 seconds __stdoff; 81 82 // The RULES is either a SAVE or a NAME. 83 // The size_t is used as cache. After loading the rules they are 84 // sorted and remain stable, then an index in the vector can be 85 // used. 86 // If this field contains - then standard time always 87 // applies. This is indicated by the monostate. 88 using __rules_t = variant<monostate, __tz::__save, string, size_t>; 89 90 __rules_t __rules; 91 92 string __format; 93 // TODO TZDB the until field can contain more than just a year. 94 // Parts of the UNTIL, the optional parts are default initialized 95 // optional<year> __until_; 96 year __year = chrono::year::min(); 97 month __in{January}; 98 __tz::__on __on{chrono::day{1}}; 99 __tz::__at __at{chrono::seconds{0}, __tz::__clock::__local}; 100 }; 101 102 } // namespace chrono::__tz 103 104 _LIBCPP_END_NAMESPACE_STD 105 106 #endif // __LIBCPP_SRC_INCLUDE_TZDB_TYPES_PRIVATE_H 107