time_zone.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. // For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html
  10. #ifndef _LIBCPP___CHRONO_TIME_ZONE_H
  11. #define _LIBCPP___CHRONO_TIME_ZONE_H
  12. #include <version>
  13. // Enable the contents of the header only when libc++ was built with experimental features enabled.
  14. #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
  15. # include <__compare/strong_order.h>
  16. # include <__config>
  17. # include <__memory/unique_ptr.h>
  18. # include <string_view>
  19. # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  20. # pragma GCC system_header
  21. # endif
  22. _LIBCPP_PUSH_MACROS
  23. # include <__undef_macros>
  24. _LIBCPP_BEGIN_NAMESPACE_STD
  25. # if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
  26. !defined(_LIBCPP_HAS_NO_LOCALIZATION)
  27. namespace chrono {
  28. class _LIBCPP_AVAILABILITY_TZDB time_zone {
  29. _LIBCPP_HIDE_FROM_ABI time_zone() = default;
  30. public:
  31. class __impl; // public so it can be used by make_unique.
  32. // The "constructor".
  33. //
  34. // The default constructor is private to avoid the constructor from being
  35. // part of the ABI. Instead use an __ugly_named function as an ABI interface,
  36. // since that gives us the ability to change it in the future.
  37. [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI static time_zone __create(unique_ptr<__impl>&& __p);
  38. _LIBCPP_EXPORTED_FROM_ABI ~time_zone();
  39. _LIBCPP_HIDE_FROM_ABI time_zone(time_zone&&) = default;
  40. _LIBCPP_HIDE_FROM_ABI time_zone& operator=(time_zone&&) = default;
  41. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI string_view name() const noexcept { return __name(); }
  42. [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const __impl& __implementation() const noexcept { return *__impl_; }
  43. private:
  44. [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI string_view __name() const noexcept;
  45. unique_ptr<__impl> __impl_;
  46. };
  47. _LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline bool
  48. operator==(const time_zone& __x, const time_zone& __y) noexcept {
  49. return __x.name() == __y.name();
  50. }
  51. _LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline strong_ordering
  52. operator<=>(const time_zone& __x, const time_zone& __y) noexcept {
  53. return __x.name() <=> __y.name();
  54. }
  55. } // namespace chrono
  56. # endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
  57. // && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
  58. _LIBCPP_END_NAMESPACE_STD
  59. _LIBCPP_POP_MACROS
  60. #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
  61. #endif // _LIBCPP___CHRONO_TIME_ZONE_H