diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-05-20 22:09:55 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-05-20 22:10:44 +0200 |
| commit | da78a8adb2302b15f89d353fa6610385f0bf2a69 (patch) | |
| tree | 35b23b6d1433bd6db174f967bfb2541c5296140f | |
| parent | 4070e3f3b270a4a8c91d4cf2b7942b842c95ea3d (diff) | |
Add add_days to LocalTime.
| -rw-r--r-- | src/local_time.cc | 17 | ||||
| -rw-r--r-- | src/local_time.h | 1 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/local_time.cc b/src/local_time.cc index ed809d49..6a8579ff 100644 --- a/src/local_time.cc +++ b/src/local_time.cc @@ -217,6 +217,23 @@ LocalTime::time_of_day (bool with_second, bool with_millisecond) const return buffer; } + +void +LocalTime::add_days (int days) +{ + using namespace boost; + + gregorian::date d (_year, _month, _day); + if (days > 0) { + d += gregorian::days (days); + } else { + d -= gregorian::days (-days); + } + + set (posix_time::ptime(d, posix_time::time_duration(_hour, _minute, _second, _millisecond * 1000))); +} + + void LocalTime::add_months (int m) { diff --git a/src/local_time.h b/src/local_time.h index 310c598c..e818ba6e 100644 --- a/src/local_time.h +++ b/src/local_time.h @@ -83,6 +83,7 @@ public: _year = y; } + void add_days (int d); void add_months (int a); void add_minutes (int a); |
