knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
TimeInterval.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 "knowrob/TimeInterval.h"
7 
8 using namespace knowrob;
9 
10 TimeInterval::TimeInterval(const std::optional<TimePoint> &since, const std::optional<TimePoint> &until)
11  : since_(since),
12  until_(until) {}
13 
14 bool TimeInterval::operator==(const TimeInterval &other) const {
15  return since_ == other.since_ && until_ == other.until_;
16 }
17 
19  static const TimeInterval timeInterval(std::nullopt, std::nullopt);
20  return timeInterval;
21 }
22 
25  return {now, now};
26 }
27 
29  return {begin, end};
30 }
31 
32 std::shared_ptr<TimeInterval> TimeInterval::intersectWith(const TimeInterval &other) const {
33  return std::make_shared<TimeInterval>(std::max(since_, other.since_), std::min(until_, other.until_));
34 }
35 
36 void TimeInterval::write(std::ostream &os) const {
37  os << '[';
38  if (since().has_value()) time::write(since().value(), os);
39  else os << '_';
40  os << ",";
41  if (until().has_value()) time::write(until().value(), os);
42  else os << '_';
43  os << ']';
44 }
std::optional< TimePoint > until_
Definition: TimeInterval.h:71
static TimeInterval during(const TimePoint &begin, const TimePoint &end)
std::shared_ptr< TimeInterval > intersectWith(const TimeInterval &other) const
bool operator==(const TimeInterval &other) const
std::optional< TimePoint > since_
Definition: TimeInterval.h:70
static const TimeInterval & anytime()
static TimeInterval currently()
TimeInterval(const std::optional< TimePoint > &since, const std::optional< TimePoint > &until)
void write(std::ostream &os) const override
const auto & since() const
Definition: TimeInterval.h:59
const auto & until() const
Definition: TimeInterval.h:64
void write(const TimePoint &tp, std::ostream &os)
Definition: TimePoint.cpp:28
TimePoint now()
Definition: TimePoint.cpp:12
std::chrono::time_point< std::chrono::system_clock, std::chrono::seconds > TimePoint
Definition: TimePoint.h:16