From aaddf6be7f6a1b1ea4f7c316a25251d408e14825 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 27 Sep 2014 17:26:06 +0000 Subject: [PATCH] Don't add DST offset when converting to local time zone. Local time zone already logically includes DST, even if its offset doesn't account for it (because the offset depends on the date, so it can't be part of TZ itself), so don't add it again when converting to/from it. Closes #16585. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77899 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/datetime.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 9aa2c7e43c..588f2f8067 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -2066,9 +2066,15 @@ wxDateTime& wxDateTime::MakeTimezone(const TimeZone& tz, bool noDST) { long secDiff = wxGetTimeZone() + tz.GetOffset(); - // we need to know whether DST is or not in effect for this date unless - // the test disabled by the caller - if ( !noDST && (IsDST() == 1) ) + // We are converting from the local time, but local time zone does not + // include the DST offset (as it varies depending on the date), so we have + // to handle DST manually, unless a special flag inhibiting this was + // specified. + // + // Notice that we also shouldn't add the DST offset if we're already in the + // local time zone, as indicated by offset of 0, converting from local time + // to local time zone shouldn't change it, whether DST is in effect or not. + if ( !noDST && secDiff && (IsDST() == 1) ) { // FIXME we assume that the DST is always shifted by 1 hour secDiff -= 3600; @@ -2081,9 +2087,8 @@ wxDateTime& wxDateTime::MakeFromTimezone(const TimeZone& tz, bool noDST) { long secDiff = wxGetTimeZone() + tz.GetOffset(); - // we need to know whether DST is or not in effect for this date unless - // the test disabled by the caller - if ( !noDST && (IsDST() == 1) ) + // See comment in MakeTimezone() above, the logic here is exactly the same. + if ( !noDST && secDiff && (IsDST() == 1) ) { // FIXME we assume that the DST is always shifted by 1 hour secDiff -= 3600;