From 136293c308ac4ee826e247e824dbeb753632091e Mon Sep 17 00:00:00 2001 From: mvglasow Date: Fri, 16 May 2025 17:48:29 +0300 Subject: [PATCH] [traffic] Add IsoTime::IsPast() Signed-off-by: mvglasow --- traffxml/traff_model.cpp | 6 ++++++ traffxml/traff_model.hpp | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/traffxml/traff_model.cpp b/traffxml/traff_model.cpp index 7479f713f..ec981e489 100644 --- a/traffxml/traff_model.cpp +++ b/traffxml/traff_model.cpp @@ -138,6 +138,12 @@ IsoTime::IsoTime(std::tm tm) : m_tm(tm) {} +bool IsoTime::IsPast() +{ + std::time_t t_now = std::time(nullptr); + std::time_t t_tm = timegm(&m_tm); + return t_tm < t_now; +} bool operator< (IsoTime lhs, IsoTime rhs) { diff --git a/traffxml/traff_model.hpp b/traffxml/traff_model.hpp index 221b0c500..0ab998e94 100644 --- a/traffxml/traff_model.hpp +++ b/traffxml/traff_model.hpp @@ -65,6 +65,15 @@ public: */ static IsoTime Now(); + /** + * @brief Whether the instance refers to a point of time in the past. + * + * Comparison is against system time. + * + * @return true if in the past, false of not. + */ + bool IsPast(); + friend bool operator< (IsoTime lhs, IsoTime rhs); friend bool operator> (IsoTime lhs, IsoTime rhs); private: