diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-03-20 16:16:17 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-03-20 16:16:17 +0000 |
| commit | f353b192693291e842e297118d5899c63a5a8e22 (patch) | |
| tree | 8f8613ea9fee2be419b11b1eee08c3f8acdb3e33 /src | |
| parent | 5e5750712fb6686cb4a192b3b232be96ad879b49 (diff) | |
Tweaks to LocalTime; build/install fixes.
Diffstat (limited to 'src')
| -rw-r--r-- | src/encrypted_kdm.h | 5 | ||||
| -rw-r--r-- | src/local_time.cc | 42 | ||||
| -rw-r--r-- | src/local_time.h | 15 | ||||
| -rw-r--r-- | src/wscript | 2 |
4 files changed, 60 insertions, 4 deletions
diff --git a/src/encrypted_kdm.h b/src/encrypted_kdm.h index 0aa36a15..41231c2e 100644 --- a/src/encrypted_kdm.h +++ b/src/encrypted_kdm.h @@ -21,6 +21,9 @@ * @brief EncryptedKDM class. */ +#ifndef LIBDCP_ENCRYPTED_KDM_H +#define LIBDCP_ENCRYPTED_KDM_H + #include "local_time.h" #include <boost/filesystem.hpp> #include <boost/date_time/local_time/local_time.hpp> @@ -92,3 +95,5 @@ private: }; } + +#endif diff --git a/src/local_time.cc b/src/local_time.cc index 665d5d41..2388825c 100644 --- a/src/local_time.cc +++ b/src/local_time.cc @@ -30,6 +30,7 @@ LocalTime::LocalTime () { time_t now = time (0); struct tm* tm = localtime (&now); + _year = tm->tm_year + 1900; _month = tm->tm_mon + 1; _day = tm->tm_mday + 1; @@ -37,6 +38,27 @@ LocalTime::LocalTime () _minute = tm->tm_min; _second = tm->tm_sec; + set_local_time_zone (); +} + +LocalTime::LocalTime (boost::posix_time::ptime t) +{ + _year = t.date().year (); + _month = t.date().month (); + _day = t.date().day (); + _hour = t.time_of_day().hours (); + _minute = t.time_of_day().minutes (); + _second = t.time_of_day().seconds (); + + set_local_time_zone (); +} + +void +LocalTime::set_local_time_zone () +{ + time_t now = time (0); + struct tm* tm = localtime (&now); + int offset = 0; #ifdef LIBDCP_POSIX @@ -95,8 +117,24 @@ LocalTime::as_string () const char buffer[32]; snprintf ( buffer, sizeof (buffer), - "%04d-%02d-%02dT%02d:%02d:%02d%s%02d:%02d", - _year, _month, _day, _hour, _minute, _second, (_tz_hour >= 0 ? "+" : "-"), abs (_tz_hour), _tz_minute + "%sT%s%s%02d:%02d", + date().c_str(), time_of_day().c_str(), (_tz_hour >= 0 ? "+" : "-"), abs (_tz_hour), _tz_minute ); return buffer; } + +string +LocalTime::date () const +{ + char buffer[32]; + snprintf (buffer, sizeof (buffer), "%04d-%02d-%02d", _year, _month, _day); + return buffer; +} + +string +LocalTime::time_of_day () const +{ + char buffer[32]; + snprintf (buffer, sizeof (buffer), "%02d:%02d:%02d", _hour, _minute, _second); + return buffer; +} diff --git a/src/local_time.h b/src/local_time.h index 9c634fed..00b32f10 100644 --- a/src/local_time.h +++ b/src/local_time.h @@ -20,30 +20,41 @@ #ifndef LIBDCP_LOCAL_TIME_H #define LIBDCP_LOCAL_TIME_H +#include <boost/date_time/posix_time/posix_time.hpp> #include <string> class local_time_test; namespace dcp { -/** I tried to use boost for this, really I did */ +/** I tried to use boost for this, really I did, but I could not get it + * to parse strings of the required format (those that include time zones). + */ class LocalTime { public: LocalTime (); + LocalTime (boost::posix_time::ptime); LocalTime (std::string); std::string as_string () const; + std::string date () const; + std::string time_of_day () const; private: friend class ::local_time_test; - + + void set_local_time_zone (); + + /* Local time */ int _year; int _month; int _day; int _hour; int _minute; int _second; + + /* Amount by which this time is offset from UTC */ int _tz_hour; int _tz_minute; }; diff --git a/src/wscript b/src/wscript index a54a40d5..fbbd9f2b 100644 --- a/src/wscript +++ b/src/wscript @@ -75,11 +75,13 @@ def build(bld): dcp.h dcp_time.h decrypted_kdm.h + decrypted_kdm_key.h encrypted_kdm.h exceptions.h gamma_lut.h image.h key.h + local_time.h lut_cache.h metadata.h mono_picture_mxf.h |
