2 //===----------------------------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
10 // For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html
12 #ifndef _LIBCPP___CHRONO_TZDB_H
13 #define _LIBCPP___CHRONO_TZDB_H
16 // Enable the contents of the header only when libc++ was built with experimental features enabled.
17 #if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
19 # include <__algorithm/ranges_lower_bound.h>
20 # include <__chrono/leap_second.h>
21 # include <__chrono/time_zone.h>
22 # include <__chrono/time_zone_link.h>
24 # include <__memory/addressof.h>
25 # include <__vector/vector.h>
28 # include <string_view>
30 # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
31 # pragma GCC system_header
35 # include <__undef_macros>
37 _LIBCPP_BEGIN_NAMESPACE_STD
39 # if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
45 vector
<time_zone
> zones
;
46 vector
<time_zone_link
> links
;
48 vector
<leap_second
> leap_seconds
;
50 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
const time_zone
* __locate_zone(string_view __name
) const {
51 if (const time_zone
* __result
= __find_in_zone(__name
))
54 if (auto __it
= ranges::lower_bound(links
, __name
, {}, &time_zone_link::name
);
55 __it
!= links
.end() && __it
->name() == __name
)
56 if (const time_zone
* __result
= __find_in_zone(__it
->target()))
62 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
const time_zone
* locate_zone(string_view __name
) const {
63 if (const time_zone
* __result
= __locate_zone(__name
))
66 std::__throw_runtime_error("tzdb: requested time zone not found");
69 [[nodiscard
]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI
const time_zone
* current_zone() const {
70 return __current_zone();
74 _LIBCPP_HIDE_FROM_ABI
const time_zone
* __find_in_zone(string_view __name
) const noexcept
{
75 if (auto __it
= ranges::lower_bound(zones
, __name
, {}, &time_zone::name
);
76 __it
!= zones
.end() && __it
->name() == __name
)
77 return std::addressof(*__it
);
82 [[nodiscard
]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI
const time_zone
* __current_zone() const;
87 # endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM &&
88 // _LIBCPP_HAS_LOCALIZATION
90 _LIBCPP_END_NAMESPACE_STD
94 #endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
96 #endif // _LIBCPP___CHRONO_TZDB_H