-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc++][TZDB] Adds basics of zoned_time class.
This implements the class, its non-templated constructors and its getters to verify the construction. Completes - LWG3224 zoned_time constructor from TimeZonePtr does not specify initialization of tp_ Implements parts of: - P0355 Extending chrono to Calendars and Time Zones
- Loading branch information
Showing
16 changed files
with
830 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
36 changes: 36 additions & 0 deletions
36
libcxx/test/std/time/time.zone/time.zone.zonedtime/copy.assign.pass.cpp
This file contains 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,36 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// UNSUPPORTED: no-filesystem, no-localization, no-tzdb | ||
|
||
// XFAIL: libcpp-has-no-experimental-tzdb | ||
// XFAIL: availability-tzdb-missing | ||
|
||
// <chrono> | ||
|
||
// template<class Duration, class TimeZonePtr = const time_zone*> | ||
// class zoned_time; | ||
// | ||
// zoned_time& operator=(const zoned_time&) = default; | ||
|
||
#include <cassert> | ||
#include <chrono> | ||
|
||
int main(int, char**) { | ||
std::chrono::zoned_time<std::chrono::seconds> zt{std::chrono::sys_seconds{std::chrono::seconds{42}}}; | ||
assert(zt.get_time_zone() == std::chrono::locate_zone("UTC")); | ||
assert(zt.get_sys_time() == std::chrono::sys_seconds{std::chrono::seconds{42}}); | ||
|
||
std::chrono::zoned_time<std::chrono::seconds> copy; | ||
copy = zt; | ||
assert(copy.get_time_zone() == std::chrono::locate_zone("UTC")); | ||
assert(copy.get_sys_time() == std::chrono::sys_seconds{std::chrono::seconds{42}}); | ||
|
||
return 0; | ||
} |
43 changes: 43 additions & 0 deletions
43
libcxx/test/std/time/time.zone/time.zone.zonedtime/copy.ctor.pass.cpp
This file contains 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,43 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// UNSUPPORTED: no-filesystem, no-localization, no-tzdb | ||
|
||
// XFAIL: libcpp-has-no-experimental-tzdb | ||
// XFAIL: availability-tzdb-missing | ||
|
||
// <chrono> | ||
|
||
// template<class Duration, class TimeZonePtr = const time_zone*> | ||
// class zoned_time; | ||
// | ||
// zoned_time(const zoned_time&) = default; | ||
|
||
#include <cassert> | ||
#include <chrono> | ||
|
||
int main(int, char**) { | ||
std::chrono::zoned_time<std::chrono::seconds> zt{std::chrono::sys_seconds{std::chrono::seconds{42}}}; | ||
assert(zt.get_time_zone() == std::chrono::locate_zone("UTC")); | ||
assert(zt.get_sys_time() == std::chrono::sys_seconds{std::chrono::seconds{42}}); | ||
|
||
{ | ||
std::chrono::zoned_time<std::chrono::seconds> copy{zt}; | ||
assert(copy.get_time_zone() == std::chrono::locate_zone("UTC")); | ||
assert(copy.get_sys_time() == std::chrono::sys_seconds{std::chrono::seconds{42}}); | ||
} | ||
|
||
{ | ||
std::chrono::zoned_time<std::chrono::seconds> copy = zt; | ||
assert(copy.get_time_zone() == std::chrono::locate_zone("UTC")); | ||
assert(copy.get_sys_time() == std::chrono::sys_seconds{std::chrono::seconds{42}}); | ||
} | ||
|
||
return 0; | ||
} |
66 changes: 66 additions & 0 deletions
66
libcxx/test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/default.pass.cpp
This file contains 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,66 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// UNSUPPORTED: no-filesystem, no-localization, no-tzdb | ||
|
||
// XFAIL: libcpp-has-no-experimental-tzdb | ||
// XFAIL: availability-tzdb-missing | ||
|
||
// <chrono> | ||
|
||
// template<class Duration, class TimeZonePtr = const time_zone*> | ||
// class zoned_time; | ||
// | ||
// zoned_time(); | ||
|
||
#include <chrono> | ||
#include <concepts> | ||
#include <type_traits> | ||
|
||
#include "test_offset_time_zone.h" | ||
|
||
// Verify the results of the default constructed object, | ||
// and whether the constructor's constrains are satisfied. | ||
int main(int, char**) { | ||
{ | ||
static_assert(std::default_initializable<std::chrono::zoned_time<std::chrono::seconds>>); | ||
std::chrono::zoned_time<std::chrono::seconds> zt; | ||
assert(zt.get_time_zone() == std::chrono::locate_zone("UTC")); | ||
assert(zt.get_sys_time() == std::chrono::sys_seconds{}); | ||
} | ||
|
||
static_assert(!std::default_initializable< | ||
std::chrono::zoned_time<std::chrono::seconds, offset_time_zone<offset_time_zone_flags::none>>>); | ||
|
||
{ | ||
using type = offset_time_zone<offset_time_zone_flags::has_default_zone>; | ||
static_assert(std::default_initializable<std::chrono::zoned_time<std::chrono::seconds, type>>); | ||
|
||
std::chrono::zoned_time<std::chrono::seconds, type> zt; | ||
|
||
assert(zt.get_time_zone().offset() == std::chrono::seconds{0}); | ||
assert(zt.get_sys_time() == std::chrono::sys_seconds{}); | ||
} | ||
|
||
static_assert( | ||
!std::default_initializable< | ||
std::chrono::zoned_time<std::chrono::seconds, offset_time_zone<offset_time_zone_flags::has_locate_zone>>>); | ||
|
||
{ | ||
using type = offset_time_zone<offset_time_zone_flags::both>; | ||
static_assert(std::default_initializable<std::chrono::zoned_time<std::chrono::seconds, type>>); | ||
|
||
std::chrono::zoned_time<std::chrono::seconds, type> zt; | ||
|
||
assert(zt.get_time_zone().offset() == std::chrono::seconds{0}); | ||
assert(zt.get_sys_time() == std::chrono::sys_seconds{}); | ||
} | ||
|
||
return 0; | ||
} |
77 changes: 77 additions & 0 deletions
77
...test/std/time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/string_view.pass.cpp
This file contains 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,77 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// UNSUPPORTED: no-filesystem, no-localization, no-tzdb | ||
|
||
// XFAIL: libcpp-has-no-experimental-tzdb | ||
// XFAIL: availability-tzdb-missing | ||
|
||
// <chrono> | ||
|
||
// template<class Duration, class TimeZonePtr = const time_zone*> | ||
// class zoned_time; | ||
// | ||
// explicit zoned_time(string_view name); | ||
|
||
#include <chrono> | ||
#include <concepts> | ||
|
||
#include "test_offset_time_zone.h" | ||
|
||
// Verify the results of the constructed object. | ||
int main(int, char**) { | ||
{ | ||
using ptr = const std::chrono::time_zone*; | ||
static_assert(std::constructible_from<std::chrono::zoned_time<std::chrono::seconds, ptr>, std::string_view>); | ||
static_assert(!std::convertible_to<std::string_view, std::chrono::zoned_time<std::chrono::seconds, ptr>>); | ||
|
||
std::chrono::zoned_time<std::chrono::seconds> zt{"UTC"}; | ||
|
||
assert(zt.get_time_zone() == std::chrono::locate_zone("UTC")); | ||
assert(zt.get_sys_time() == std::chrono::sys_seconds{}); | ||
} | ||
|
||
{ | ||
using ptr = offset_time_zone<offset_time_zone_flags::none>; | ||
static_assert(!std::constructible_from<std::chrono::zoned_time<std::chrono::seconds, ptr>, std::string_view>); | ||
static_assert(!std::convertible_to<std::string_view, std::chrono::zoned_time<std::chrono::seconds, ptr>>); | ||
} | ||
|
||
{ | ||
using ptr = offset_time_zone<offset_time_zone_flags::has_default_zone>; | ||
static_assert(!std::constructible_from<std::chrono::zoned_time<std::chrono::seconds, ptr>, std::string_view>); | ||
static_assert(!std::convertible_to<std::string_view, std::chrono::zoned_time<std::chrono::seconds, ptr>>); | ||
} | ||
|
||
{ | ||
using ptr = offset_time_zone<offset_time_zone_flags::has_locate_zone>; | ||
static_assert(std::constructible_from<std::chrono::zoned_time<std::chrono::seconds, ptr>, std::string_view>); | ||
static_assert(!std::convertible_to<std::string_view, std::chrono::zoned_time<std::chrono::seconds, ptr>>); | ||
|
||
ptr tz; | ||
std::chrono::zoned_time<std::chrono::seconds, ptr> zt{"42"}; | ||
|
||
assert(zt.get_time_zone().offset() == std::chrono::seconds{42}); | ||
assert(zt.get_sys_time() == std::chrono::sys_seconds{}); | ||
} | ||
|
||
{ | ||
using ptr = offset_time_zone<offset_time_zone_flags::both>; | ||
static_assert(std::constructible_from<std::chrono::zoned_time<std::chrono::seconds, ptr>, std::string_view>); | ||
static_assert(!std::convertible_to<std::string_view, std::chrono::zoned_time<std::chrono::seconds, ptr>>); | ||
|
||
ptr tz; | ||
std::chrono::zoned_time<std::chrono::seconds, ptr> zt{"42"}; | ||
|
||
assert(zt.get_time_zone().offset() == std::chrono::seconds{42}); | ||
assert(zt.get_sys_time() == std::chrono::sys_seconds{}); | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.