WPILibC++  2020.3.2
Chrono.h
1 //===- llvm/Support/Chrono.h - Utilities for Timing Manipulation-*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef WPIUTIL_WPI_CHRONO_H
11 #define WPIUTIL_WPI_CHRONO_H
12 
13 #include "wpi/Compiler.h"
14 
15 #include <chrono>
16 #include <ctime>
17 
18 namespace wpi {
19 
20 class raw_ostream;
21 
22 namespace sys {
23 
32 template <typename D = std::chrono::nanoseconds>
33 using TimePoint = std::chrono::time_point<std::chrono::system_clock, D>;
34 
36 LLVM_ATTRIBUTE_ALWAYS_INLINE std::time_t toTimeT(TimePoint<> TP) {
37  using namespace std::chrono;
38  return system_clock::to_time_t(
39  time_point_cast<system_clock::time_point::duration>(TP));
40 }
41 
43 LLVM_ATTRIBUTE_ALWAYS_INLINE TimePoint<std::chrono::seconds>
44 toTimePoint(std::time_t T) {
45  using namespace std::chrono;
46  return time_point_cast<seconds>(system_clock::from_time_t(T));
47 }
48 
50 LLVM_ATTRIBUTE_ALWAYS_INLINE TimePoint<>
51 toTimePoint(std::time_t T, uint32_t nsec) {
52  using namespace std::chrono;
53  return time_point_cast<nanoseconds>(system_clock::from_time_t(T))
54  + nanoseconds(nsec);
55 }
56 
57 } // namespace sys
58 
59 raw_ostream &operator<<(raw_ostream &OS, sys::TimePoint<> TP);
60 
61 } // namespace wpi
62 
63 #endif // WPIUTIL_WPI_CHRONO_H
wpi
WPILib C++ utilities (wpiutil) namespace.
Definition: EventLoopRunner.h:17
wpi::operator<<
raw_ostream & operator<<(raw_ostream &Out, const VersionTuple &V)
Print a version number.