diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-03-10 17:17:45 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-03-10 17:17:45 +0100 |
| commit | a818ea7b22fc3c669dea70f4104ab5d9ed50b642 (patch) | |
| tree | bffbc738184c525564c751a5f039c19478c23af5 /src | |
| parent | d7e82f235998557e7529729d630762e309d1e654 (diff) | |
Add LocalTime::add_minutes.
Diffstat (limited to 'src')
| -rw-r--r-- | src/local_time.cc | 18 | ||||
| -rw-r--r-- | src/local_time.h | 8 |
2 files changed, 23 insertions, 3 deletions
diff --git a/src/local_time.cc b/src/local_time.cc index 2aa55183..f0eb42a3 100644 --- a/src/local_time.cc +++ b/src/local_time.cc @@ -39,7 +39,9 @@ #include "exceptions.h" #include "dcp_assert.h" #include <boost/lexical_cast.hpp> +#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/c_local_time_adjustor.hpp> +#include <boost/date_time/gregorian/gregorian.hpp> #include <cstdio> using std::string; @@ -79,6 +81,12 @@ LocalTime::set (struct tm const * tm) */ LocalTime::LocalTime (boost::posix_time::ptime t) { + set (t); +} + +void +LocalTime::set (boost::posix_time::ptime t) +{ _year = t.date().year (); _month = t.date().month (); _day = t.date().day (); @@ -234,6 +242,16 @@ LocalTime::add_months (int m) } } +void +LocalTime::add_minutes (int m) +{ + using namespace boost; + + posix_time::ptime t(gregorian::date(_year, _month, _day), posix_time::time_duration(_hour, _minute, _second)); + t += posix_time::time_duration(0, m, 0); + set (t); +} + bool LocalTime::operator== (LocalTime const & other) const { diff --git a/src/local_time.h b/src/local_time.h index 0b13985c..310c598c 100644 --- a/src/local_time.h +++ b/src/local_time.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2020 Carl Hetherington <cth@carlh.net> This file is part of libdcp. @@ -41,7 +41,7 @@ #include <boost/date_time/posix_time/posix_time.hpp> #include <string> -class local_time_test; +class local_time_basic_test; namespace dcp { @@ -84,15 +84,17 @@ public: } void add_months (int a); + void add_minutes (int a); bool operator== (LocalTime const & other) const; bool operator!= (LocalTime const & other) const; bool operator< (LocalTime const & other) const; private: - friend class ::local_time_test; + friend class ::local_time_basic_test; void set (struct tm const * tm); + void set (boost::posix_time::ptime); void set_local_time_zone (); /* Local time */ |
