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

@@ -456,9 +456,8 @@ wxDateTime::TimeZone::TimeZone(wxDateTime::TZ tz)
switch ( tz )
{
case wxDateTime::Local:
// get the offset from C RTL: it returns the difference GMT-local
// while we want to have the offset _from_ GMT, hence the '-'
m_offset = -wxGetTimeZone();
// Use a special value for local time zone.
m_offset = -1;
break;
case wxDateTime::GMT_12:
@@ -503,6 +502,13 @@ wxDateTime::TimeZone::TimeZone(wxDateTime::TZ tz)
}
}
long wxDateTime::TimeZone::GetOffset() const
{
// get the offset from C RTL: it returns the difference GMT-local
// while we want to have the offset _from_ GMT, hence the '-'
return m_offset == -1 ? -wxGetTimeZone() : m_offset;
}
// ----------------------------------------------------------------------------
// static functions
// ----------------------------------------------------------------------------
@@ -1432,7 +1438,7 @@ unsigned long wxDateTime::GetAsDOS() const
const tm* wxTryGetTm(tm& tmstruct, time_t t, const wxDateTime::TimeZone& tz)
{
if ( tz.GetOffset() == -wxGetTimeZone() )
if ( tz.IsLocal() )
{
// we are working with local time
return wxLocaltime_r(&t, &tmstruct);