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