From 5e0fc1caab7e548d2ef25a79e34299df359e14f8 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Mon, 18 Jan 2021 02:18:09 -0500 Subject: [PATCH] Variant: Ensure implmentation of addition/subtraction of dates/durations does not involve casting Implicit casting of a duration anchors it around the 'now' point in time, which would throw off the conversion. --- src/Variant.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Variant.cpp b/src/Variant.cpp index c60b278eb..c37cd904a 100644 --- a/src/Variant.cpp +++ b/src/Variant.cpp @@ -1295,12 +1295,12 @@ Variant& Variant::operator-= (const Variant& other) case type_date: switch (right._type) { - case type_boolean: right.cast (type_integer); _date -= right._integer; break; - case type_integer: _date -= right._integer; break; - case type_real: _date -= (int) right._real; break; + case type_boolean: right.cast (type_integer); _date -= right._integer; break; + case type_integer: _date -= right._integer; break; + case type_real: _date -= (int) right._real; break; case type_string: throw std::string (STRING_VARIANT_SUB_STRING); - case type_date: cast (type_duration); _duration -= right._date; break; - case type_duration: _date -= right._duration; break; + case type_date: _type = Variant::type_duration; _duration = _date - right._date; break; + case type_duration: _date -= right._duration; break; } break; @@ -1408,12 +1408,12 @@ Variant& Variant::operator+= (const Variant& other) case type_duration: switch (right._type) { - case type_boolean: right.cast (type_duration); _duration += right._duration; break; - case type_integer: _duration += right._integer; break; - case type_real: _duration += (int) right._real; break; - case type_string: cast (type_string); _string += right._string; break; - case type_date: cast (type_date); _date += right._date; break; - case type_duration: _duration += right._duration; break; + case type_boolean: right.cast (type_duration); _duration += right._duration; break; + case type_integer: _duration += right._integer; break; + case type_real: _duration += (int) right._real; break; + case type_string: cast (type_string); _string += right._string; break; + case type_date: _type = Variant::type_date; _date += right._date + _duration; break; + case type_duration: _duration += right._duration; break; } break; }