summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-05-16 11:38:35 +0100
committerCarl Hetherington <cth@carlh.net>2014-05-16 11:38:35 +0100
commita8ae455886f36c19257129f34b172051bbe120bf (patch)
treec3b5f9d66b660b440acdfa8cceebca816281cd19 /src
parent2f0e6ee9d883abbbc31aca0d1cc80e89eb9b0af2 (diff)
Hand-merge changes from master (110dc70..979739e)
Diffstat (limited to 'src')
-rw-r--r--src/local_time.cc27
-rw-r--r--src/raw_convert.h2
2 files changed, 8 insertions, 21 deletions
diff --git a/src/local_time.cc b/src/local_time.cc
index 2388825c..fe58c077 100644
--- a/src/local_time.cc
+++ b/src/local_time.cc
@@ -20,6 +20,7 @@
#include "local_time.h"
#include "exceptions.h"
#include <boost/lexical_cast.hpp>
+#include <boost/date_time/c_local_time_adjustor.hpp>
#include <cstdio>
using std::string;
@@ -56,28 +57,12 @@ LocalTime::LocalTime (boost::posix_time::ptime t)
void
LocalTime::set_local_time_zone ()
{
- time_t now = time (0);
- struct tm* tm = localtime (&now);
-
- int offset = 0;
-
-#ifdef LIBDCP_POSIX
- offset = tm->tm_gmtoff / 60;
-#else
- TIME_ZONE_INFORMATION tz;
- GetTimeZoneInformation (&tz);
- offset = tz.Bias;
-#endif
+ boost::posix_time::ptime const utc_now = boost::posix_time::second_clock::universal_time ();
+ boost::posix_time::ptime const now = boost::date_time::c_local_adjustor<boost::posix_time::ptime>::utc_to_local (utc_now);
+ boost::posix_time::time_duration offset = now - utc_now;
- bool const negative = offset < 0;
- offset = negative ? -offset : offset;
-
- _tz_hour = offset / 60;
- _tz_minute = offset % 60;
-
- if (negative) {
- _tz_hour = -_tz_hour;
- }
+ _tz_hour = offset.hours ();
+ _tz_minute = offset.minutes ();
}
/** @param s A string of the form 2013-01-05T18:06:59+04:00 */
diff --git a/src/raw_convert.h b/src/raw_convert.h
index 68bbaf7a..37cddbf0 100644
--- a/src/raw_convert.h
+++ b/src/raw_convert.h
@@ -18,6 +18,7 @@
*/
#include <sstream>
+#include <iomanip>
namespace dcp {
@@ -30,6 +31,7 @@ raw_convert (Q v)
{
std::stringstream s;
s.imbue (std::locale::classic ());
+ s << std::setprecision (16);
s << v;
P r;
s >> r;