From d43370b8a879f5d318701de4f16808a7cb1de77e Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 21 Aug 2013 11:17:42 +0100 Subject: Try to fix timezone offset formatting. --- src/metadata.cc | 27 ++++++++++++++++----------- src/metadata.h | 6 +++--- test/bias_to_string_test.cc | 30 ------------------------------ test/tests.cc | 2 +- test/utc_offset_to_string_test.cc | 30 ++++++++++++++++++++++++++++++ 5 files changed, 50 insertions(+), 45 deletions(-) delete mode 100644 test/bias_to_string_test.cc create mode 100644 test/utc_offset_to_string_test.cc diff --git a/src/metadata.cc b/src/metadata.cc index 5304fd96..bcf5d76c 100644 --- a/src/metadata.cc +++ b/src/metadata.cc @@ -52,25 +52,30 @@ void XMLMetadata::set_issue_date_now () { char buffer[64]; - time_t now; - time (&now); + time_t now = time (0); struct tm* tm = localtime (&now); -#ifdef LIBDCP_POSIX - strftime (buffer, 64, "%Y-%m-%dT%I:%M:%S%z", tm); - issue_date = string (buffer); -#else - /* No %z for strftime on Windows: it will seemingly be interpreted as %Z and will - output some localised string describing the timezone */ strftime (buffer, 64, "%Y-%m-%dT%I:%M:%S", tm); + int offset = 0; + +#ifdef LIBDCP_POSIX + + offset = tm->tm_gmtoff / 60; + +#else TIME_ZONE_INFORMATION tz; GetTimeZoneInformation (&tz); - issue_date = string (buffer) + bias_to_string (tz.Bias); + offset = tz.Bias; #endif + + issue_date = string (buffer) + utc_offset_to_string (offset); } +/** @param b Offset from UTC to local time in minutes. + * @return string of the form e.g. -01:00. + */ string -XMLMetadata::bias_to_string (int b) +XMLMetadata::utc_offset_to_string (int b) { bool const negative = (b < 0); b = negative ? -b : b; @@ -85,6 +90,6 @@ XMLMetadata::bias_to_string (int b) o << "+"; } - o << setw(2) << setfill('0') << hours << setw(2) << setfill('0') << minutes; + o << setw(2) << setfill('0') << hours << ":" << setw(2) << setfill('0') << minutes; return o.str (); } diff --git a/src/metadata.h b/src/metadata.h index 7ba17fa4..d71537fd 100644 --- a/src/metadata.h +++ b/src/metadata.h @@ -26,7 +26,7 @@ #include -class bias_to_string_test; +class utc_offset_to_string_test; namespace libdcp { @@ -53,9 +53,9 @@ public: std::string issue_date; private: - friend class ::bias_to_string_test; + friend class ::utc_offset_to_string_test; - static std::string bias_to_string (int); + static std::string utc_offset_to_string (int); }; } diff --git a/test/bias_to_string_test.cc b/test/bias_to_string_test.cc deleted file mode 100644 index 56df40ea..00000000 --- a/test/bias_to_string_test.cc +++ /dev/null @@ -1,30 +0,0 @@ -/* - Copyright (C) 2013 Carl Hetherington - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "metadata.h" - -/** Test XMLMetadata::bias_to_string */ -BOOST_AUTO_TEST_CASE (bias_to_string_test) -{ - BOOST_CHECK_EQUAL (libdcp::XMLMetadata::bias_to_string (30), "+0030"); - BOOST_CHECK_EQUAL (libdcp::XMLMetadata::bias_to_string (60), "+0100"); - BOOST_CHECK_EQUAL (libdcp::XMLMetadata::bias_to_string (61), "+0101"); - BOOST_CHECK_EQUAL (libdcp::XMLMetadata::bias_to_string (7 * 60), "+0700"); - BOOST_CHECK_EQUAL (libdcp::XMLMetadata::bias_to_string (-11 * 60), "-1100"); -} diff --git a/test/tests.cc b/test/tests.cc index 11189558..2543d025 100644 --- a/test/tests.cc +++ b/test/tests.cc @@ -70,7 +70,7 @@ wav (libdcp::Channel) static string test_corpus = "../libdcp-test"; -#include "bias_to_string_test.cc" +#include "utc_offset_to_string_test.cc" #include "lut_test.cc" #include "util_test.cc" #include "decryption_test.cc" diff --git a/test/utc_offset_to_string_test.cc b/test/utc_offset_to_string_test.cc new file mode 100644 index 00000000..6ea597f0 --- /dev/null +++ b/test/utc_offset_to_string_test.cc @@ -0,0 +1,30 @@ +/* + Copyright (C) 2013 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "metadata.h" + +/** Test XMLMetadata::utc_offset_to_string */ +BOOST_AUTO_TEST_CASE (utc_offset_to_string_test) +{ + BOOST_CHECK_EQUAL (libdcp::XMLMetadata::utc_offset_to_string (30), "+00:30"); + BOOST_CHECK_EQUAL (libdcp::XMLMetadata::utc_offset_to_string (60), "+01:00"); + BOOST_CHECK_EQUAL (libdcp::XMLMetadata::utc_offset_to_string (61), "+01:01"); + BOOST_CHECK_EQUAL (libdcp::XMLMetadata::utc_offset_to_string (7 * 60), "+07:00"); + BOOST_CHECK_EQUAL (libdcp::XMLMetadata::utc_offset_to_string (-11 * 60), "-11:00"); +} -- cgit v1.2.3 From 5a637337f4fc4c3cba211f67ce475a0ae55a9a67 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 21 Aug 2013 11:17:52 +0100 Subject: Bump version --- wscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wscript b/wscript index 2ee959a3..fb39ca0b 100644 --- a/wscript +++ b/wscript @@ -2,7 +2,7 @@ import subprocess import os APPNAME = 'libdcp' -VERSION = '0.74pre' +VERSION = '0.74' def options(opt): opt.load('compiler_cxx') -- cgit v1.2.3 From bbf265955518069c5c841be5fe02a95b60e9197b Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 21 Aug 2013 11:17:52 +0100 Subject: Bump version --- wscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wscript b/wscript index fb39ca0b..4f7291db 100644 --- a/wscript +++ b/wscript @@ -2,7 +2,7 @@ import subprocess import os APPNAME = 'libdcp' -VERSION = '0.74' +VERSION = '0.75pre' def options(opt): opt.load('compiler_cxx') -- cgit v1.2.3