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