From 82ddf372f31608bbd9f94fe1902cb63f725c1fa6 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Mon, 4 Jul 2016 16:36:41 +0300 Subject: [PATCH] Don't use negative sum of seconds in the specified date range. --- source/Library/Chrono.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/source/Library/Chrono.cpp b/source/Library/Chrono.cpp index 50448bea..1e0cb1de 100644 --- a/source/Library/Chrono.cpp +++ b/source/Library/Chrono.cpp @@ -225,18 +225,14 @@ Int64 Chrono::DateRangeToSeconds(Uint16 _year, Uint8 _month, Uint8 _day, Uint16 // Are we within the same year? if (_year == year_) { - return (DayOfYear(_year, _month, _day) - DayOfYear(year_, month_, day_)) * 86400ULL; + return std::abs((DayOfYear(_year, _month, _day) - DayOfYear(year_, month_, day_)) * 86400ULL); } - // Should we negate the result when returning it? - bool neg = false; // Is the start year greater than the end year? - if (_year > year_) + else if (_year > year_) { std::swap(_year, year_); std::swap(_month, month_); std::swap(_day, day_); - // Negate the result - neg = true; } // Calculate the remaining days from the first year Int64 num = DaysInYear(_year) - DayOfYear(_year, _month, _day); @@ -250,7 +246,7 @@ Int64 Chrono::DateRangeToSeconds(Uint16 _year, Uint8 _month, Uint8 _day, Uint16 // Convert the obtained days in seconds num *= 86400ULL; // Return the result - return neg ? -num : num; + return std::abs(num); } // ------------------------------------------------------------------------------------------------