knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
TimePoint.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of KnowRob, please consult
3  * https://github.com/knowrob/knowrob for license details.
4  */
5 
6 #include <chrono>
7 #include <cmath>
8 #include "knowrob/TimePoint.h"
9 
10 using namespace knowrob;
11 
14  return std::chrono::time_point_cast<std::chrono::seconds>(tp);
15 }
16 
17 TimePoint time::fromSeconds(double seconds) {
18  auto tp =
19  std::chrono::system_clock::from_time_t(static_cast<time_t>(seconds));
20  return std::chrono::time_point_cast<std::chrono::seconds>(tp);
21 }
22 
23 double time::toSeconds(const TimePoint &timestamp) {
24  auto time_t_value = std::chrono::system_clock::to_time_t(timestamp);
25  return static_cast<double>(time_t_value);
26 }
27 
28 void time::write(const TimePoint &tp, std::ostream &os) {
29  os << time::toSeconds(tp);
30 }
std::time_t to_time_t(TP tp)
Definition: DataSource.cpp:41
double toSeconds(const TimePoint &timestamp)
Definition: TimePoint.cpp:23
void write(const TimePoint &tp, std::ostream &os)
Definition: TimePoint.cpp:28
TimePoint fromSeconds(double seconds)
Definition: TimePoint.cpp:17
TimePoint now()
Definition: TimePoint.cpp:12
std::chrono::time_point< std::chrono::system_clock, std::chrono::seconds > TimePoint
Definition: TimePoint.h:16