[traffxml] Introduce timestamp shift operation

Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
mvglasow
2025-06-14 21:14:00 +03:00
parent e3d86be324
commit 0681171d69
2 changed files with 39 additions and 0 deletions

View File

@@ -153,6 +153,12 @@ IsoTime::IsoTime(std::chrono::time_point<std::chrono::utc_clock> tp)
bool IsoTime::IsPast()
{
return m_tp < std::chrono::utc_clock::now();
}\
void IsoTime::Shift(IsoTime nowRef)
{
auto const offset = std::chrono::utc_clock::now() - nowRef.m_tp;
m_tp += offset;
}
bool IsoTime::operator< (IsoTime & rhs)
@@ -256,6 +262,18 @@ std::optional<TrafficImpact> TraffMessage::GetTrafficImpact()
return std::nullopt;
}
void TraffMessage::ShiftTimestamps()
{
IsoTime nowRef = m_updateTime;
m_receiveTime.Shift(nowRef);
m_updateTime.Shift(nowRef);
m_expirationTime.Shift(nowRef);
if (m_startTime)
m_startTime.value().Shift(nowRef);
if (m_endTime)
m_endTime.value().Shift(nowRef);
}
void MergeMultiMwmColoring(MultiMwmColoring & delta, MultiMwmColoring & target)
{
// for each mwm in delta

View File

@@ -72,6 +72,17 @@ public:
*/
bool IsPast();
/**
* @brief Shifts time to the present.
*
* This method is intended for testing. It shifts the timestamp by a fixed amount, so that
* `nowRef` corresponds to current time. After this method returns, the timestamp will have the
* same offset from current time that it had from `nowRef` at the time the call was made.
*
* @param nowRef
*/
void Shift(IsoTime nowRef);
bool operator< (IsoTime & rhs);
bool operator> (IsoTime & rhs);
private:
@@ -362,6 +373,16 @@ struct TraffMessage
*/
std::optional<TrafficImpact> GetTrafficImpact();
/**
* @brief Shifts timestamps to the present.
*
* This method is intended for testing. It shifts the timestamps of the message by a fixed amount,
* so that `m_updateTime` corresponds to current time, and all other timestamps maintain their
* offset to `m_updateTime`. If `m_startTime` and/or `m_endTime` are set, they may be adjusted
* further to maintain their offset from midnight or the full hour (currently not implemented).
*/
void ShiftTimestamps();
std::string m_id;
IsoTime m_receiveTime = IsoTime::Now();
IsoTime m_updateTime = IsoTime::Now();