From 7242accb5829361987f72cf1fe323c05ab474004 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sun, 17 Jan 2021 22:56:37 -0500 Subject: [PATCH] Variant: Convert durations into dates as implicitly anchored around now The _period attribute holds the number of seconds that the Duration holds, while _date attribute holds the number of seconds since the beginning of unix epoch (also known as epoch time). As such, it does not make sense to convert _period directly into _date. Interpret _period as offset relative to current unix epoch time. Closes #2390. --- src/Variant.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Variant.cpp b/src/Variant.cpp index 7f6f840d4..c60b278eb 100644 --- a/src/Variant.cpp +++ b/src/Variant.cpp @@ -1930,7 +1930,9 @@ void Variant::cast (const enum type new_type) case type_real: _real = static_cast(_date); break; case type_string: _string = (std::string) *this; break; case type_date: break; - case type_duration: _duration = _date; break; + // TODO: Not exactly correct (should duration convert into date?), but + // currently needed for symmetry, which is assumed by operators. + case type_duration: _duration = _date - time (nullptr); break; } break; @@ -1941,7 +1943,7 @@ void Variant::cast (const enum type new_type) case type_integer: _integer = (long long) _duration; break; case type_real: _real = static_cast(_duration); break; case type_string: _string = (std::string) *this; break; - case type_date: _date = _duration; break; + case type_date: _date = time (nullptr) + _duration; break; case type_duration: break; } break;