From: Vadim Zeitlin Date: Sun, 25 Mar 2012 00:31:47 +0000 (+0000) Subject: Fix bug with parsing time formats during DST periods. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/4323bbde8deac0023525011d53cf4223dac3f0a1 Fix bug with parsing time formats during DST periods. wxDateTime::ParseFormat() used todays date as fall back when parsing all formats, including those involving times, which meant that its results depended on whether DST was active at the time of the parsing which was clearly wrong. Fix this by using a fixed date on which DST is known not to be active as fall back date. This fixes unit test failures in DateTimeTestCase::TestTimeFormat() when it was ran on a DST transition date. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70993 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/datetimefmt.cpp b/src/common/datetimefmt.cpp index ac7540dc88..cfce31f86a 100644 --- a/src/common/datetimefmt.cpp +++ b/src/common/datetimefmt.cpp @@ -291,8 +291,14 @@ ParseFormatAt(wxString::const_iterator& p, const wxString str(p, end); wxString::const_iterator endParse; wxDateTime dt; - if ( dt.ParseFormat(str, fmt, &endParse) || - (!fmtAlt.empty() && dt.ParseFormat(str, fmtAlt, &endParse)) ) + + // Use a default date outside of the DST period to avoid problems with + // parsing the time differently depending on the todays date (which is used + // as the fall back date if none is explicitly specified). + static const wxDateTime dtDef(1, wxDateTime::Jan, 2012); + + if ( dt.ParseFormat(str, fmt, dtDef, &endParse) || + (!fmtAlt.empty() && dt.ParseFormat(str, fmtAlt, dtDef, &endParse)) ) { p += endParse - str.begin(); }