Date::Compare

git-svn-id: svn://ultimatepp.org/upp/trunk@597 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2008-11-03 20:06:57 +00:00
parent 30574be501
commit 284f3e26cb
2 changed files with 11 additions and 5 deletions

View file

@ -230,12 +230,16 @@ void Date::Set(int d) {
day = d + 1;
}
int Date::Compare(Date b) const
{
int q = SgnCompare(year, b.year);
if(q) return q;
q = SgnCompare(month, b.month);
return q ? q : SgnCompare(day, b.day);
}
bool operator<(Date a, Date b) {
if(a.year < b.year) return true;
if(a.year > b.year) return false;
if(a.month < b.month) return true;
if(a.month > b.month) return false;
return a.day < b.day;
return a.Compare(b) < 0;
}
int operator-(Date a, Date b) { return a.Get() - b.Get(); }

View file

@ -15,6 +15,8 @@ struct Date : RelOps< Date, Moveable<Date> > {
static Date Low() { return Date(-4000, 1, 1); }
static Date High() { return Date(4000, 1, 1); }
int Compare(Date b) const;
Date() { year = -32768; day = month = 0; }
Date(const Nuller&) { year = -32768; day = month = 0; }