Update of /cvsroot/pclasses/pclasses2/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11915/src
Modified Files:
Date.cpp
Log Message:
add operators +, -, +=, -=
Index: Date.cpp
===================================================================
RCS file: /cvsroot/pclasses/pclasses2/src/Date.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Date.cpp 27 Dec 2004 05:33:15 -0000 1.2
+++ Date.cpp 19 Jan 2005 16:25:17 -0000 1.3
@@ -171,6 +171,57 @@
return (!operator==(d));
}
+Date& Date::operator+=(const TimeSpan& sp) throw()
+{
+ int tmp = (int)_day + sp.days();
+ while ( tmp > daysInMonth(_month, _year) )
+ {
+ tmp -= daysInMonth(_month, _year);
+ if ( _month == 12 )
+ {
+ _month = 1;
+ ++_year;
+ }
+ else
+ ++_month;
+ }
+ _day = tmp;
+ return *this;
+}
+
+Date& Date::operator-=(const TimeSpan& sp) throw()
+{
+ int tmp = (int)_day - sp.days();
+ while ( tmp < 1 )
+ {
+ if ( _month == 1 )
+ {
+ _month = 12;
+ --_year;
+ }
+ else
+ --_month;
+
+ tmp += daysInMonth(_month, _year);
+ }
+ _day = tmp;
+ return *this;
+}
+
+Date operator+(const Date& d, const TimeSpan& sp) throw()
+{
+ Date ret = d;
+ ret += sp;
+ return ret;
+}
+
+Date operator-(const Date& d, const TimeSpan& sp) throw()
+{
+ Date ret = d;
+ ret -= sp;
+ return ret;
+}
+
std::ostream& operator << (std::ostream& os, const Date& d)
{
int oldw = os.width();
|