From a818ea7b22fc3c669dea70f4104ab5d9ed50b642 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 10 Mar 2020 17:17:45 +0100 Subject: Add LocalTime::add_minutes. --- src/local_time.cc | 18 ++++++++++++++++++ src/local_time.h | 8 +++++--- 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'src') 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 +#include #include +#include #include 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 { 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 + Copyright (C) 2014-2020 Carl Hetherington This file is part of libdcp. @@ -41,7 +41,7 @@ #include #include -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 */ -- cgit v1.2.3