diff options
Diffstat (limited to 'src/local_time.cc')
| -rw-r--r-- | src/local_time.cc | 26 |
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 { |
