[lld][WebAssembly] Introduce Ctx::arg
[llvm-project.git] / libcxx / test / std / time / time.clock / time.clock.file / to_from_sys.pass.cpp
blob5b1f4659911118fe6405eaaddc20c099fc507f85
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // UNSUPPORTED: availability-filesystem-missing
13 // <chrono>
15 // file_clock
17 // template<class Duration>
18 // static sys_time<see-below> to_sys(const file_time<Duration>&);
20 // template<class Duration>
21 // static file_time<see-below> from_sys(const sys_time<Duration>&);
23 #include <chrono>
24 #include <cassert>
26 int main(int, char**) {
27 // Test round-trip through the system clock, starting from file_clock::now()
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));
34 // Test round-trip through the system clock, starting from system_clock::now()
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));
41 // Make sure the value we get is in the ballpark of something reasonable
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();
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));
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));
55 // Make sure to_sys and from_sys are consistent with each other
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);
64 return 0;