1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-02-21 20:27:13 +01:00

Add utility to calculate date range in seconds on Chrono library.

This commit is contained in:
Sandu Liviu Catalin 2016-07-04 16:23:35 +03:00
parent 6613feb6ba
commit 805251a6db
2 changed files with 39 additions and 0 deletions

View File

@ -219,6 +219,40 @@ Date Chrono::ReverseDayOfyear(Uint16 year, Uint16 doy)
return Date(year, month, doy); return Date(year, month, doy);
} }
// ------------------------------------------------------------------------------------------------
Int64 Chrono::DateRangeToSeconds(Uint16 _year, Uint8 _month, Uint8 _day, Uint16 year_, Uint8 month_, Uint8 day_)
{
// Are we within the same year?
if (_year == year_)
{
return (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_)
{
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);
// Calculate the days withing the years range
while (++_year < year_)
{
num += DaysInYear(_year);
}
// Calculate the days up to the last day
num += DayOfYear(year_, month_, day_);
// Convert the obtained days in seconds
num *= 86400ULL;
// Return the result
return neg ? -num : num;
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
static SLongInt SqGetEpochTimeMicro() static SLongInt SqGetEpochTimeMicro()
{ {

View File

@ -104,6 +104,11 @@ public:
* Convert just the year and day of year to full date. * Convert just the year and day of year to full date.
*/ */
static Date ReverseDayOfyear(Uint16 year, Uint16 doy); static Date ReverseDayOfyear(Uint16 year, Uint16 doy);
/* --------------------------------------------------------------------------------------------
* Calculate the number of days in the specified date range.
*/
static Int64 DateRangeToSeconds(Uint16 _year, Uint8 _month, Uint8 _day, Uint16 year_, Uint8 month_, Uint8 day_);
}; };
} // Namespace:: SqMod } // Namespace:: SqMod