diff --git a/interface/wx/datetime.h b/interface/wx/datetime.h index 289ac1da48..814c77c5c6 100644 --- a/interface/wx/datetime.h +++ b/interface/wx/datetime.h @@ -1257,10 +1257,7 @@ public: If @a noDST is @true, no DST adjustments will be made. - Notice using wxDateTime::Local for @a tz parameter doesn't really make - sense and may result in unexpected results as it will return a - different object when DST is in use and @a noDST has its default value - of @false. + If @a tz parameter is wxDateTime::Local, no adjustment is performed. @return The date adjusted by the different between the given and the local time zones. @@ -1297,9 +1294,7 @@ public: If @a noDST is @true, no DST adjustments will be made. - Notice that, as with FromTimezone(), using wxDateTime::Local as @a tz - doesn't really make sense and may return a different object when DST is - in effect and @a noDST is @false. + If @a tz parameter is wxDateTime::Local, no adjustment is performed. @return The date adjusted by the different between the local and the given time zones. diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 5b6013b8a8..2696551520 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -2094,11 +2094,11 @@ wxDateTime& wxDateTime::MakeTimezone(const TimeZone& tz, bool noDST) { long secDiff = wxGetTimeZone() + tz.GetOffset(); - // 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. - if ( !noDST && (IsDST() == 1) ) + // We are converting from the local time to some other time zone, 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. + if ( !noDST && (IsDST() == 1) && !tz.IsLocal() ) { secDiff -= DST_OFFSET; } @@ -2111,7 +2111,7 @@ wxDateTime& wxDateTime::MakeFromTimezone(const TimeZone& tz, bool noDST) long secDiff = wxGetTimeZone() + tz.GetOffset(); // See comment in MakeTimezone() above, the logic here is exactly the same. - if ( !noDST && (IsDST() == 1) ) + if ( !noDST && (IsDST() == 1) && !tz.IsLocal() ) { secDiff -= DST_OFFSET; } diff --git a/tests/datetime/datetimetest.cpp b/tests/datetime/datetimetest.cpp index 0ae4321900..246193790b 100644 --- a/tests/datetime/datetimetest.cpp +++ b/tests/datetime/datetimetest.cpp @@ -1565,21 +1565,20 @@ void DateTimeTestCase::TestTranslateFromUnicodeFormat() void DateTimeTestCase::TestConvToFromLocalTZ() { - // Choose a date when the DST is on in many time zones: in this case, - // converting to/from local TZ does modify the object because it - // adds/subtracts DST to/from it, so to get the expected results we need to - // explicitly disable DST support in these functions. + // Choose a date when the DST is on in many time zones and verify that + // converting from/to local time zone still doesn't modify time in this + // case as this used to be broken. wxDateTime dt(18, wxDateTime::Apr, 2017, 19); - CPPUNIT_ASSERT_EQUAL( dt.FromTimezone(wxDateTime::Local, true), dt ); - CPPUNIT_ASSERT_EQUAL( dt.ToTimezone(wxDateTime::Local, true), dt ); + CHECK( dt.FromTimezone(wxDateTime::Local) == dt ); + CHECK( dt.ToTimezone(wxDateTime::Local) == dt ); - // And another one when it is off: in this case, there is no need to pass - // "true" as "noDST" argument to these functions. + // For a date when the DST is not used, this always worked, but still + // verify that it continues to. dt = wxDateTime(18, wxDateTime::Jan, 2018, 19); - CPPUNIT_ASSERT_EQUAL( dt.FromTimezone(wxDateTime::Local), dt ); - CPPUNIT_ASSERT_EQUAL( dt.ToTimezone(wxDateTime::Local), dt ); + CHECK( dt.FromTimezone(wxDateTime::Local) == dt ); + CHECK( dt.ToTimezone(wxDateTime::Local) == dt ); } static void DoTestSetFunctionsOnDST(const wxDateTime &orig)