X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flocal_time.cc;h=fe58c07736388622d60b0d90e20c832044d584e1;hb=19e00ec24925192d354dd15961b9f067c790edbf;hp=2388825cea4fdddb7be9c7946a52c222b2d3ae8f;hpb=f353b192693291e842e297118d5899c63a5a8e22;p=libdcp.git 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 +#include #include 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::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 */