summaryrefslogtreecommitdiff
path: root/src/local_time.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2019-12-23 01:05:49 +0100
committerCarl Hetherington <cth@carlh.net>2019-12-23 01:05:49 +0100
commit64e72c622be986c7272e938c2d3235c61abef402 (patch)
tree6cece3eee55fd26a79b2aa3c7e618f55258bcefc /src/local_time.cc
parent2b5af718d2a1f5da548303c8531afe86fa82d2d8 (diff)
Add struct tm constructor for LocalTime, use it to tidy up
day_{greater,less}_than_or_equal and add add_months() method.
Diffstat (limited to 'src/local_time.cc')
-rw-r--r--src/local_time.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/local_time.cc b/src/local_time.cc
index 5030500e..2aa55183 100644
--- a/src/local_time.cc
+++ b/src/local_time.cc
@@ -52,7 +52,17 @@ LocalTime::LocalTime ()
{
time_t now = time (0);
struct tm* tm = localtime (&now);
+ set (tm);
+}
+
+LocalTime::LocalTime (struct tm t)
+{
+ set (&t);
+}
+void
+LocalTime::set (struct tm const * tm)
+{
_year = tm->tm_year + 1900;
_month = tm->tm_mon + 1;
_day = tm->tm_mday;
@@ -208,6 +218,22 @@ LocalTime::time_of_day (bool with_second, bool with_millisecond) const
return buffer;
}
+void
+LocalTime::add_months (int m)
+{
+ _month += m;
+
+ while (_month < 0) {
+ _month += 12;
+ _year--;
+ }
+
+ while (_month > 11) {
+ _month -= 12;
+ _year++;
+ }
+}
+
bool
LocalTime::operator== (LocalTime const & other) const
{