1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-02-20 19:57:12 +01:00

Don't use negative sum of seconds in the specified date range.

This commit is contained in:
Sandu Liviu Catalin 2016-07-04 16:36:41 +03:00
parent 87ab54d453
commit 82ddf372f3

View File

@ -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);
}
// ------------------------------------------------------------------------------------------------