fix operator< and operator== not working as expected
This commit is contained in:
@@ -16,9 +16,18 @@ void DateTime::Init()
|
||||
DateTime DateTime::GetNowDateTime()
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
DateTime tNow;
|
||||
tm tNow;
|
||||
localtime_r( &now, &tNow );
|
||||
return tNow;
|
||||
DateTime dtNow;
|
||||
#define COPY_M( v ) dtNow.v = tNow.v;
|
||||
COPY_M( tm_year );
|
||||
COPY_M( tm_mon );
|
||||
COPY_M( tm_mday );
|
||||
COPY_M( tm_hour );
|
||||
COPY_M( tm_min );
|
||||
COPY_M( tm_sec );
|
||||
#undef COPY_M
|
||||
return dtNow;
|
||||
}
|
||||
|
||||
DateTime DateTime::GetNowDate()
|
||||
|
||||
@@ -25,14 +25,21 @@ tm GetNextSunday( tm start );
|
||||
tm GetDayInYearAndYear( int iDayInYearIndex, int iYear );
|
||||
|
||||
|
||||
struct DateTime : public tm
|
||||
struct DateTime
|
||||
{
|
||||
int tm_sec; /* seconds after the minute - [0,59] */
|
||||
int tm_min; /* minutes after the hour - [0,59] */
|
||||
int tm_hour; /* hours since midnight - [0,23] */
|
||||
int tm_mday; /* day of the month - [1,31] */
|
||||
int tm_mon; /* months since January - [0,11] */
|
||||
int tm_year; /* years since 1900 */
|
||||
|
||||
DateTime();
|
||||
void Init();
|
||||
|
||||
bool operator<( const DateTime& other ) const
|
||||
{
|
||||
#define COMPARE( v ) if(v!=other.v) return v<other.v;
|
||||
#define COMPARE( v ) if(v<other.v) return true; if(v>other.v) return false;
|
||||
COMPARE( tm_year );
|
||||
COMPARE( tm_mon );
|
||||
COMPARE( tm_mday );
|
||||
@@ -41,7 +48,7 @@ struct DateTime : public tm
|
||||
COMPARE( tm_sec );
|
||||
#undef COMPARE
|
||||
// they're equal
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
bool operator==( const DateTime& other ) const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user