-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[libc++][TZDB] Implements time_zone::to_sys. #90394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// -*- C++ -*- | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html | ||
|
||
#ifndef _LIBCPP___CHRONO_EXCEPTION_H | ||
#define _LIBCPP___CHRONO_EXCEPTION_H | ||
|
||
#include <version> | ||
// Enable the contents of the header only when libc++ was built with experimental features enabled. | ||
#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) | ||
|
||
# include <__chrono/calendar.h> | ||
# include <__chrono/local_info.h> | ||
# include <__chrono/time_point.h> | ||
# include <__config> | ||
# include <__configuration/availability.h> | ||
# include <__verbose_abort> | ||
# include <format> | ||
# include <stdexcept> | ||
# include <string> | ||
|
||
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
# endif | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
# if _LIBCPP_STD_VER >= 20 | ||
|
||
namespace chrono { | ||
|
||
class nonexistent_local_time : public runtime_error { | ||
public: | ||
template <class _Duration> | ||
_LIBCPP_HIDE_FROM_ABI nonexistent_local_time(const local_time<_Duration>& __time, const local_info& __info) | ||
: runtime_error{__create_message(__time, __info)} { | ||
// [time.zone.exception.nonexist]/2 | ||
// Preconditions: i.result == local_info::nonexistent is true. | ||
// The value of __info.result is not used. | ||
_LIBCPP_ASSERT_PEDANTIC(__info.result == local_info::nonexistent, | ||
"creating an nonexistent_local_time from a local_info that is not non-existent"); | ||
} | ||
|
||
_LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI ~nonexistent_local_time() override; // exported as key function | ||
|
||
private: | ||
template <class _Duration> | ||
_LIBCPP_HIDE_FROM_ABI string __create_message(const local_time<_Duration>& __time, const local_info& __info) { | ||
return std::format( | ||
R"({} is in a gap between | ||
{} {} and | ||
{} {} which are both equivalent to | ||
{} UTC)", | ||
__time, | ||
local_seconds{__info.first.end.time_since_epoch()} + __info.first.offset, | ||
__info.first.abbrev, | ||
local_seconds{__info.second.begin.time_since_epoch()} + __info.second.offset, | ||
__info.second.abbrev, | ||
__info.first.end); | ||
} | ||
}; | ||
|
||
template <class _Duration> | ||
_LIBCPP_NORETURN _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_nonexistent_local_time( | ||
[[maybe_unused]] const local_time<_Duration>& __time, [[maybe_unused]] const local_info& __info) { | ||
# ifndef _LIBCPP_HAS_NO_EXCEPTIONS | ||
throw nonexistent_local_time(__time, __info); | ||
# else | ||
_LIBCPP_VERBOSE_ABORT("nonexistent_local_time was thrown in -fno-exceptions mode"); | ||
# endif | ||
} | ||
|
||
class ambiguous_local_time : public runtime_error { | ||
public: | ||
template <class _Duration> | ||
_LIBCPP_HIDE_FROM_ABI ambiguous_local_time(const local_time<_Duration>& __time, const local_info& __info) | ||
: runtime_error{__create_message(__time, __info)} { | ||
// [time.zone.exception.ambig]/2 | ||
// Preconditions: i.result == local_info::ambiguous is true. | ||
// The value of __info.result is not used. | ||
_LIBCPP_ASSERT_PEDANTIC(__info.result == local_info::ambiguous, | ||
"creating an ambiguous_local_time from a local_info that is not ambiguous"); | ||
} | ||
|
||
_LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI ~ambiguous_local_time() override; // exported as key function | ||
|
||
private: | ||
template <class _Duration> | ||
_LIBCPP_HIDE_FROM_ABI string __create_message(const local_time<_Duration>& __time, const local_info& __info) { | ||
return std::format( | ||
// There are two spaces after the full-stop; this has been verified | ||
// in the sources of the Standard. | ||
R"({0} is ambiguous. It could be | ||
{0} {1} == {2} UTC or | ||
{0} {3} == {4} UTC)", | ||
__time, | ||
__info.first.abbrev, | ||
__time - __info.first.offset, | ||
__info.second.abbrev, | ||
__time - __info.second.offset); | ||
} | ||
}; | ||
|
||
template <class _Duration> | ||
_LIBCPP_NORETURN _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_ambiguous_local_time( | ||
[[maybe_unused]] const local_time<_Duration>& __time, [[maybe_unused]] const local_info& __info) { | ||
# ifndef _LIBCPP_HAS_NO_EXCEPTIONS | ||
throw ambiguous_local_time(__time, __info); | ||
# else | ||
_LIBCPP_VERBOSE_ABORT("ambiguous_local_time was thrown in -fno-exceptions mode"); | ||
# endif | ||
} | ||
|
||
} // namespace chrono | ||
|
||
# endif // _LIBCPP_STD_VER >= 20 | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) | ||
|
||
#endif // _LIBCPP___CHRONO_EXCEPTION_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <chrono> | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
namespace chrono { | ||
|
||
_LIBCPP_AVAILABILITY_TZDB | ||
_LIBCPP_EXPORTED_FROM_ABI nonexistent_local_time::~nonexistent_local_time() = default; // key function | ||
_LIBCPP_AVAILABILITY_TZDB | ||
_LIBCPP_EXPORTED_FROM_ABI ambiguous_local_time::~ambiguous_local_time() = default; // key function | ||
|
||
} // namespace chrono | ||
|
||
_LIBCPP_END_NAMESPACE_STD |
53 changes: 53 additions & 0 deletions
53
.../libcxx/time/time.zone/time.zone.exception/time.zone.exception.ambig/assert.ctor.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
|
||
// REQUIRES: has-unix-headers | ||
// REQUIRES: libcpp-hardening-mode={{extensive|debug}} | ||
// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing | ||
|
||
// XFAIL: libcpp-has-no-experimental-tzdb | ||
|
||
// <chrono> | ||
|
||
// class ambiguous_local_time | ||
// | ||
// template<class Duration> | ||
// ambiguous_local_time(const local_time<Duration>& tp, const local_info& i); | ||
|
||
#include <chrono> | ||
|
||
#include "check_assertion.h" | ||
|
||
// [time.zone.exception.ambig]/2 | ||
// Preconditions: i.result == local_info::ambiguous is true. | ||
int main(int, char**) { | ||
TEST_LIBCPP_ASSERT_FAILURE( | ||
(std::chrono::ambiguous_local_time{ | ||
std::chrono::local_seconds{}, | ||
std::chrono::local_info{-1, // this is not one of the "named" result values | ||
std::chrono::sys_info{}, | ||
std::chrono::sys_info{}}}), | ||
"creating an ambiguous_local_time from a local_info that is not ambiguous"); | ||
|
||
TEST_LIBCPP_ASSERT_FAILURE( | ||
(std::chrono::ambiguous_local_time{ | ||
std::chrono::local_seconds{}, | ||
std::chrono::local_info{std::chrono::local_info::unique, std::chrono::sys_info{}, std::chrono::sys_info{}}}), | ||
"creating an ambiguous_local_time from a local_info that is not ambiguous"); | ||
|
||
TEST_LIBCPP_ASSERT_FAILURE( | ||
(std::chrono::ambiguous_local_time{ | ||
std::chrono::local_seconds{}, | ||
std::chrono::local_info{ | ||
std::chrono::local_info::nonexistent, std::chrono::sys_info{}, std::chrono::sys_info{}}}), | ||
"creating an ambiguous_local_time from a local_info that is not ambiguous"); | ||
|
||
return 0; | ||
} |
53 changes: 53 additions & 0 deletions
53
...bcxx/time/time.zone/time.zone.exception/time.zone.exception.nonexist/assert.ctor.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
|
||
// REQUIRES: has-unix-headers | ||
// REQUIRES: libcpp-hardening-mode={{extensive|debug}} | ||
// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing | ||
|
||
// XFAIL: libcpp-has-no-experimental-tzdb | ||
|
||
// <chrono> | ||
|
||
// class nonexistent_local_time | ||
// | ||
// template<class Duration> | ||
// nonexistent_local_time(const local_time<Duration>& tp, const local_info& i); | ||
|
||
#include <chrono> | ||
|
||
#include "check_assertion.h" | ||
|
||
// [time.zone.exception.nonexist]/2 | ||
// Preconditions: i.result == local_info::nonexistent is true. | ||
int main(int, char**) { | ||
TEST_LIBCPP_ASSERT_FAILURE( | ||
(std::chrono::nonexistent_local_time{ | ||
std::chrono::local_seconds{}, | ||
std::chrono::local_info{-1, // this is not one of the "named" result values | ||
std::chrono::sys_info{}, | ||
std::chrono::sys_info{}}}), | ||
"creating an nonexistent_local_time from a local_info that is not non-existent"); | ||
|
||
TEST_LIBCPP_ASSERT_FAILURE( | ||
(std::chrono::nonexistent_local_time{ | ||
std::chrono::local_seconds{}, | ||
std::chrono::local_info{std::chrono::local_info::unique, std::chrono::sys_info{}, std::chrono::sys_info{}}}), | ||
"creating an nonexistent_local_time from a local_info that is not non-existent"); | ||
|
||
TEST_LIBCPP_ASSERT_FAILURE( | ||
(std::chrono::nonexistent_local_time{ | ||
std::chrono::local_seconds{}, | ||
std::chrono::local_info{ | ||
std::chrono::local_info::ambiguous, std::chrono::sys_info{}, std::chrono::sys_info{}}}), | ||
"creating an nonexistent_local_time from a local_info that is not non-existent"); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.