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:
parent
6613feb6ba
commit
805251a6db
@ -219,6 +219,40 @@ Date Chrono::ReverseDayOfyear(Uint16 year, Uint16 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()
|
||||
{
|
||||
|
@ -104,6 +104,11 @@ public:
|
||||
* Convert just the year and day of year to full date.
|
||||
*/
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user