Hi guys,
the addMonths and the addYears can lead to invalid date generation like:
"Tue Mar 29 2011" - 1 Month would become 29 February 2011 and that
is a not a valid date.
I reimplemented addMonths and addYears in term of boost::gregorian
date arithmetic, patch
is inline. I have also seen that WDate class has the members year_,
month_ and day_, you
can remove those and use the date::ymd_type (your choice).
Gaetano
diff --git a/src/Wt/WDate.C b/src/Wt/WDate.C
index 4788efe..79064d0 100644
--- a/src/Wt/WDate.C
+++ b/src/Wt/WDate.C
@@ -59,17 +59,10 @@ WDate WDate::addDays(int ndays) const
WDate WDate::addMonths(int nmonths) const
{
if (valid_) {
- int month = month_ + nmonths;
- div_t a = div(month - 1, 12);
- int year = year_ + a.quot;
- month = 1 + a.rem;
-
- if (month <= 0) {
- month += 12;
- year -= 1;
- }
+ date d(year_, month_, day_);
+ d += months(nmonths);
- return WDate(year, month, day_);
+ return WDate(d.year(), d.month(), d.day());
} else
return *this;
}
@@ -77,7 +70,10 @@ WDate WDate::addMonths(int nmonths) const
WDate WDate::addYears(int nyears) const
{
if (valid_) {
- return WDate(year_ + nyears, month_, day_);
+ date d(year_, month_, day_);
+ d += years(nyears);
+
+ return WDate(d.year(), d.month(), d.day());
} else
return *this;
}
--
cpp-today.blogspot.com
------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest