From c477605bda3ec24faa8e42d22959dc89176b7add Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 26 Feb 2015 00:55:33 +0100 Subject: [PATCH] Fix TZ handling in wxDateTime::ParseRfc822Date(). When the TZ offset specified in the RFC 822 string was equal to the local TZ offset but the date fell in the DST period, the result was one hour off. Fix this by converting the date to the UTC explicitly, and then converting it back to the local TZ to ensure that the DST is taken into effect. See #15370. --- docs/changes.txt | 1 + src/common/datetimefmt.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index 8b953d7ae2..66bbbf592e 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -580,6 +580,7 @@ Major new features in this release Unix: - Fix wxIPaddress::Hostname() failing if /etc/hosts contained very long names. +- Fix wxDateTime::ParseRfc822Date() for some TZ/DST combinations. All (GUI): diff --git a/src/common/datetimefmt.cpp b/src/common/datetimefmt.cpp index 137439f27e..6dc2968dae 100644 --- a/src/common/datetimefmt.cpp +++ b/src/common/datetimefmt.cpp @@ -996,7 +996,14 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end) // the spec was correct, construct the date from the values we found Set(day, mon, year, hour, min, sec); - MakeFromTimezone(TimeZone::Make(offset*SEC_PER_MIN)); + + // As always, dealing with the time zone is the most interesting part: we + // can't just use MakeFromTimeZone() here because it wouldn't handle the + // DST correctly because the TZ specified in the string is DST-invariant + // and so we have to manually shift to the UTC first and then convert to + // the local TZ. + *this -= wxTimeSpan::Minutes(offset); + MakeFromUTC(); if ( end ) *end = p;