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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user