Add LocalTime::add_minutes.
[libdcp.git] / src / local_time.cc
index 2aa551836fdf2d8737b41956ee07d9c91410ba30..f0eb42a31b489d464d2a8b6cc03db5a13fc0bc87 100644 (file)
@@ -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;
@@ -78,6 +80,12 @@ LocalTime::set (struct tm const * tm)
  *  time zone.
  */
 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 ();
@@ -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
 {