From adf8a83f4fd73950bfbdfc231d530167b802868e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 28 Jan 2009 21:52:37 +0000 Subject: [PATCH] correct wxDateTime DST begin/end computations for years > 2006 in USA (closes #10425) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@58486 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/common/datetime.cpp | 40 +++++++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 7738ad7f96..69a0aa8900 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -102,6 +102,7 @@ All: - Fix wxURL::GetInputStream() for URLs with special characters in credentials (Robert Wruck). - Fix wxURI::GetUser() for URIs without password. +- Correct wxDateTime DST computation for 2006 and later (Christopher Barker). All (GUI): diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 61108a59c8..f3ab89c64c 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -1239,6 +1239,17 @@ wxDateTime wxDateTime::GetBeginDST(int year, Country country) wxFAIL_MSG( _T("no first Sunday in April?") ); } } + else if ( year > 2006 ) + // Energy Policy Act of 2005, Pub. L. no. 109-58, 119 Stat 594 (2005). + // Starting in 2007, daylight time begins in the United States on the + // second Sunday in March and ends on the first Sunday in November + { + if ( !dt.SetToWeekDay(Sun, 2, Mar, year) ) + { + // weird... + wxFAIL_MSG( _T("no second Sunday in March?") ); + } + } else { if ( !dt.SetToWeekDay(Sun, 1, Apr, year) ) @@ -1318,21 +1329,36 @@ wxDateTime wxDateTime::GetEndDST(int year, Country country) dt.Set(30, Sep, year); break; - default: - // DST ends at 2 a.m. on the last Sunday of October - if ( !dt.SetToLastWeekDay(Sun, Oct, year) ) + default: // default for switch (year) + if ( year > 2006 ) + // Energy Policy Act of 2005, Pub. L. no. 109-58, 119 Stat 594 (2005). + // Starting in 2007, daylight time begins in the United States on the + // second Sunday in March and ends on the first Sunday in November { - // weirder and weirder... - wxFAIL_MSG( _T("no last Sunday in October?") ); + if ( !dt.SetToWeekDay(Sun, 1, Nov, year) ) + { + // weird... + wxFAIL_MSG( _T("no first Sunday in November?") ); + } + } + else + // pre-2007 + // DST ends at 2 a.m. on the last Sunday of October + { + if ( !dt.SetToLastWeekDay(Sun, Oct, year) ) + { + // weirder and weirder... + wxFAIL_MSG( _T("no last Sunday in October?") ); + } } dt += wxTimeSpan::Hours(2); - // TODO what about timezone?? + // TODO: what about timezone?? } break; - default: + default: // default for switch (country) // assume October 26th as the end of the DST - totally bogus too dt.Set(26, Oct, year); }