| 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 |
|
| 11 |
// UNSUPPORTED: availability-filesystem-missing |
| 12 |
|
| 13 |
// <chrono> |
| 14 |
// |
| 15 |
// file_clock |
| 16 |
// |
| 17 |
// template<class Duration> |
| 18 |
// static sys_time<see-below> to_sys(const file_time<Duration>&); |
| 19 |
// |
| 20 |
// template<class Duration> |
| 21 |
// static file_time<see-below> from_sys(const sys_time<Duration>&); |
| 22 |
|
| 23 |
#include <chrono> |
| 24 |
#include <cassert> |
| 25 |
|
| 26 |
int main(int, char**) { |
| 27 |
// Test round-trip through the system clock, starting from file_clock::now() |
| 28 |
{ |
| 29 |
std::chrono::file_clock::time_point const ft = std::chrono::file_clock::now(); |
| 30 |
auto st = std::chrono::file_clock::to_sys(ft); |
| 31 |
assert(ft == std::chrono::file_clock::from_sys(st)); |
| 32 |
} |
| 33 |
|
| 34 |
// Test round-trip through the system clock, starting from system_clock::now() |
| 35 |
{ |
| 36 |
std::chrono::system_clock::time_point const st = std::chrono::system_clock::now(); |
| 37 |
auto ft = std::chrono::file_clock::from_sys(st); |
| 38 |
assert(st == std::chrono::file_clock::to_sys(ft)); |
| 39 |
} |
| 40 |
|
| 41 |
// Make sure the value we get is in the ballpark of something reasonable |
| 42 |
{ |
| 43 |
std::chrono::file_clock::time_point const file_now = std::chrono::file_clock::now(); |
| 44 |
std::chrono::system_clock::time_point const sys_now = std::chrono::system_clock::now(); |
| 45 |
{ |
| 46 |
auto diff = sys_now - std::chrono::file_clock::to_sys(file_now); |
| 47 |
assert(std::chrono::milliseconds(-500) < diff && diff < std::chrono::milliseconds(500)); |
| 48 |
} |
| 49 |
{ |
| 50 |
auto diff = std::chrono::file_clock::from_sys(sys_now) - file_now; |
| 51 |
assert(std::chrono::milliseconds(-500) < diff && diff < std::chrono::milliseconds(500)); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
// Make sure to_sys and from_sys are consistent with each other |
| 56 |
{ |
| 57 |
std::chrono::file_clock::time_point const ft = std::chrono::file_clock::now(); |
| 58 |
std::chrono::system_clock::time_point const st = std::chrono::system_clock::now(); |
| 59 |
auto sys_diff = std::chrono::file_clock::to_sys(ft) - st; |
| 60 |
auto file_diff = ft - std::chrono::file_clock::from_sys(st); |
| 61 |
assert(sys_diff == file_diff); |
| 62 |
} |
| 63 |
|
| 64 |
return 0; |
| 65 |
} |