add a Date::CompareDate(...) and Date::CompareTime(...) methods

This commit is contained in:
Tomasz Sowa 2023-09-07 04:41:41 +02:00
parent 09215ef5f2
commit e94589d6b5
Signed by: tomasz.sowa
GPG Key ID: 662CC1438638588B
2 changed files with 28 additions and 5 deletions

View File

@ -241,9 +241,9 @@ bool Date::operator!=(const Date & d) const
}
int Date::Compare(const Date & d) const
int Date::CompareDate(const Date & d, bool ignore_year) const
{
if( year != d.year )
if( !ignore_year && year != d.year )
return year - d.year;
if( month != d.month )
@ -252,6 +252,13 @@ int Date::Compare(const Date & d) const
if( day != d.day )
return day - d.day;
// dates are equal
return 0;
}
int Date::CompareTime(const Date & d) const
{
if( hour != d.hour )
return hour - d.hour;
@ -261,11 +268,24 @@ int Date::Compare(const Date & d) const
if( sec != d.sec )
return sec - d.sec;
// dates are equal
// times are equal
return 0;
}
int Date::Compare(const Date & d, bool ignore_year) const
{
int res = CompareDate(d, ignore_year);
if( res == 0 )
{
res = CompareTime(d);
}
return res;
}
bool Date::operator>(const Date & d) const
{
return Compare(d) > 0;

View File

@ -161,12 +161,15 @@ public:
time_t operator-(const Date & d) const;
/*
'Compare' returns zero if this and d are equal
'Compare' methods returns zero if this and d are equal
return value less than zero if this is lower than d
and a value greater than zero if this is greater than d
*/
int Compare(const Date & d) const;
int CompareDate(const Date & d, bool ignore_year = false) const;
int CompareTime(const Date & d) const;
int Compare(const Date & d, bool ignore_year = false) const;
/*