Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:15

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 // For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html
0011 
0012 #ifndef _LIBCPP___CHRONO_TZDB_H
0013 #define _LIBCPP___CHRONO_TZDB_H
0014 
0015 #include <version>
0016 // Enable the contents of the header only when libc++ was built with experimental features enabled.
0017 #if _LIBCPP_HAS_EXPERIMENTAL_TZDB
0018 
0019 #  include <__algorithm/ranges_lower_bound.h>
0020 #  include <__chrono/leap_second.h>
0021 #  include <__chrono/time_zone.h>
0022 #  include <__chrono/time_zone_link.h>
0023 #  include <__config>
0024 #  include <__memory/addressof.h>
0025 #  include <__vector/vector.h>
0026 #  include <stdexcept>
0027 #  include <string>
0028 #  include <string_view>
0029 
0030 #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0031 #    pragma GCC system_header
0032 #  endif
0033 
0034 _LIBCPP_PUSH_MACROS
0035 #  include <__undef_macros>
0036 
0037 _LIBCPP_BEGIN_NAMESPACE_STD
0038 
0039 #  if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
0040 
0041 namespace chrono {
0042 
0043 struct tzdb {
0044   string version;
0045   vector<time_zone> zones;
0046   vector<time_zone_link> links;
0047 
0048   vector<leap_second> leap_seconds;
0049 
0050   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const time_zone* __locate_zone(string_view __name) const {
0051     if (const time_zone* __result = __find_in_zone(__name))
0052       return __result;
0053 
0054     if (auto __it = ranges::lower_bound(links, __name, {}, &time_zone_link::name);
0055         __it != links.end() && __it->name() == __name)
0056       if (const time_zone* __result = __find_in_zone(__it->target()))
0057         return __result;
0058 
0059     return nullptr;
0060   }
0061 
0062   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const time_zone* locate_zone(string_view __name) const {
0063     if (const time_zone* __result = __locate_zone(__name))
0064       return __result;
0065 
0066     std::__throw_runtime_error("tzdb: requested time zone not found");
0067   }
0068 
0069   [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI const time_zone* current_zone() const {
0070     return __current_zone();
0071   }
0072 
0073 private:
0074   _LIBCPP_HIDE_FROM_ABI const time_zone* __find_in_zone(string_view __name) const noexcept {
0075     if (auto __it = ranges::lower_bound(zones, __name, {}, &time_zone::name);
0076         __it != zones.end() && __it->name() == __name)
0077       return std::addressof(*__it);
0078 
0079     return nullptr;
0080   }
0081 
0082   [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI const time_zone* __current_zone() const;
0083 };
0084 
0085 } // namespace chrono
0086 
0087 #  endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM &&
0088          // _LIBCPP_HAS_LOCALIZATION
0089 
0090 _LIBCPP_END_NAMESPACE_STD
0091 
0092 _LIBCPP_POP_MACROS
0093 
0094 #endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
0095 
0096 #endif // _LIBCPP___CHRONO_TZDB_H