fix operator< and operator== not working as expected

This commit is contained in:
Chris Danford
2004-07-20 07:11:26 +00:00
parent 0d4dde7dcd
commit 8d2d1ed3f7
2 changed files with 21 additions and 5 deletions
+11 -2
View File
@@ -16,9 +16,18 @@ void DateTime::Init()
DateTime DateTime::GetNowDateTime() DateTime DateTime::GetNowDateTime()
{ {
time_t now = time(NULL); time_t now = time(NULL);
DateTime tNow; tm tNow;
localtime_r( &now, &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() DateTime DateTime::GetNowDate()
+10 -3
View File
@@ -25,14 +25,21 @@ tm GetNextSunday( tm start );
tm GetDayInYearAndYear( int iDayInYearIndex, int iYear ); 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(); DateTime();
void Init(); void Init();
bool operator<( const DateTime& other ) const 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_year );
COMPARE( tm_mon ); COMPARE( tm_mon );
COMPARE( tm_mday ); COMPARE( tm_mday );
@@ -41,7 +48,7 @@ struct DateTime : public tm
COMPARE( tm_sec ); COMPARE( tm_sec );
#undef COMPARE #undef COMPARE
// they're equal // they're equal
return true; return false;
} }
bool operator==( const DateTime& other ) const bool operator==( const DateTime& other ) const
{ {