Explicitly disambiguate local time zone from UTC

Don't rely on time zone offset to check whether it is local as this
doesn't, and can't, work for the local time zone in Great Britain which
uses the same offset as UTC, but does use DST, unlike the latter.

Add a unit test (albeit disabled by default) checking that the code that
previously didn't work correctly in BST does work now (run the tests
using "TZ=Europe/London ./test wxDateTime-BST-bugs" under Unix to test).

Closes #14317, #17220.

See #10445.
This commit is contained in:
Vadim Zeitlin
2017-11-29 22:58:06 +01:00
parent f13b7c6a55
commit 543c522cb8
4 changed files with 48 additions and 6 deletions

View File

@@ -683,7 +683,7 @@ void DateTimeTestCase::TestTimeFormat()
const long timeZonesOffsets[] =
{
wxDateTime::TimeZone(wxDateTime::Local).GetOffset(),
-1, // This is pseudo-offset used for local time zone
// Fictitious TimeZone offsets to ensure time zone formating and
// interpretation works
@@ -1638,4 +1638,27 @@ TEST_CASE("wxDateTime::SetOnDST", "[datetime][dst]")
}
}
// Tests random problems that used to appear in BST time zone during DST.
// This test is disabled by default as it only passes in BST time zone, due to
// the times hard-coded in it.
TEST_CASE("wxDateTime-BST-bugs", "[datetime][dst][BST][.]")
{
SECTION("bug-17220")
{
wxDateTime dt;
dt.Set(22, wxDateTime::Oct, 2015, 10, 10, 10, 10);
REQUIRE( dt.IsDST() );
CHECK( dt.GetTm().hour == 10 );
CHECK( dt.GetTm(wxDateTime::UTC).hour == 9 );
CHECK( dt.Format("%Y-%m-%d %H:%M:%S", wxDateTime::Local ) == "2015-10-22 10:10:10" );
CHECK( dt.Format("%Y-%m-%d %H:%M:%S", wxDateTime::UTC ) == "2015-10-22 09:10:10" );
dt.MakeFromUTC();
CHECK( dt.Format("%Y-%m-%d %H:%M:%S", wxDateTime::Local ) == "2015-10-22 11:10:10" );
CHECK( dt.Format("%Y-%m-%d %H:%M:%S", wxDateTime::UTC ) == "2015-10-22 10:10:10" );
}
}
#endif // wxUSE_DATETIME