Fixed several bugs in wxDateTime timezone handling:

- ToTimezone() and MakeTimezone() now work as expected
 - added and documented FromTimezone() and MakeFromTimezone()
 - Set(double jdn) interprets jdn always in UTC
 - updated ParseRfc822Date() timezone handling
 - removed workarounds for old bugs from the test


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35334 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2005-08-28 13:06:36 +00:00
parent 5378558e5c
commit d26adb9df7
5 changed files with 114 additions and 59 deletions

View File

@@ -257,7 +257,9 @@ void DateTimeTestCase::TestTimeJDN()
{
const Date& d = testDates[n];
wxDateTime dt(d.day, d.month, d.year, d.hour, d.min, d.sec);
double jdn = dt.GetJulianDayNumber();
// JDNs must be computed for UTC times
double jdn = dt.FromUTC().GetJulianDayNumber();
CPPUNIT_ASSERT( jdn == d.jdn );
@@ -662,7 +664,7 @@ void DateTimeTestCase::TestTimeTicks()
long ticks = (dt.GetValue() / 1000).ToLong();
CPPUNIT_ASSERT( ticks == d.ticks );
dt = d.DT().ToTimezone(wxDateTime::GMT0);
dt = d.DT().FromTimezone(wxDateTime::GMT0);
ticks = (dt.GetValue() / 1000).ToLong();
CPPUNIT_ASSERT( ticks == d.gmticks );
}
@@ -674,12 +676,25 @@ void DateTimeTestCase::TestTimeParse()
static const struct ParseTestData
{
const wxChar *format;
Date date;
Date date; // NB: this should be in UTC
bool good;
} parseTestDates[] =
{
{ _T("Sat, 18 Dec 1999 00:46:40 +0100"), { 18, wxDateTime::Dec, 1999, 00, 46, 40, 0.0, wxDateTime::Inv_WeekDay, 0, 0 }, true },
{ _T("Wed, 1 Dec 1999 05:17:20 +0300"), { 1, wxDateTime::Dec, 1999, 03, 17, 20, 0.0, wxDateTime::Inv_WeekDay, 0, 0 }, true },
{
_T("Sat, 18 Dec 1999 00:46:40 +0100"),
{ 17, wxDateTime::Dec, 1999, 23, 46, 40, 0.0, wxDateTime::Inv_WeekDay, 0, 0 },
true
},
{
_T("Wed, 1 Dec 1999 05:17:20 +0300"),
{ 1, wxDateTime::Dec, 1999, 2, 17, 20, 0.0, wxDateTime::Inv_WeekDay, 0, 0 },
true
},
{
_T("Sun, 28 Aug 2005 03:31:30 +0200"),
{ 28, wxDateTime::Aug, 2005, 1, 31, 30, 0.0, wxDateTime::Inv_WeekDay, 0, 0 },
true
},
};
for ( size_t n = 0; n < WXSIZEOF(parseTestDates); n++ )
@@ -691,10 +706,7 @@ void DateTimeTestCase::TestTimeParse()
{
CPPUNIT_ASSERT( parseTestDates[n].good );
wxDateTime dtReal = parseTestDates[n].date.DT();
//RN: We need this because the tests are based on
//a non-GMT time zone
dtReal.MakeTimezone(wxDateTime::WEST, true);
wxDateTime dtReal = parseTestDates[n].date.DT().FromUTC();
CPPUNIT_ASSERT( dt == dtReal );
}
else // failed to parse