knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::time Namespace Reference

Functions

TimePoint now ()
 
TimePoint fromSeconds (double seconds)
 
double toSeconds (const TimePoint &timestamp)
 
void write (const TimePoint &tp, std::ostream &os)
 

Function Documentation

◆ fromSeconds()

TimePoint knowrob::time::fromSeconds ( double  seconds)
Parameters
secondsthe number of seconds since the epoch.
Returns
the time point.

Definition at line 17 of file TimePoint.cpp.

17  {
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 }

◆ now()

TimePoint knowrob::time::now ( )
Returns
the current time point.

Definition at line 12 of file TimePoint.cpp.

12  {
14  return std::chrono::time_point_cast<std::chrono::seconds>(tp);
15 }
TimePoint now()
Definition: TimePoint.cpp:12

◆ toSeconds()

double knowrob::time::toSeconds ( const TimePoint timestamp)
Parameters
timestampthe time point.
Returns
the number of seconds since the epoch.

Definition at line 23 of file TimePoint.cpp.

23  {
24  auto time_t_value = std::chrono::system_clock::to_time_t(timestamp);
25  return static_cast<double>(time_t_value);
26 }
std::time_t to_time_t(TP tp)
Definition: DataSource.cpp:41

◆ write()

void knowrob::time::write ( const TimePoint tp,
std::ostream &  os 
)

Write a time point to an output stream.

Parameters
tpthe time point.
osthe output stream.

Definition at line 28 of file TimePoint.cpp.

28  {
29  os << time::toSeconds(tp);
30 }
double toSeconds(const TimePoint &timestamp)
Definition: TimePoint.cpp:23