| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 10 |
// UNSUPPORTED: no-filesystem, no-localization, no-tzdb |
| 11 |
|
| 12 |
// XFAIL: libcpp-has-no-experimental-tzdb |
| 13 |
// XFAIL: availability-tzdb-missing |
| 14 |
|
| 15 |
// <chrono> |
| 16 |
|
| 17 |
// class time_zone; |
| 18 |
|
| 19 |
// template <class _Duration> |
| 20 |
// local_time<common_type_t<Duration, seconds>> |
| 21 |
// to_local(const sys_time<Duration>& tp) const; |
| 22 |
|
| 23 |
#include <chrono> |
| 24 |
#include <format> |
| 25 |
#include <cassert> |
| 26 |
#include <string_view> |
| 27 |
|
| 28 |
#include "test_macros.h" |
| 29 |
#include "assert_macros.h" |
| 30 |
#include "concat_macros.h" |
| 31 |
|
| 32 |
int main(int, char**) { |
| 33 |
// To make sure the test does not depend on changes in the database it uses a |
| 34 |
// time zone with a fixed offset. |
| 35 |
using namespace std::literals::chrono_literals; |
| 36 |
|
| 37 |
const std::chrono::time_zone* tz = std::chrono::locate_zone("Etc/GMT+1"); |
| 38 |
|
| 39 |
assert(tz->to_local(std::chrono::sys_time<std::chrono::nanoseconds>{-1ns}) == |
| 40 |
std::chrono::local_time<std::chrono::nanoseconds>{-1ns - 1h}); |
| 41 |
|
| 42 |
assert(tz->to_local(std::chrono::sys_time<std::chrono::microseconds>{0us}) == |
| 43 |
std::chrono::local_time<std::chrono::microseconds>{0us - 1h}); |
| 44 |
|
| 45 |
assert(tz->to_local( |
| 46 |
std::chrono::sys_time<std::chrono::seconds>{std::chrono::sys_days{std::chrono::January / 1 / -21970}}) == |
| 47 |
std::chrono::local_time<std::chrono::seconds>{ |
| 48 |
(std::chrono::sys_days{std::chrono::January / 1 / -21970}).time_since_epoch() - 1h}); |
| 49 |
|
| 50 |
assert( |
| 51 |
tz->to_local(std::chrono::sys_time<std::chrono::days>{std::chrono::sys_days{std::chrono::January / 1 / 21970}}) == |
| 52 |
std::chrono::local_time<std::chrono::seconds>{ |
| 53 |
(std::chrono::sys_days{std::chrono::January / 1 / 21970}).time_since_epoch() - 1h}); |
| 54 |
|
| 55 |
assert(tz->to_local(std::chrono::sys_time<std::chrono::weeks>{}) == |
| 56 |
std::chrono::local_time<std::chrono::seconds>{ |
| 57 |
(std::chrono::sys_days{std::chrono::January / 1 / 1970}).time_since_epoch() - 1h}); |
| 58 |
|
| 59 |
assert(tz->to_local(std::chrono::sys_time<std::chrono::months>{}) == |
| 60 |
std::chrono::local_time<std::chrono::seconds>{ |
| 61 |
(std::chrono::sys_days{std::chrono::January / 1 / 1970}).time_since_epoch() - 1h}); |
| 62 |
|
| 63 |
assert(tz->to_local(std::chrono::sys_time<std::chrono::years>{}) == |
| 64 |
std::chrono::local_time<std::chrono::seconds>{ |
| 65 |
(std::chrono::sys_days{std::chrono::January / 1 / 1970}).time_since_epoch() - 1h}); |
| 66 |
|
| 67 |
return 0; |
| 68 |
} |