-
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] Finishes zoned_time constructors.
Completes - LWG3225 zoned_time converting constructor shall not be noexcept - LWG3226 zoned_time constructor from string_view should accept zoned_time<Duration2, TimeZonePtr2> Implements parts of: - P0355 Extending to chrono Calendars and Time Zones
- Loading branch information
Showing
14 changed files
with
1,252 additions
and
7 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
74 changes: 74 additions & 0 deletions
74
...me/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/string_view_local_time.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,74 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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(string_view name, const local_time<Duration>& st); | ||
|
||
#include <chrono> | ||
#include <concepts> | ||
|
||
#include "../test_offset_time_zone.h" | ||
|
||
namespace cr = std::chrono; | ||
|
||
// Verify the results of the constructed object. | ||
int main(int, char**) { | ||
{ | ||
using ptr = const cr::time_zone*; | ||
static_assert(std::constructible_from<cr::zoned_time<cr::seconds, ptr>, std::string_view, cr::sys_seconds>); | ||
|
||
cr::zoned_time<cr::seconds> zt{"Etc/GMT+1", cr::local_seconds{cr::seconds{0}}}; | ||
|
||
assert(zt.get_time_zone() == cr::locate_zone("Etc/GMT+1")); | ||
assert(zt.get_sys_time() == cr::sys_seconds{cr::hours{1}}); | ||
} | ||
|
||
{ | ||
using ptr = offset_time_zone<offset_time_zone_flags::none>; | ||
static_assert(!std::constructible_from<cr::zoned_time<cr::seconds, ptr>, std::string_view, cr::local_seconds>); | ||
} | ||
|
||
{ | ||
using ptr = offset_time_zone<offset_time_zone_flags::has_default_zone>; | ||
static_assert(!std::constructible_from<cr::zoned_time<cr::seconds, ptr>, std::string_view, cr::local_seconds>); | ||
} | ||
|
||
{ | ||
using ptr = offset_time_zone<offset_time_zone_flags::has_locate_zone>; | ||
static_assert(std::constructible_from<cr::zoned_time<cr::seconds, ptr>, std::string_view, cr::local_seconds>); | ||
|
||
ptr tz; | ||
cr::zoned_time<cr::seconds, ptr> zt{"42", cr::local_seconds{cr::seconds{99}}}; | ||
|
||
assert(zt.get_time_zone().offset() == cr::seconds{42}); | ||
assert(zt.get_sys_time() == cr::sys_seconds{cr::seconds{141}}); | ||
} | ||
|
||
{ | ||
using ptr = offset_time_zone<offset_time_zone_flags::both>; | ||
static_assert(std::constructible_from<cr::zoned_time<cr::seconds, ptr>, std::string_view, cr::local_seconds>); | ||
|
||
ptr tz; | ||
cr::zoned_time<cr::seconds, ptr> zt{"42", cr::local_seconds{cr::seconds{99}}}; | ||
|
||
assert(zt.get_time_zone().offset() == cr::seconds{42}); | ||
assert(zt.get_sys_time() == cr::sys_seconds{cr::seconds{141}}); | ||
} | ||
|
||
return 0; | ||
} |
100 changes: 100 additions & 0 deletions
100
....zone/time.zone.zonedtime/time.zone.zonedtime.ctor/string_view_local_time_choose.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,100 @@ | ||
//===----------------------------------------------------------------------===/ | ||
// | ||
// 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(string_view name, const local_time<Duration>& st, choose c); | ||
|
||
#include <chrono> | ||
#include <concepts> | ||
#include <cassert> | ||
|
||
#include "../test_offset_time_zone.h" | ||
|
||
namespace cr = std::chrono; | ||
|
||
int main(int, char**) { | ||
// Tests unique conversions. To make sure the test does not depend on changes | ||
// in the database it uses a time zone with a fixed offset. | ||
{ | ||
cr::zoned_time<cr::seconds> zt{"Etc/GMT+1", cr::local_seconds{cr::seconds{0}}, cr::choose::earliest}; | ||
|
||
assert(zt.get_time_zone() == cr::locate_zone("Etc/GMT+1")); | ||
assert(zt.get_sys_time() == cr::sys_seconds{cr::hours{1}}); | ||
} | ||
|
||
// Tests ambiguous conversions. | ||
{ | ||
// Z Europe/Berlin 0:53:28 - LMT 1893 Ap | ||
// ... | ||
// 1 DE CE%sT 1980 | ||
// 1 E CE%sT | ||
// | ||
// ... | ||
// R E 1981 ma - Mar lastSu 1u 1 S | ||
// R E 1996 ma - O lastSu 1u 0 - | ||
|
||
using namespace std::literals::chrono_literals; | ||
{ | ||
cr::zoned_time<cr::seconds> zt{ | ||
"Europe/Berlin", | ||
cr::local_seconds{(cr::sys_days{cr::September / 28 / 1986} + 2h + 30min).time_since_epoch()}, | ||
cr::choose::earliest}; | ||
|
||
assert(zt.get_time_zone() == cr::locate_zone("Europe/Berlin")); | ||
assert(zt.get_sys_time() == cr::sys_days{cr::September / 28 / 1986} + 0h + 30min); | ||
} | ||
{ | ||
cr::zoned_time<cr::seconds> zt{ | ||
"Europe/Berlin", | ||
cr::local_seconds{(cr::sys_days{cr::September / 28 / 1986} + 2h + 30min).time_since_epoch()}, | ||
cr::choose::latest}; | ||
|
||
assert(zt.get_time_zone() == cr::locate_zone("Europe/Berlin")); | ||
assert(zt.get_sys_time() == cr::sys_days{cr::September / 28 / 1986} + 1h + 30min); | ||
} | ||
} | ||
|
||
static_assert(std::constructible_from<cr::zoned_time<cr::seconds, const cr::time_zone*>, | ||
std::string_view, | ||
cr::local_seconds, | ||
cr::choose>); | ||
|
||
static_assert(!std::constructible_from< cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::none>>, | ||
std::string_view, | ||
cr::local_seconds, | ||
cr::choose>); | ||
|
||
static_assert( | ||
!std::constructible_from< cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::has_default_zone>>, | ||
std::string_view, | ||
cr::local_seconds, | ||
cr::choose>); | ||
|
||
static_assert( | ||
!std::constructible_from< cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::has_locate_zone>>, | ||
std::string_view, | ||
cr::local_seconds, | ||
cr::choose>); | ||
|
||
static_assert(!std::constructible_from< cr::zoned_time<cr::seconds, offset_time_zone<offset_time_zone_flags::both>>, | ||
std::string_view, | ||
cr::local_seconds, | ||
cr::choose>); | ||
|
||
return 0; | ||
} |
74 changes: 74 additions & 0 deletions
74
...time/time.zone/time.zone.zonedtime/time.zone.zonedtime.ctor/string_view_sys_time.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,74 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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(string_view name, const sys_time<Duration>& st); | ||
|
||
#include <chrono> | ||
#include <concepts> | ||
|
||
#include "../test_offset_time_zone.h" | ||
|
||
namespace cr = std::chrono; | ||
|
||
// Verify the results of the constructed object. | ||
int main(int, char**) { | ||
{ | ||
using ptr = const cr::time_zone*; | ||
static_assert(std::constructible_from<cr::zoned_time<cr::seconds, ptr>, std::string_view, cr::sys_seconds>); | ||
|
||
cr::zoned_time<cr::seconds> zt{"UTC", cr::sys_seconds{cr::seconds{99}}}; | ||
|
||
assert(zt.get_time_zone() == cr::locate_zone("UTC")); | ||
assert(zt.get_sys_time() == cr::sys_seconds{cr::seconds{99}}); | ||
} | ||
|
||
{ | ||
using ptr = offset_time_zone<offset_time_zone_flags::none>; | ||
static_assert(!std::constructible_from<cr::zoned_time<cr::seconds, ptr>, std::string_view, cr::sys_seconds>); | ||
} | ||
|
||
{ | ||
using ptr = offset_time_zone<offset_time_zone_flags::has_default_zone>; | ||
static_assert(!std::constructible_from<cr::zoned_time<cr::seconds, ptr>, std::string_view, cr::sys_seconds>); | ||
} | ||
|
||
{ | ||
using ptr = offset_time_zone<offset_time_zone_flags::has_locate_zone>; | ||
static_assert(std::constructible_from<cr::zoned_time<cr::seconds, ptr>, std::string_view, cr::sys_seconds>); | ||
|
||
ptr tz; | ||
cr::zoned_time<cr::seconds, ptr> zt{"42", cr::sys_seconds{cr::seconds{99}}}; | ||
|
||
assert(zt.get_time_zone().offset() == cr::seconds{42}); | ||
assert(zt.get_sys_time() == cr::sys_seconds{cr::seconds{99}}); | ||
} | ||
|
||
{ | ||
using ptr = offset_time_zone<offset_time_zone_flags::both>; | ||
static_assert(std::constructible_from<cr::zoned_time<cr::seconds, ptr>, std::string_view, cr::sys_seconds>); | ||
|
||
ptr tz; | ||
cr::zoned_time<cr::seconds, ptr> zt{"42", cr::sys_seconds{cr::seconds{99}}}; | ||
|
||
assert(zt.get_time_zone().offset() == cr::seconds{42}); | ||
assert(zt.get_sys_time() == cr::sys_seconds{cr::seconds{99}}); | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.