correct wxDateTime DST begin/end computations for years > 2006 in USA (closes #10425)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58486 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
f54e5c1a4f
commit
6b522db5c8
@ -1273,6 +1273,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) )
|
||||
@ -1349,21 +1360,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);
|
||||
}
|
||||
|
@ -536,7 +536,7 @@ for n in range(20):
|
||||
void DateTimeTestCase::TestTimeDST()
|
||||
{
|
||||
// taken from http://www.energy.ca.gov/daylightsaving.html
|
||||
static const Date datesDST[2][2004 - 1900 + 1] =
|
||||
static const Date datesDST[2][2009 - 1990 + 1] =
|
||||
{
|
||||
{
|
||||
{ 1, wxDateTime::Apr, 1990, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
@ -554,6 +554,11 @@ void DateTimeTestCase::TestTimeDST()
|
||||
{ 7, wxDateTime::Apr, 2002, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
{ 6, wxDateTime::Apr, 2003, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
{ 4, wxDateTime::Apr, 2004, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
{ 3, wxDateTime::Apr, 2005, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
{ 2, wxDateTime::Apr, 2006, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
{11, wxDateTime::Mar, 2007, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
{ 9, wxDateTime::Mar, 2008, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
{ 8, wxDateTime::Mar, 2009, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
},
|
||||
{
|
||||
{ 28, wxDateTime::Oct, 1990, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
@ -571,20 +576,26 @@ void DateTimeTestCase::TestTimeDST()
|
||||
{ 27, wxDateTime::Oct, 2002, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
{ 26, wxDateTime::Oct, 2003, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
{ 31, wxDateTime::Oct, 2004, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
{ 30, wxDateTime::Oct, 2005, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
{ 29, wxDateTime::Oct, 2006, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
{ 4, wxDateTime::Nov, 2007, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
{ 2, wxDateTime::Nov, 2008, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
{ 1, wxDateTime::Nov, 2009, 0, 0, 0, 0.0, wxDateTime::Inv_WeekDay, 0 },
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
for ( int year = 1990; year < 2005; year++ )
|
||||
for ( size_t n = 0; n < WXSIZEOF(datesDST[0]); n++ )
|
||||
{
|
||||
const int year = 1990 + n;
|
||||
wxDateTime dtBegin = wxDateTime::GetBeginDST(year, wxDateTime::USA),
|
||||
dtEnd = wxDateTime::GetEndDST(year, wxDateTime::USA);
|
||||
|
||||
size_t n = year - 1990;
|
||||
const Date& dBegin = datesDST[0][n];
|
||||
const Date& dEnd = datesDST[1][n];
|
||||
|
||||
CPPUNIT_ASSERT( dBegin.SameDay(dtBegin.GetTm()) );
|
||||
CPPUNIT_ASSERT( dEnd.SameDay(dtEnd.GetTm()) );
|
||||
CPPUNIT_ASSERT_EQUAL( dBegin.DT().FormatDate(), dtBegin.FormatDate() );
|
||||
CPPUNIT_ASSERT_EQUAL( dEnd.DT().FormatDate(), dtEnd.FormatDate() );
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user