|
| 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___CHRONO_TIME_ZONE_TYPES_H |
| 13 | +#define _LIBCPP___CHRONO_TIME_ZONE_TYPES_H |
| 14 | + |
| 15 | +#include <version> |
| 16 | +// Enable the contents of the header only when libc++ was built with experimental features enabled. |
| 17 | +#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB) |
| 18 | + |
| 19 | +# include <__chrono/day.h> |
| 20 | +# include <__chrono/duration.h> |
| 21 | +# include <__chrono/month.h> |
| 22 | +# include <__chrono/weekday.h> |
| 23 | +# include <__chrono/year.h> |
| 24 | +# include <__config> |
| 25 | +# include <string> |
| 26 | +# include <variant> |
| 27 | + |
| 28 | +# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 29 | +# pragma GCC system_header |
| 30 | +# endif |
| 31 | + |
| 32 | +_LIBCPP_BEGIN_NAMESPACE_STD |
| 33 | + |
| 34 | +# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ |
| 35 | + !defined(_LIBCPP_HAS_NO_LOCALIZATION) |
| 36 | + |
| 37 | +namespace chrono::__tz { |
| 38 | + |
| 39 | +// Sun>=8 first Sunday on or after the eighth |
| 40 | +// Sun<=25 last Sunday on or before the 25th |
| 41 | +struct _LIBCPP_AVAILABILITY_TZDB __constrained_weekday { |
| 42 | + /* year_month_day operator()(year __year, month __month);*/ // needed but not implemented |
| 43 | + |
| 44 | + weekday __weekday; |
| 45 | + enum __comparison_t { __le, __ge } __comparison; |
| 46 | + day __day; |
| 47 | +}; |
| 48 | + |
| 49 | +// The on field has a few alternative presentations |
| 50 | +// 5 the fifth of the month |
| 51 | +// lastSun the last Sunday in the month |
| 52 | +// lastMon the last Monday in the month |
| 53 | +// Sun>=8 first Sunday on or after the eighth |
| 54 | +// Sun<=25 last Sunday on or before the 25th |
| 55 | +using __on = variant<day, weekday_last, __constrained_weekday>; |
| 56 | + |
| 57 | +enum class _LIBCPP_AVAILABILITY_TZDB __clock { __local, __standard, __universal }; |
| 58 | + |
| 59 | +struct _LIBCPP_AVAILABILITY_TZDB __at { |
| 60 | + seconds __time{0}; |
| 61 | + __tz::__clock __clock{__tz::__clock::__local}; |
| 62 | +}; |
| 63 | + |
| 64 | +struct _LIBCPP_AVAILABILITY_TZDB __save { |
| 65 | + seconds __time; |
| 66 | + bool __is_dst; |
| 67 | +}; |
| 68 | + |
| 69 | +// The names of the fields match the fields of a Rule. |
| 70 | +struct _LIBCPP_AVAILABILITY_TZDB __rule { |
| 71 | + year __from; |
| 72 | + year __to; |
| 73 | + month __in_month; // __in is a reserved name |
| 74 | + __tz::__on __on; |
| 75 | + __tz::__at __at; |
| 76 | + __tz::__save __save; |
| 77 | + string __letters; |
| 78 | +}; |
| 79 | + |
| 80 | +struct _LIBCPP_AVAILABILITY_TZDB __continuation { |
| 81 | + seconds __stdoff; |
| 82 | + |
| 83 | + // The RULES is either a SAVE or a NAME. |
| 84 | + // The size_t is used as cache. After loading the rules they are |
| 85 | + // sorted and remain stable, then an index in the vector can be |
| 86 | + // used. |
| 87 | + // If this field contains - then standard time always |
| 88 | + // applies. This is indicated by the monostate. |
| 89 | + using __rules_t = variant<monostate, __tz::__save, string, size_t>; |
| 90 | + |
| 91 | + __rules_t __rules; |
| 92 | + |
| 93 | + string __format; |
| 94 | + // TODO TZDB until can be contain more than just a year. |
| 95 | + // Parts of the UNTIL, the optional parts are default initialized |
| 96 | + // optional<year> __until_; |
| 97 | + year __year = chrono::year::min(); |
| 98 | + month __in_month{January}; // __in is a reserved name |
| 99 | + __tz::__on __on{chrono::day{1}}; |
| 100 | + __tz::__at __at{chrono::seconds{0}, __tz::__clock::__local}; |
| 101 | +}; |
| 102 | + |
| 103 | +} // namespace chrono::__tz |
| 104 | + |
| 105 | +# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) |
| 106 | + // && !defined(_LIBCPP_HAS_NO_LOCALIZATION) |
| 107 | + |
| 108 | +_LIBCPP_END_NAMESPACE_STD |
| 109 | + |
| 110 | +#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB) |
| 111 | + |
| 112 | +#endif // _LIBCPP___CHRONO_TIME_ZONE_TYPES_H |
0 commit comments