more wxDateTime tests
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5045 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -144,8 +144,8 @@ static void TestMimeEnum()
|
|||||||
wxFileType *filetype = mimeTM.GetFileTypeFromMimeType(mimetypes[n]);
|
wxFileType *filetype = mimeTM.GetFileTypeFromMimeType(mimetypes[n]);
|
||||||
if ( !filetype )
|
if ( !filetype )
|
||||||
{
|
{
|
||||||
printf("nothing known about the filetype '%s'!\n",
|
printf("nothing known about the filetype '%s'!\n",
|
||||||
mimetypes[n].c_str());
|
mimetypes[n].c_str());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,6 +252,8 @@ static void TestDivision()
|
|||||||
|
|
||||||
#ifdef TEST_TIME
|
#ifdef TEST_TIME
|
||||||
|
|
||||||
|
#include <wx/date.h>
|
||||||
|
|
||||||
#include <wx/datetime.h>
|
#include <wx/datetime.h>
|
||||||
|
|
||||||
// the test data
|
// the test data
|
||||||
@@ -585,10 +587,10 @@ for n in range(20):
|
|||||||
weekNum = weekNum + countFromEnd
|
weekNum = weekNum + countFromEnd
|
||||||
|
|
||||||
data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
|
data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'wday': wdayNames[wday] }
|
||||||
|
|
||||||
print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
|
print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)d, "\
|
||||||
"wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
|
"wxDateTime::%(wday)s, wxDateTime::%(month)s, %(year)d }," % data
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const WeekDateTestData weekDatesTestData[] =
|
static const WeekDateTestData weekDatesTestData[] =
|
||||||
{
|
{
|
||||||
@@ -669,7 +671,7 @@ for n in range(20):
|
|||||||
weekNum = dt.iso_week[1]
|
weekNum = dt.iso_week[1]
|
||||||
|
|
||||||
data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'dayNum': rjust(`dayNum`, 3) }
|
data = { 'day': rjust(`day`, 2), 'month': monthNames[month - 1], 'year': year, 'weekNum': rjust(`weekNum`, 2), 'dayNum': rjust(`dayNum`, 3) }
|
||||||
|
|
||||||
print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)s, "\
|
print "{ { %(day)s, wxDateTime::%(month)s, %(year)d }, %(weekNum)s, "\
|
||||||
"%(dayNum)s }," % data
|
"%(dayNum)s }," % data
|
||||||
*/
|
*/
|
||||||
@@ -789,7 +791,7 @@ static void TestTimeDST()
|
|||||||
size_t n = year - 1990;
|
size_t n = year - 1990;
|
||||||
const Date& dBegin = datesDST[0][n];
|
const Date& dBegin = datesDST[0][n];
|
||||||
const Date& dEnd = datesDST[1][n];
|
const Date& dEnd = datesDST[1][n];
|
||||||
|
|
||||||
if ( dBegin.SameDay(dtBegin.GetTm()) && dEnd.SameDay(dtEnd.GetTm()) )
|
if ( dBegin.SameDay(dtBegin.GetTm()) && dEnd.SameDay(dtEnd.GetTm()) )
|
||||||
{
|
{
|
||||||
puts(" (ok)");
|
puts(" (ok)");
|
||||||
@@ -813,6 +815,87 @@ static void TestTimeDST()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test text -> wxDateTime conversion
|
||||||
|
static void TestTimeParse()
|
||||||
|
{
|
||||||
|
puts("\n*** wxDateTime parse test ***");
|
||||||
|
|
||||||
|
struct ParseTestData
|
||||||
|
{
|
||||||
|
const char *format;
|
||||||
|
Date date;
|
||||||
|
bool good;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const ParseTestData parseTestDates[] =
|
||||||
|
{
|
||||||
|
"Sat, 18 Dec 1999 00:46:40 +0100", { 18, wxDateTime::Dec, 1999, 00, 46, 40 }, TRUE,
|
||||||
|
};
|
||||||
|
|
||||||
|
for ( size_t n = 0; n < WXSIZEOF(parseTestDates); n++ )
|
||||||
|
{
|
||||||
|
const char *format = parseTestDates[n].format;
|
||||||
|
|
||||||
|
printf("%s => ", format);
|
||||||
|
|
||||||
|
wxDateTime dt;
|
||||||
|
if ( dt.ParseRfc822Date(format) )
|
||||||
|
{
|
||||||
|
printf("%s ", dt.Format().c_str());
|
||||||
|
|
||||||
|
if ( parseTestDates[n].good )
|
||||||
|
{
|
||||||
|
wxDateTime dtReal = parseTestDates[n].date.DT();
|
||||||
|
if ( dt == dtReal )
|
||||||
|
{
|
||||||
|
puts("(ok)");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("(ERROR: should be %s)\n", dtReal.Format().c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
puts("(ERROR: bad format)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("bad format (%s)\n",
|
||||||
|
parseTestDates[n].good ? "ERROR" : "ok");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// test compatibility with the old wxDate/wxTime classes
|
||||||
|
static void TestTimeCompatibility()
|
||||||
|
{
|
||||||
|
puts("\n*** wxDateTime compatibility test ***");
|
||||||
|
|
||||||
|
printf("wxDate for JDN 0: %s\n", wxDate(0l).FormatDate().c_str());
|
||||||
|
printf("wxDate for MJD 0: %s\n", wxDate(2400000).FormatDate().c_str());
|
||||||
|
|
||||||
|
double jdnNow = wxDateTime::Now().GetJDN();
|
||||||
|
long jdnMidnight = (long)(jdnNow - 0.5);
|
||||||
|
printf("wxDate for today: %s\n", wxDate(jdnMidnight).FormatDate().c_str());
|
||||||
|
|
||||||
|
jdnMidnight = wxDate().Set().GetJulianDate();
|
||||||
|
printf("wxDateTime for today: %s\n",
|
||||||
|
wxDateTime((double)(jdnMidnight + 0.5)).Format("%c", wxDateTime::GMT0).c_str());
|
||||||
|
|
||||||
|
int flags = wxEUROPEAN;//wxFULL;
|
||||||
|
wxDate date;
|
||||||
|
date.Set();
|
||||||
|
printf("Today is %s\n", date.FormatDate(flags).c_str());
|
||||||
|
for ( int n = 0; n < 7; n++ )
|
||||||
|
{
|
||||||
|
printf("Previous %s is %s\n",
|
||||||
|
wxDateTime::GetWeekDayName((wxDateTime::WeekDay)n),
|
||||||
|
date.Previous(n + 1).FormatDate(flags).c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // TEST_TIME
|
#endif // TEST_TIME
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -1262,8 +1345,10 @@ int main(int argc, char **argv)
|
|||||||
TestTimeJDN();
|
TestTimeJDN();
|
||||||
TestTimeDST();
|
TestTimeDST();
|
||||||
TestTimeWDays();
|
TestTimeWDays();
|
||||||
}
|
|
||||||
TestTimeWNumber();
|
TestTimeWNumber();
|
||||||
|
TestTimeParse();
|
||||||
|
}
|
||||||
|
TestTimeCompatibility();
|
||||||
#endif // TEST_TIME
|
#endif // TEST_TIME
|
||||||
|
|
||||||
wxUninitialize();
|
wxUninitialize();
|
||||||
|
Reference in New Issue
Block a user