summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2020-05-12 12:35:41 +0200
committerCarl Hetherington <cth@carlh.net>2020-05-12 13:12:48 +0200
commitd0ed9dd836b270d6bf75b302535de0f0f8f376e5 (patch)
treeedd68c3b5fd610f3252493614df9d0b5eee47b98 /src
parentc871f79f49087582c6ea7a42e79fd5fd3968bf00 (diff)
Add a proper implementation of add_months() and a test for the
case when it fails by giving erroneous dates like 30th February.
Diffstat (limited to 'src')
-rw-r--r--src/local_time.cc15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/local_time.cc b/src/local_time.cc
index 3a4b0cd9..1c174e50 100644
--- a/src/local_time.cc
+++ b/src/local_time.cc
@@ -220,17 +220,16 @@ LocalTime::time_of_day (bool with_second, bool with_millisecond) const
void
LocalTime::add_months (int m)
{
- _month += m;
+ using namespace boost;
- while (_month < 0) {
- _month += 12;
- _year--;
+ gregorian::date d (_year, _month, _day);
+ if (m > 0) {
+ d += gregorian::months (m);
+ } else {
+ d -= gregorian::months (-m);
}
- while (_month > 11) {
- _month -= 12;
- _year++;
- }
+ set (posix_time::ptime(d, posix_time::time_duration(_hour, _minute, _second, _millisecond * 1000)));
}
void