2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
2003-06-03 20:58:22 +00:00
|
|
|
* Copyright (c) 1997-2003, International Business Machines Corporation and
|
2000-01-15 02:00:06 +00:00
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-09-21 00:43:14 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "dtfmrgts.h"
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/timezone.h"
|
|
|
|
#include "unicode/gregocal.h"
|
|
|
|
#include "unicode/smpdtfmt.h"
|
|
|
|
#include "unicode/datefmt.h"
|
|
|
|
#include "unicode/simpletz.h"
|
|
|
|
#include "unicode/resbund.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// class DateFormatRegressionTest
|
|
|
|
// *****************************************************************************
|
|
|
|
|
|
|
|
#define CASE(id,test) case id: name = #test; if (exec) { logln(#test "---"); logln((UnicodeString)""); test(); } break;
|
|
|
|
|
|
|
|
void
|
2000-08-23 19:11:16 +00:00
|
|
|
DateFormatRegressionTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
// if (exec) logln((UnicodeString)"TestSuite DateFormatRegressionTest");
|
|
|
|
switch (index) {
|
|
|
|
CASE(0,Test4029195)
|
|
|
|
CASE(1,Test4052408)
|
|
|
|
CASE(2,Test4056591)
|
|
|
|
CASE(3,Test4059917)
|
|
|
|
CASE(4,Test4060212)
|
|
|
|
CASE(5,Test4061287)
|
|
|
|
CASE(6,Test4065240)
|
|
|
|
CASE(7,Test4071441)
|
|
|
|
CASE(8,Test4073003)
|
|
|
|
CASE(9,Test4089106)
|
|
|
|
CASE(10,Test4100302)
|
|
|
|
CASE(11,Test4101483)
|
|
|
|
CASE(12,Test4103340)
|
|
|
|
CASE(13,Test4103341)
|
|
|
|
CASE(14,Test4104136)
|
|
|
|
CASE(15,Test4104522)
|
|
|
|
CASE(16,Test4106807)
|
|
|
|
CASE(17,Test4108407)
|
|
|
|
CASE(18,Test4134203)
|
|
|
|
CASE(19,Test4151631)
|
|
|
|
CASE(20,Test4151706)
|
|
|
|
CASE(21,Test4162071)
|
1999-10-15 23:16:58 +00:00
|
|
|
CASE(22,Test4182066)
|
1999-10-16 01:35:16 +00:00
|
|
|
CASE(23,Test4210209)
|
2000-11-13 21:03:06 +00:00
|
|
|
CASE(24,Test714)
|
2003-06-06 01:48:24 +00:00
|
|
|
CASE(25,Test1684)
|
1999-08-16 21:50:52 +00:00
|
|
|
default: name = ""; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4029195
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4029195(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
UDate today = Calendar::getNow();
|
|
|
|
logln((UnicodeString) "today: " + today);
|
|
|
|
|
|
|
|
SimpleDateFormat *sdf = (SimpleDateFormat*) DateFormat::createDateInstance();
|
|
|
|
failure(status, "SimpleDateFormat::createDateInstance");
|
|
|
|
UnicodeString pat;
|
|
|
|
pat = sdf->toPattern(pat);
|
|
|
|
logln("pattern: " + pat);
|
|
|
|
UnicodeString fmtd;
|
|
|
|
FieldPosition pos(FieldPosition::DONT_CARE);
|
|
|
|
fmtd = sdf->format(today, fmtd, pos);
|
|
|
|
logln("today: " + fmtd);
|
|
|
|
|
|
|
|
sdf->applyPattern("G yyyy DDD");
|
|
|
|
UnicodeString todayS;
|
|
|
|
todayS = sdf->format(today, todayS, pos);
|
|
|
|
logln("today: " + todayS);
|
|
|
|
//try {
|
|
|
|
today = sdf->parse(todayS, status);
|
|
|
|
failure(status, "sdf->parse");
|
|
|
|
logln((UnicodeString)"today date: " + today);
|
|
|
|
/*} catch(Exception e) {
|
|
|
|
logln("Error reparsing date: " + e.getMessage());
|
|
|
|
}*/
|
|
|
|
|
|
|
|
//try {
|
|
|
|
UnicodeString rt;
|
|
|
|
rt = sdf->format(sdf->parse(todayS, status), rt, pos);
|
|
|
|
failure(status, "sdf->parse");
|
|
|
|
logln("round trip: " + rt);
|
|
|
|
if(rt != todayS)
|
|
|
|
errln("Fail: Want " + todayS + " Got " + rt);
|
|
|
|
/*}
|
|
|
|
catch (ParseException e) {
|
|
|
|
errln("Fail: " + e);
|
|
|
|
e.printStackTrace();
|
|
|
|
}*/
|
|
|
|
|
|
|
|
delete sdf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4052408
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4052408(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
DateFormat *fmt = DateFormat::createDateTimeInstance(DateFormat::SHORT,
|
2002-04-11 18:36:11 +00:00
|
|
|
DateFormat::SHORT, Locale::getUS());
|
2003-02-21 08:32:22 +00:00
|
|
|
UDate dt = date(97, UCAL_MAY, 3, 8, 55);
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString str;
|
|
|
|
str = fmt->format(dt, str);
|
|
|
|
logln(str);
|
|
|
|
|
2002-04-11 23:29:14 +00:00
|
|
|
if(str != "5/3/97 8:55 AM")
|
|
|
|
errln("Fail: Test broken; Want 5/3/97 8:55 AM Got " + str);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
UnicodeString expected[] = {
|
|
|
|
(UnicodeString) "", //"ERA_FIELD",
|
2002-04-11 23:29:14 +00:00
|
|
|
(UnicodeString) "97", //"YEAR_FIELD",
|
1999-08-16 21:50:52 +00:00
|
|
|
(UnicodeString) "5", //"MONTH_FIELD",
|
|
|
|
(UnicodeString) "3", //"DATE_FIELD",
|
|
|
|
(UnicodeString) "", //"HOUR_OF_DAY1_FIELD",
|
|
|
|
(UnicodeString) "", //"HOUR_OF_DAY0_FIELD",
|
|
|
|
(UnicodeString) "55", //"MINUTE_FIELD",
|
|
|
|
(UnicodeString) "", //"SECOND_FIELD",
|
|
|
|
(UnicodeString) "", //"MILLISECOND_FIELD",
|
|
|
|
(UnicodeString) "", //"DAY_OF_WEEK_FIELD",
|
|
|
|
(UnicodeString) "", //"DAY_OF_YEAR_FIELD",
|
|
|
|
(UnicodeString) "", //"DAY_OF_WEEK_IN_MONTH_FIELD",
|
|
|
|
(UnicodeString) "", //"WEEK_OF_YEAR_FIELD",
|
|
|
|
(UnicodeString) "", //"WEEK_OF_MONTH_FIELD",
|
|
|
|
(UnicodeString) "AM", //"AM_PM_FIELD",
|
|
|
|
(UnicodeString) "8", //"HOUR1_FIELD",
|
|
|
|
(UnicodeString) "", //"HOUR0_FIELD",
|
|
|
|
(UnicodeString) "" //"TIMEZONE_FIELD"
|
|
|
|
};
|
|
|
|
|
|
|
|
//Hashtable expected;// = new Hashtable();
|
|
|
|
//expected.put(new LongKey(DateFormat.MONTH_FIELD), "5");
|
|
|
|
//expected.put(new LongKey(DateFormat.DATE_FIELD), "3");
|
|
|
|
//expected.put(new LongKey(DateFormat.YEAR_FIELD), "97");
|
|
|
|
//expected.put(new LongKey(DateFormat.HOUR1_FIELD), "8");
|
|
|
|
//expected.put(new LongKey(DateFormat.MINUTE_FIELD), "55");
|
|
|
|
//expected.put(new LongKey(DateFormat.AM_PM_FIELD), "AM");
|
|
|
|
|
|
|
|
//StringBuffer buf = new StringBuffer();
|
|
|
|
UnicodeString fieldNames[] = {
|
|
|
|
(UnicodeString) "ERA_FIELD",
|
|
|
|
(UnicodeString) "YEAR_FIELD",
|
|
|
|
(UnicodeString) "MONTH_FIELD",
|
|
|
|
(UnicodeString) "DATE_FIELD",
|
|
|
|
(UnicodeString) "HOUR_OF_DAY1_FIELD",
|
|
|
|
(UnicodeString) "HOUR_OF_DAY0_FIELD",
|
|
|
|
(UnicodeString) "MINUTE_FIELD",
|
|
|
|
(UnicodeString) "SECOND_FIELD",
|
|
|
|
(UnicodeString) "MILLISECOND_FIELD",
|
|
|
|
(UnicodeString) "DAY_OF_WEEK_FIELD",
|
|
|
|
(UnicodeString) "DAY_OF_YEAR_FIELD",
|
|
|
|
(UnicodeString) "DAY_OF_WEEK_IN_MONTH_FIELD",
|
|
|
|
(UnicodeString) "WEEK_OF_YEAR_FIELD",
|
|
|
|
(UnicodeString) "WEEK_OF_MONTH_FIELD",
|
|
|
|
(UnicodeString) "AM_PM_FIELD",
|
|
|
|
(UnicodeString) "HOUR1_FIELD",
|
|
|
|
(UnicodeString) "HOUR0_FIELD",
|
|
|
|
(UnicodeString) "TIMEZONE_FIELD"
|
|
|
|
};
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool pass = TRUE;
|
1999-08-16 21:50:52 +00:00
|
|
|
for(int i = 0; i <= 17; ++i) {
|
|
|
|
FieldPosition pos(i);
|
|
|
|
UnicodeString buf;
|
|
|
|
fmt->format(dt, buf, pos);
|
|
|
|
//char[] dst = new char[pos.getEndIndex() - pos.getBeginIndex()];
|
|
|
|
UnicodeString dst;
|
2001-10-04 16:36:32 +00:00
|
|
|
buf.extractBetween(pos.getBeginIndex(), pos.getEndIndex(), dst);
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString str(dst);
|
2001-10-04 16:36:32 +00:00
|
|
|
logln((UnicodeString)"" + i + (UnicodeString)": " + fieldNames[i] +
|
|
|
|
(UnicodeString)", \"" + str + (UnicodeString)"\", " +
|
|
|
|
pos.getBeginIndex() + (UnicodeString)", " +
|
|
|
|
pos.getEndIndex());
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString exp = expected[i];
|
1999-12-08 02:11:04 +00:00
|
|
|
if((exp.length() == 0 && str.length() == 0) || str == exp)
|
1999-08-16 21:50:52 +00:00
|
|
|
logln(" ok");
|
|
|
|
else {
|
2002-04-11 18:36:11 +00:00
|
|
|
errln(UnicodeString(" expected ") + exp);
|
1999-08-16 21:50:52 +00:00
|
|
|
pass = FALSE;
|
|
|
|
}
|
2001-10-04 16:36:32 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
if( ! pass)
|
|
|
|
errln("Fail: FieldPosition not set right by DateFormat");
|
2001-10-04 16:36:32 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
delete fmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4056591
|
|
|
|
* Verify the function of the [s|g]et2DigitYearStart() API.
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4056591(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
//try {
|
2002-04-11 18:36:11 +00:00
|
|
|
SimpleDateFormat *fmt = new SimpleDateFormat(UnicodeString("yyMMdd"), Locale::getUS(), status);
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "new SimpleDateFormat");
|
2003-02-21 08:32:22 +00:00
|
|
|
UDate start = date(1809-1900, UCAL_DECEMBER, 25);
|
1999-08-16 21:50:52 +00:00
|
|
|
fmt->set2DigitYearStart(start, status);
|
|
|
|
failure(status, "fmt->setTwoDigitStartDate");
|
|
|
|
if( (fmt->get2DigitYearStart(status) != start) || failure(status, "get2DigitStartDate"))
|
|
|
|
errln("get2DigitYearStart broken");
|
|
|
|
UDate dates [] = {
|
2003-02-21 08:32:22 +00:00
|
|
|
date(1809-1900, UCAL_DECEMBER, 25),
|
|
|
|
date(1909-1900, UCAL_DECEMBER, 24),
|
|
|
|
date(1809-1900, UCAL_DECEMBER, 26),
|
|
|
|
date(1861-1900, UCAL_DECEMBER, 25),
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
UnicodeString strings [] = {
|
|
|
|
(UnicodeString) "091225",
|
|
|
|
(UnicodeString) "091224",
|
|
|
|
(UnicodeString) "091226",
|
|
|
|
(UnicodeString) "611225"
|
|
|
|
};
|
|
|
|
|
|
|
|
/*Object[] DATA = {
|
|
|
|
"091225", new Date(1809-1900, Calendar.DECEMBER, 25),
|
|
|
|
"091224", new Date(1909-1900, Calendar.DECEMBER, 24),
|
|
|
|
"091226", new Date(1809-1900, Calendar.DECEMBER, 26),
|
|
|
|
"611225", new Date(1861-1900, Calendar.DECEMBER, 25),
|
|
|
|
};*/
|
|
|
|
|
|
|
|
for(int i = 0; i < 4; i++) {
|
|
|
|
UnicodeString s = strings[i];
|
|
|
|
UDate exp = dates[i];
|
|
|
|
UDate got = fmt->parse(s, status);
|
|
|
|
failure(status, "fmt->parse");
|
|
|
|
logln(s + " -> " + got + "; exp " + exp);
|
|
|
|
if(got != exp)
|
|
|
|
errln("set2DigitYearStart broken");
|
|
|
|
}
|
|
|
|
/*}
|
|
|
|
catch (ParseException e) {
|
|
|
|
errln("Fail: " + e);
|
|
|
|
e.printStackTrace();
|
|
|
|
}*/
|
|
|
|
|
|
|
|
delete fmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4059917
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4059917(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
SimpleDateFormat *fmt;
|
|
|
|
UnicodeString myDate;
|
|
|
|
|
2000-04-15 21:28:17 +00:00
|
|
|
fmt = new SimpleDateFormat( UnicodeString("yyyy/MM/dd"), status );
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "new SimpleDateFormat");
|
|
|
|
myDate = "1997/01/01";
|
|
|
|
aux917( fmt, myDate );
|
|
|
|
|
|
|
|
delete fmt;
|
|
|
|
fmt = NULL;
|
|
|
|
|
2000-04-15 21:28:17 +00:00
|
|
|
fmt = new SimpleDateFormat( UnicodeString("yyyyMMdd"), status );
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "new SimpleDateFormat");
|
|
|
|
myDate = "19970101";
|
|
|
|
aux917( fmt, myDate );
|
|
|
|
|
|
|
|
delete fmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DateFormatRegressionTest::aux917( SimpleDateFormat *fmt, UnicodeString& str ) {
|
|
|
|
//try {
|
|
|
|
UnicodeString pat;
|
|
|
|
pat = fmt->toPattern(pat);
|
|
|
|
logln( "==================" );
|
|
|
|
logln( "testIt: pattern=" + pat +
|
|
|
|
" string=" + str );
|
|
|
|
|
|
|
|
|
|
|
|
Formattable o;
|
|
|
|
//Object o;
|
|
|
|
ParsePosition pos(0);
|
|
|
|
fmt->parseObject( str, o, pos );
|
|
|
|
//logln( UnicodeString("Parsed object: ") + o );
|
|
|
|
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString formatted;
|
|
|
|
FieldPosition poss(FieldPosition::DONT_CARE);
|
|
|
|
formatted = fmt->format( o, formatted, poss, status );
|
|
|
|
failure(status, "fmt->format");
|
|
|
|
logln( "Formatted string: " + formatted );
|
|
|
|
if( formatted != str)
|
|
|
|
errln("Fail: Want " + str + " Got " + formatted);
|
|
|
|
/*}
|
|
|
|
catch (ParseException e) {
|
|
|
|
errln("Fail: " + e);
|
|
|
|
e.printStackTrace();
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4060212
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4060212(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
UnicodeString dateString = "1995-040.05:01:29";
|
|
|
|
|
|
|
|
logln( "dateString= " + dateString );
|
|
|
|
logln("Using yyyy-DDD.hh:mm:ss");
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2000-04-15 21:28:17 +00:00
|
|
|
SimpleDateFormat *formatter = new SimpleDateFormat(UnicodeString("yyyy-DDD.hh:mm:ss"), status);
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "new SimpleDateFormat");
|
|
|
|
ParsePosition pos(0);
|
|
|
|
UDate myDate = formatter->parse( dateString, pos );
|
|
|
|
UnicodeString myString;
|
|
|
|
DateFormat *fmt = DateFormat::createDateTimeInstance( DateFormat::FULL,
|
|
|
|
DateFormat::LONG);
|
|
|
|
myString = fmt->format( myDate, myString);
|
|
|
|
logln( myString );
|
|
|
|
|
|
|
|
Calendar *cal = new GregorianCalendar(status);
|
|
|
|
failure(status, "new GregorianCalendar");
|
|
|
|
cal->setTime(myDate, status);
|
|
|
|
failure(status, "cal->setTime");
|
2003-02-21 08:32:22 +00:00
|
|
|
if ((cal->get(UCAL_DAY_OF_YEAR, status) != 40) || failure(status, "cal->get"))
|
|
|
|
errln((UnicodeString) "Fail: Got " + cal->get(UCAL_DAY_OF_YEAR, status) +
|
1999-08-16 21:50:52 +00:00
|
|
|
" Want 40");
|
|
|
|
|
|
|
|
logln("Using yyyy-ddd.hh:mm:ss");
|
|
|
|
delete formatter;
|
|
|
|
formatter = NULL;
|
2000-04-15 21:28:17 +00:00
|
|
|
formatter = new SimpleDateFormat(UnicodeString("yyyy-ddd.hh:mm:ss"), status);
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "new SimpleDateFormat");
|
|
|
|
pos.setIndex(0);
|
|
|
|
myDate = formatter->parse( dateString, pos );
|
|
|
|
myString = fmt->format( myDate, myString );
|
|
|
|
logln( myString );
|
|
|
|
cal->setTime(myDate, status);
|
|
|
|
failure(status, "cal->setTime");
|
2003-02-21 08:32:22 +00:00
|
|
|
if ((cal->get(UCAL_DAY_OF_YEAR, status) != 40) || failure(status, "cal->get"))
|
|
|
|
errln((UnicodeString) "Fail: Got " + cal->get(UCAL_DAY_OF_YEAR, status) +
|
1999-08-16 21:50:52 +00:00
|
|
|
" Want 40");
|
|
|
|
|
|
|
|
delete formatter;
|
|
|
|
delete fmt;
|
|
|
|
delete cal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4061287
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4061287(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-04-15 21:28:17 +00:00
|
|
|
SimpleDateFormat *df = new SimpleDateFormat(UnicodeString("dd/MM/yyyy"), status);
|
2003-06-06 04:54:34 +00:00
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Couldn't create SimpleDateFormat, error: %s", u_errorName(status));
|
|
|
|
delete df;
|
|
|
|
return;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "new SimpleDateFormat");
|
|
|
|
//try {
|
|
|
|
logln(UnicodeString("") + df->parse("35/01/1971", status));
|
|
|
|
failure(status, "df->parse");
|
|
|
|
//logln(df.parse("35/01/1971").toString());
|
|
|
|
//}
|
|
|
|
/*catch (ParseException e) {
|
|
|
|
errln("Fail: " + e);
|
|
|
|
e.printStackTrace();
|
|
|
|
}*/
|
|
|
|
df->setLenient(FALSE);
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool ok = FALSE;
|
1999-08-16 21:50:52 +00:00
|
|
|
//try {
|
|
|
|
logln(UnicodeString("") + df->parse("35/01/1971", status));
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
ok = TRUE;
|
|
|
|
//logln(df.parse("35/01/1971").toString());
|
|
|
|
//} catch (ParseException e) {ok=TRUE;}
|
|
|
|
if(!ok)
|
|
|
|
errln("Fail: Lenient not working");
|
2000-06-29 19:42:17 +00:00
|
|
|
delete df;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4065240
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4065240(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
UDate curDate;
|
|
|
|
DateFormat *shortdate, *fulldate;
|
|
|
|
UnicodeString strShortDate, strFullDate;
|
|
|
|
Locale saveLocale = Locale::getDefault();
|
|
|
|
TimeZone *saveZone = TimeZone::createDefault();
|
|
|
|
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
//try {
|
|
|
|
Locale *curLocale = new Locale("de","DE");
|
|
|
|
Locale::setDefault(*curLocale, status);
|
|
|
|
failure(status, "Locale::setDefault");
|
|
|
|
// {sfb} adoptDefault instead of setDefault
|
|
|
|
//TimeZone::setDefault(TimeZone::createTimeZone("EST"));
|
|
|
|
TimeZone::adoptDefault(TimeZone::createTimeZone("EST"));
|
|
|
|
curDate = date(98, 0, 1);
|
|
|
|
shortdate = DateFormat::createDateInstance(DateFormat::SHORT);
|
|
|
|
fulldate = DateFormat::createDateTimeInstance(DateFormat::LONG, DateFormat::LONG);
|
|
|
|
strShortDate = "The current date (short form) is ";
|
|
|
|
UnicodeString temp;
|
|
|
|
temp = shortdate->format(curDate, temp);
|
|
|
|
strShortDate += temp;
|
|
|
|
strFullDate = "The current date (long form) is ";
|
|
|
|
UnicodeString temp2;
|
|
|
|
fulldate->format(curDate, temp2);
|
|
|
|
strFullDate += temp2;
|
|
|
|
|
|
|
|
logln(strShortDate);
|
|
|
|
logln(strFullDate);
|
|
|
|
|
|
|
|
// {sfb} What to do with resource bundle stuff?????
|
|
|
|
|
|
|
|
// Check to see if the resource is present; if not, we can't test
|
|
|
|
ResourceBundle *bundle = new ResourceBundle(
|
1999-11-18 22:50:13 +00:00
|
|
|
u_getDataDirectory(), *curLocale, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "new ResourceBundle");
|
|
|
|
//(UnicodeString) "java.text.resources.DateFormatZoneData", curLocale);
|
|
|
|
|
|
|
|
// {sfb} API change to ResourceBundle -- add getLocale()
|
|
|
|
/*if (bundle->getLocale().getLanguage(temp) == UnicodeString("de")) {
|
|
|
|
// UPDATE THIS AS ZONE NAME RESOURCE FOR <EST> in de_DE is updated
|
|
|
|
if (!strFullDate.endsWith(UnicodeString("GMT-05:00")))
|
|
|
|
errln("Fail: Want GMT-05:00");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
logln("*** TEST COULD NOT BE COMPLETED BECAUSE DateFormatZoneData ***");
|
|
|
|
logln("*** FOR LOCALE de OR de_DE IS MISSING ***");
|
|
|
|
}*/
|
|
|
|
//}
|
|
|
|
//finally {
|
|
|
|
Locale::setDefault(saveLocale, status);
|
|
|
|
failure(status, "Locale::setDefault");
|
|
|
|
TimeZone::setDefault(*saveZone);
|
|
|
|
//}
|
|
|
|
|
2000-06-29 19:42:17 +00:00
|
|
|
delete shortdate;
|
|
|
|
delete fulldate;
|
1999-08-16 21:50:52 +00:00
|
|
|
delete saveZone;
|
2000-06-29 19:42:17 +00:00
|
|
|
delete curLocale;
|
|
|
|
delete bundle;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
DateFormat.equals is too narrowly defined. As a result, MessageFormat
|
|
|
|
does not work correctly. DateFormat.equals needs to be written so
|
|
|
|
that the Calendar sub-object is not compared using Calendar.equals,
|
|
|
|
but rather compared for equivalency. This may necessitate adding a
|
|
|
|
(package private) method to Calendar to test for equivalency.
|
|
|
|
|
|
|
|
Currently this bug breaks MessageFormat.toPattern
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @bug 4071441
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4071441(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
DateFormat *fmtA = DateFormat::createInstance();
|
|
|
|
DateFormat *fmtB = DateFormat::createInstance();
|
|
|
|
|
|
|
|
// {sfb} Is it OK to cast away const here?
|
|
|
|
Calendar *calA = (Calendar*) fmtA->getCalendar();
|
|
|
|
Calendar *calB = (Calendar*) fmtB->getCalendar();
|
2003-06-06 04:54:34 +00:00
|
|
|
if(!calA || !calB) {
|
|
|
|
errln("Couldn't get proper calendars, exiting");
|
|
|
|
delete fmtA;
|
|
|
|
delete fmtB;
|
|
|
|
return;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
UDate epoch = date(0, 0, 0);
|
2003-02-21 08:32:22 +00:00
|
|
|
UDate xmas = date(61, UCAL_DECEMBER, 25);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
calA->setTime(epoch, status);
|
|
|
|
failure(status, "calA->setTime");
|
|
|
|
calB->setTime(epoch, status);
|
|
|
|
failure(status, "calB->setTime");
|
|
|
|
if (*calA != *calB)
|
|
|
|
errln("Fail: Can't complete test; Calendar instances unequal");
|
|
|
|
if (*fmtA != *fmtB)
|
|
|
|
errln("Fail: DateFormat unequal when Calendars equal");
|
|
|
|
calB->setTime(xmas, status);
|
|
|
|
failure(status, "calB->setTime");
|
|
|
|
if (*calA == *calB)
|
|
|
|
errln("Fail: Can't complete test; Calendar instances equal");
|
2002-08-21 18:34:14 +00:00
|
|
|
if (*fmtA != *fmtB)
|
1999-08-16 21:50:52 +00:00
|
|
|
errln("Fail: DateFormat unequal when Calendars equivalent");
|
2002-08-21 18:34:14 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
logln("DateFormat.equals ok");
|
|
|
|
|
|
|
|
delete fmtA;
|
|
|
|
delete fmtB;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The java.text.DateFormat.parse(String) method expects for the
|
|
|
|
US locale a string formatted according to mm/dd/yy and parses it
|
|
|
|
correctly.
|
|
|
|
|
|
|
|
When given a string mm/dd/yyyy it only parses up to the first
|
|
|
|
two y's, typically resulting in a date in the year 1919.
|
|
|
|
|
|
|
|
Please extend the parsing method(s) to handle strings with
|
|
|
|
four-digit year values (probably also applicable to various
|
|
|
|
other locales. */
|
|
|
|
/**
|
|
|
|
* @bug 4073003
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4073003(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
//try {
|
2003-03-14 00:46:33 +00:00
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
SimpleDateFormat fmt("dd/MM/yy", Locale::getUK(), ec);
|
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
errln("FAIL: SimpleDateFormat constructor");
|
|
|
|
return;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString tests [] = {
|
|
|
|
(UnicodeString) "12/25/61",
|
|
|
|
(UnicodeString) "12/25/1961",
|
|
|
|
(UnicodeString) "4/3/2010",
|
|
|
|
(UnicodeString) "4/3/10"
|
|
|
|
};
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
for(int i= 0; i < 4; i+=2) {
|
2003-03-14 00:46:33 +00:00
|
|
|
UDate d = fmt.parse(tests[i], status);
|
|
|
|
failure(status, "fmt.parse");
|
|
|
|
UDate dd = fmt.parse(tests[i+1], status);
|
|
|
|
failure(status, "fmt.parse");
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString s;
|
2003-03-14 00:46:33 +00:00
|
|
|
s = fmt.format(d, s);
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString ss;
|
2003-03-14 00:46:33 +00:00
|
|
|
ss = fmt.format(dd, ss);
|
1999-08-16 21:50:52 +00:00
|
|
|
if (d != dd)
|
|
|
|
errln((UnicodeString) "Fail: " + d + " != " + dd);
|
|
|
|
if (s != ss)
|
|
|
|
errln((UnicodeString)"Fail: " + s + " != " + ss);
|
|
|
|
logln("Ok: " + s + " " + d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4089106
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4089106(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
TimeZone *def = TimeZone::createDefault();
|
|
|
|
//try {
|
|
|
|
TimeZone *z = new SimpleTimeZone((int)(1.25 * 3600000), "FAKEZONE");
|
|
|
|
TimeZone::setDefault(*z);
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
SimpleDateFormat *f = new SimpleDateFormat(status);
|
2003-06-06 04:54:34 +00:00
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Couldn't create SimpleDateFormat, error %s", u_errorName(status));
|
|
|
|
delete f;
|
|
|
|
delete def;
|
|
|
|
delete z;
|
|
|
|
return;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "new SimpleDateFormat");
|
|
|
|
if (f->getTimeZone()!= *z)
|
|
|
|
errln("Fail: SimpleTimeZone should use TimeZone.getDefault()");
|
|
|
|
|
|
|
|
//}
|
|
|
|
//finally {
|
|
|
|
TimeZone::setDefault(*def);
|
|
|
|
//}
|
|
|
|
|
|
|
|
delete z;
|
|
|
|
delete f;
|
|
|
|
delete def;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4100302
|
|
|
|
*/
|
|
|
|
|
|
|
|
// {sfb} not applicable in C++??
|
|
|
|
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4100302(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
/* Locale locales [] = {
|
|
|
|
Locale::CANADA,
|
|
|
|
Locale::CANADA_FRENCH,
|
|
|
|
Locale::CHINA,
|
|
|
|
Locale::CHINESE,
|
|
|
|
Locale::ENGLISH,
|
|
|
|
Locale::FRANCE,
|
|
|
|
Locale::FRENCH,
|
|
|
|
Locale::GERMAN,
|
|
|
|
Locale::GERMANY,
|
|
|
|
Locale::ITALIAN,
|
|
|
|
Locale::ITALY,
|
|
|
|
Locale::JAPAN,
|
|
|
|
Locale::JAPANESE,
|
|
|
|
Locale::KOREA,
|
|
|
|
Locale::KOREAN,
|
|
|
|
Locale::PRC,
|
|
|
|
Locale::SIMPLIFIED_CHINESE,
|
|
|
|
Locale::TAIWAN,
|
|
|
|
Locale::TRADITIONAL_CHINESE,
|
|
|
|
Locale::UK,
|
|
|
|
Locale::US
|
|
|
|
};
|
|
|
|
//try {
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool pass = TRUE;
|
1999-08-16 21:50:52 +00:00
|
|
|
for(int i = 0; i < 21; i++) {
|
|
|
|
|
|
|
|
Format *format = DateFormat::createDateTimeInstance(DateFormat::FULL,
|
|
|
|
DateFormat::FULL, locales[i]);
|
|
|
|
byte[] bytes;
|
|
|
|
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
|
|
|
|
|
|
|
oos.writeObject(format);
|
|
|
|
oos.flush();
|
|
|
|
|
|
|
|
baos.close();
|
|
|
|
bytes = baos.toByteArray();
|
|
|
|
|
|
|
|
ObjectInputStream ois =
|
|
|
|
new ObjectInputStream(new ByteArrayInputStream(bytes));
|
|
|
|
|
|
|
|
if (!format.equals(ois.readObject())) {
|
|
|
|
pass = FALSE;
|
|
|
|
logln("DateFormat instance for locale " +
|
|
|
|
locales[i] + " is incorrectly serialized/deserialized.");
|
|
|
|
} else {
|
|
|
|
logln("DateFormat instance for locale " +
|
|
|
|
locales[i] + " is OKAY.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!pass) errln("Fail: DateFormat serialization/equality bug");
|
|
|
|
}
|
|
|
|
catch (IOException e) {
|
|
|
|
errln("Fail: " + e);
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
catch (ClassNotFoundException e) {
|
|
|
|
errln("Fail: " + e);
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
*/}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4101483
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4101483(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2002-04-11 18:36:11 +00:00
|
|
|
SimpleDateFormat *sdf = new SimpleDateFormat(UnicodeString("z"), Locale::getUS(), status);
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "new SimpleDateFormat");
|
2004-03-11 14:05:33 +00:00
|
|
|
FieldPosition fp(UDAT_TIMEZONE_FIELD);
|
1999-08-16 21:50:52 +00:00
|
|
|
//Date d = date(9234567890L);
|
|
|
|
UDate d = 9234567890.0;
|
|
|
|
//StringBuffer buf = new StringBuffer("");
|
|
|
|
UnicodeString buf;
|
|
|
|
sdf->format(d, buf, fp);
|
|
|
|
//logln(sdf.format(d, buf, fp).toString());
|
|
|
|
logln(dateToString(d) + " => " + buf);
|
|
|
|
logln("beginIndex = " + fp.getBeginIndex());
|
|
|
|
logln("endIndex = " + fp.getEndIndex());
|
|
|
|
if (fp.getBeginIndex() == fp.getEndIndex())
|
|
|
|
errln("Fail: Empty field");
|
|
|
|
|
|
|
|
delete sdf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4103340
|
|
|
|
* @bug 4138203
|
|
|
|
* This bug really only works in Locale.US, since that's what the locale
|
|
|
|
* used for Date.toString() is. Bug 4138203 reports that it fails on Korean
|
|
|
|
* NT; it would actually have failed on any non-US locale. Now it should
|
|
|
|
* work on all locales.
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4103340(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// choose a date that is the FIRST of some month
|
|
|
|
// and some arbitrary time
|
|
|
|
UDate d = date(97, 3, 1, 1, 1, 1);
|
2002-04-11 18:36:11 +00:00
|
|
|
SimpleDateFormat *df = new SimpleDateFormat(UnicodeString("MMMM"), Locale::getUS(), status);
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "new SimpleDateFormat");
|
|
|
|
|
|
|
|
UnicodeString s;
|
|
|
|
s = dateToString(d, s);
|
|
|
|
UnicodeString s2;
|
|
|
|
FieldPosition pos(FieldPosition::DONT_CARE);
|
|
|
|
s2 = df->format(d, s2, pos);
|
|
|
|
logln("Date=" + s);
|
|
|
|
logln("DF=" + s2);
|
|
|
|
UnicodeString substr;
|
|
|
|
s2.extract(0,2, substr);
|
|
|
|
if (s.indexOf(substr) == -1)
|
|
|
|
errln("Months should match");
|
|
|
|
|
|
|
|
delete df;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4103341
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4103341(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
TimeZone *saveZone =TimeZone::createDefault();
|
|
|
|
//try {
|
|
|
|
|
|
|
|
// {sfb} changed from setDefault to adoptDefault
|
|
|
|
TimeZone::adoptDefault(TimeZone::createTimeZone("CST"));
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2000-04-15 21:28:17 +00:00
|
|
|
SimpleDateFormat *simple = new SimpleDateFormat(UnicodeString("MM/dd/yyyy HH:mm"), status);
|
2003-06-06 04:54:34 +00:00
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Couldn't create SimpleDateFormat, error %s", u_errorName(status));
|
|
|
|
delete simple;
|
|
|
|
return;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "new SimpleDateFormat");
|
|
|
|
TimeZone *temp = TimeZone::createDefault();
|
|
|
|
if(simple->getTimeZone() != *temp)
|
|
|
|
errln("Fail: SimpleDateFormat not using default zone");
|
|
|
|
//}
|
|
|
|
//finally {
|
|
|
|
TimeZone::adoptDefault(saveZone);
|
|
|
|
//}
|
|
|
|
|
|
|
|
delete temp;
|
|
|
|
delete simple;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4104136
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4104136(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
SimpleDateFormat *sdf = new SimpleDateFormat(status);
|
2003-06-06 04:54:34 +00:00
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Couldn't create SimpleDateFormat, error %s", u_errorName(status));
|
|
|
|
delete sdf;
|
|
|
|
return;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "new SimpleDateFormat");
|
|
|
|
UnicodeString pattern = "'time' hh:mm";
|
|
|
|
sdf->applyPattern(pattern);
|
|
|
|
logln("pattern: \"" + pattern + "\"");
|
|
|
|
|
|
|
|
UnicodeString strings [] = {
|
|
|
|
(UnicodeString)"time 10:30",
|
|
|
|
(UnicodeString) "time 10:x",
|
|
|
|
(UnicodeString) "time 10x"
|
|
|
|
};
|
|
|
|
|
|
|
|
ParsePosition ppos [] = {
|
|
|
|
ParsePosition(10),
|
|
|
|
ParsePosition(0),
|
|
|
|
ParsePosition(0)
|
|
|
|
};
|
|
|
|
|
|
|
|
UDate dates [] = {
|
2003-02-21 08:32:22 +00:00
|
|
|
date(70, UCAL_JANUARY, 1, 10, 30),
|
1999-08-16 21:50:52 +00:00
|
|
|
-1,
|
|
|
|
-1
|
|
|
|
};
|
|
|
|
|
|
|
|
/*Object[] DATA = {
|
|
|
|
"time 10:30", new ParsePosition(10), new Date(70, Calendar.JANUARY, 1, 10, 30),
|
|
|
|
"time 10:x", new ParsePosition(0), null,
|
|
|
|
"time 10x", new ParsePosition(0), null,
|
|
|
|
};*/
|
|
|
|
|
|
|
|
for(int i = 0; i < 3; i++) {
|
|
|
|
UnicodeString text = strings[i];
|
|
|
|
ParsePosition finish = ppos[i];
|
|
|
|
UDate exp = dates[i];
|
|
|
|
|
|
|
|
ParsePosition pos(0);
|
|
|
|
UDate d = sdf->parse(text, pos);
|
|
|
|
logln(" text: \"" + text + "\"");
|
2001-05-26 01:23:28 +00:00
|
|
|
logln(" index: %d", pos.getIndex());
|
1999-08-16 21:50:52 +00:00
|
|
|
logln((UnicodeString) " result: " + d);
|
|
|
|
if(pos.getIndex() != finish.getIndex())
|
|
|
|
errln("Fail: Expected pos " + finish.getIndex());
|
|
|
|
if (! ((d == 0 && exp == -1) || (d == exp)))
|
|
|
|
errln((UnicodeString) "Fail: Expected result " + exp);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete sdf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4104522
|
|
|
|
* CANNOT REPRODUCE
|
|
|
|
* According to the bug report, this test should throw a
|
|
|
|
* StringIndexOutOfBoundsException during the second parse. However,
|
|
|
|
* this is not seen.
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4104522(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
SimpleDateFormat *sdf = new SimpleDateFormat(status);
|
2003-06-06 04:54:34 +00:00
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Couldn't create SimpleDateFormat, error %s", u_errorName(status));
|
|
|
|
delete sdf;
|
|
|
|
return;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "new SimpleDateFormat");
|
|
|
|
UnicodeString pattern = "'time' hh:mm";
|
|
|
|
sdf->applyPattern(pattern);
|
|
|
|
logln("pattern: \"" + pattern + "\"");
|
|
|
|
|
|
|
|
// works correctly
|
|
|
|
ParsePosition pp(0);
|
|
|
|
UnicodeString text = "time ";
|
|
|
|
UDate dt = sdf->parse(text, pp);
|
|
|
|
logln(" text: \"" + text + "\"" +
|
|
|
|
" date: " + dt);
|
|
|
|
|
|
|
|
// works wrong
|
|
|
|
pp.setIndex(0);
|
|
|
|
text = "time";
|
|
|
|
dt = sdf->parse(text, pp);
|
|
|
|
logln(" text: \"" + text + "\"" +
|
|
|
|
" date: " + dt);
|
2000-06-29 19:42:17 +00:00
|
|
|
|
|
|
|
delete sdf;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4106807
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4106807(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
UDate dt;
|
|
|
|
DateFormat *df = DateFormat::createDateTimeInstance();
|
|
|
|
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
SimpleDateFormat *sdfs [] = {
|
2000-04-15 21:28:17 +00:00
|
|
|
new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss"), status),
|
|
|
|
new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss'Z'"), status),
|
|
|
|
new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss''"), status),
|
|
|
|
new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss'a''a'"), status),
|
|
|
|
new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss %"), status)
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
2003-06-06 04:54:34 +00:00
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Couldn't create SimpleDateFormat, error %s", u_errorName(status));
|
|
|
|
delete sdfs[0];
|
|
|
|
delete sdfs[1];
|
|
|
|
delete sdfs[2];
|
|
|
|
delete sdfs[3];
|
|
|
|
delete sdfs[4];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "new SimpleDateFormat");
|
|
|
|
|
|
|
|
UnicodeString strings [] = {
|
|
|
|
(UnicodeString) "19980211140000",
|
|
|
|
(UnicodeString) "19980211140000",
|
|
|
|
(UnicodeString) "19980211140000",
|
|
|
|
(UnicodeString) "19980211140000a",
|
|
|
|
(UnicodeString) "19980211140000 "
|
|
|
|
};
|
|
|
|
|
|
|
|
/*Object[] data = {
|
|
|
|
new SimpleDateFormat("yyyyMMddHHmmss"), "19980211140000",
|
|
|
|
new SimpleDateFormat("yyyyMMddHHmmss'Z'"), "19980211140000",
|
|
|
|
new SimpleDateFormat("yyyyMMddHHmmss''"), "19980211140000",
|
|
|
|
new SimpleDateFormat("yyyyMMddHHmmss'a''a'"), "19980211140000a",
|
|
|
|
new SimpleDateFormat("yyyyMMddHHmmss %"), "19980211140000 ",
|
|
|
|
};*/
|
|
|
|
GregorianCalendar *gc = new GregorianCalendar(status);
|
|
|
|
failure(status, "new GregorianCalendar");
|
|
|
|
TimeZone *timeZone = TimeZone::createDefault();
|
|
|
|
|
|
|
|
TimeZone *gmt = timeZone->clone();
|
|
|
|
|
|
|
|
gmt->setRawOffset(0);
|
|
|
|
|
|
|
|
for(int32_t i = 0; i < 5; i++) {
|
|
|
|
SimpleDateFormat *format = sdfs[i];
|
|
|
|
UnicodeString dateString = strings[i];
|
|
|
|
//try {
|
|
|
|
format->setTimeZone(*gmt);
|
|
|
|
dt = format->parse(dateString, status);
|
|
|
|
// {sfb} some of these parses will fail purposely
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
1999-10-07 00:07:53 +00:00
|
|
|
status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString fmtd;
|
|
|
|
FieldPosition pos(FieldPosition::DONT_CARE);
|
|
|
|
fmtd = df->format(dt, fmtd, pos);
|
|
|
|
logln(fmtd);
|
|
|
|
//logln(df->format(dt));
|
|
|
|
gc->setTime(dt, status);
|
|
|
|
failure(status, "gc->getTime");
|
2003-02-21 08:32:22 +00:00
|
|
|
logln(UnicodeString("") + gc->get(UCAL_ZONE_OFFSET, status));
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "gc->get");
|
|
|
|
UnicodeString s;
|
|
|
|
s = format->format(dt, s, pos);
|
|
|
|
logln(s);
|
|
|
|
/*}
|
|
|
|
catch (ParseException e) {
|
|
|
|
logln("No way Jose");
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
delete timeZone;
|
|
|
|
delete df;
|
|
|
|
for(int32_t j = 0; j < 5; j++)
|
|
|
|
delete sdfs [j];
|
|
|
|
delete gc;
|
|
|
|
delete gmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Synopsis: Chinese time zone CTT is not recogonized correctly.
|
|
|
|
Description: Platform Chinese Windows 95 - ** Time zone set to CST **
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @bug 4108407
|
|
|
|
*/
|
|
|
|
|
|
|
|
// {sfb} what to do with this one ??
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4108407(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
/*long l = System.currentTimeMillis();
|
|
|
|
logln("user.timezone = " + System.getProperty("user.timezone", "?"));
|
|
|
|
logln("Time Zone :" +
|
|
|
|
DateFormat.getDateInstance().getTimeZone().getID());
|
|
|
|
logln("Default format :" +
|
|
|
|
DateFormat.getDateInstance().format(new Date(l)));
|
|
|
|
logln("Full format :" +
|
|
|
|
DateFormat.getDateInstance(DateFormat.FULL).format(new
|
|
|
|
Date(l)));
|
|
|
|
logln("*** Set host TZ to CST ***");
|
|
|
|
logln("*** THE RESULTS OF THIS TEST MUST BE VERIFIED MANUALLY ***");*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4134203
|
|
|
|
* SimpleDateFormat won't parse "GMT"
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4134203(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString dateFormat = "MM/dd/yy HH:mm:ss zzz";
|
|
|
|
SimpleDateFormat *fmt = new SimpleDateFormat(dateFormat, status);
|
|
|
|
failure(status, "new SimpleDateFormat");
|
|
|
|
ParsePosition p0(0);
|
|
|
|
UDate d = fmt->parse("01/22/92 04:52:00 GMT", p0);
|
|
|
|
logln(dateToString(d));
|
|
|
|
if(p0 == ParsePosition(0))
|
|
|
|
errln("Fail: failed to parse 'GMT'");
|
|
|
|
// In the failure case an exception is thrown by parse();
|
|
|
|
// if no exception is thrown, the test passes.
|
|
|
|
|
|
|
|
delete fmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4151631
|
|
|
|
* SimpleDateFormat incorrect handling of 2 single quotes in format()
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4151631(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
UnicodeString pattern = "'TO_DATE('''dd'-'MM'-'yyyy HH:mm:ss''' , ''DD-MM-YYYY HH:MI:SS'')'";
|
|
|
|
logln("pattern=" + pattern);
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2002-04-11 18:36:11 +00:00
|
|
|
SimpleDateFormat *format = new SimpleDateFormat(pattern, Locale::getUS(), status);
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "new SimpleDateFormat");
|
|
|
|
UnicodeString result;
|
|
|
|
FieldPosition pos(FieldPosition::DONT_CARE);
|
2003-02-21 08:32:22 +00:00
|
|
|
result = format->format(date(1998-1900, UCAL_JUNE, 30, 13, 30, 0), result, pos);
|
1999-08-16 21:50:52 +00:00
|
|
|
if (result != "TO_DATE('30-06-1998 13:30:00' , 'DD-MM-YYYY HH:MI:SS')") {
|
|
|
|
errln("Fail: result=" + result);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
logln("Pass: result=" + result);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete format;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4151706
|
|
|
|
* 'z' at end of date format throws index exception in SimpleDateFormat
|
|
|
|
* CANNOT REPRODUCE THIS BUG ON 1.2FCS
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4151706(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-03-28 02:36:14 +00:00
|
|
|
UnicodeString dateString("Thursday, 31-Dec-98 23:00:00 GMT");
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2002-04-11 18:36:11 +00:00
|
|
|
SimpleDateFormat fmt(UnicodeString("EEEE, dd-MMM-yy HH:mm:ss z"), Locale::getUS(), status);
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "new SimpleDateFormat");
|
|
|
|
//try {
|
2001-03-28 02:36:14 +00:00
|
|
|
UDate d = fmt.parse(dateString, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
failure(status, "fmt->parse");
|
|
|
|
// {sfb} what about next two lines?
|
|
|
|
//if (d.getTime() != Date.UTC(1998-1900, Calendar.DECEMBER, 31, 23, 0, 0))
|
|
|
|
// errln("Incorrect value: " + d);
|
|
|
|
/*} catch (Exception e) {
|
|
|
|
errln("Fail: " + e);
|
|
|
|
}*/
|
2001-03-28 02:36:14 +00:00
|
|
|
UnicodeString temp;
|
|
|
|
FieldPosition pos(0);
|
|
|
|
logln(dateString + " -> " + fmt.format(d, temp, pos));
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bug 4162071
|
|
|
|
* Cannot reproduce this bug under 1.2 FCS -- it may be a convoluted duplicate
|
|
|
|
* of some other bug that has been fixed.
|
|
|
|
*/
|
|
|
|
void
|
1999-12-22 22:57:04 +00:00
|
|
|
DateFormatRegressionTest::Test4162071(void)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
UnicodeString dateString("Thu, 30-Jul-1999 11:51:14 GMT");
|
|
|
|
UnicodeString format("EEE', 'dd-MMM-yyyy HH:mm:ss z"); // RFC 822/1123
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2002-04-11 18:36:11 +00:00
|
|
|
SimpleDateFormat df(format, Locale::getUS(), status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
errln("Couldn't create SimpleDateFormat");
|
|
|
|
|
|
|
|
//try {
|
|
|
|
UDate x = df.parse(dateString, status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_SUCCESS(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
logln("Parse format \"" + format + "\" ok");
|
|
|
|
else
|
|
|
|
errln("Parse format \"" + format + "\" failed.");
|
|
|
|
UnicodeString temp;
|
|
|
|
FieldPosition pos(0);
|
|
|
|
logln(dateString + " -> " + df.format(x, temp, pos));
|
|
|
|
//} catch (Exception e) {
|
|
|
|
// errln("Parse format \"" + format + "\" failed.");
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
1999-10-15 23:16:58 +00:00
|
|
|
/**
|
|
|
|
* DateFormat shouldn't parse year "-1" as a two-digit year (e.g., "-1" -> 1999).
|
|
|
|
*/
|
1999-12-22 22:57:04 +00:00
|
|
|
void DateFormatRegressionTest::Test4182066(void) {
|
1999-10-15 23:16:58 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2002-04-11 18:36:11 +00:00
|
|
|
SimpleDateFormat fmt("MM/dd/yy", Locale::getUS(), status);
|
|
|
|
SimpleDateFormat dispFmt("MMM dd yyyy GG", Locale::getUS(), status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status)) {
|
1999-10-15 23:16:58 +00:00
|
|
|
errln("Couldn't create SimpleDateFormat");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We expect 2-digit year formats to put 2-digit years in the right
|
|
|
|
* window. Out of range years, that is, anything less than "00" or
|
|
|
|
* greater than "99", are treated as literal years. So "1/2/3456"
|
|
|
|
* becomes 3456 AD. Likewise, "1/2/-3" becomes -3 AD == 2 BC.
|
|
|
|
*/
|
|
|
|
const char* STRINGS[] = {
|
|
|
|
"02/29/00",
|
|
|
|
"01/23/01",
|
|
|
|
"04/05/-1",
|
|
|
|
"01/23/-9",
|
|
|
|
"11/12/1314",
|
|
|
|
"10/31/1",
|
|
|
|
"09/12/+1",
|
|
|
|
"09/12/001",
|
|
|
|
};
|
2001-05-22 16:54:15 +00:00
|
|
|
int32_t STRINGS_COUNT = (int32_t)(sizeof(STRINGS) / sizeof(STRINGS[0]));
|
1999-10-15 23:16:58 +00:00
|
|
|
UDate FAIL_DATE = (UDate) 0;
|
|
|
|
UDate DATES[] = {
|
2003-02-21 08:32:22 +00:00
|
|
|
date(2000-1900, UCAL_FEBRUARY, 29),
|
|
|
|
date(2001-1900, UCAL_JANUARY, 23),
|
|
|
|
date( -1-1900, UCAL_APRIL, 5),
|
|
|
|
date( -9-1900, UCAL_JANUARY, 23),
|
|
|
|
date(1314-1900, UCAL_NOVEMBER, 12),
|
|
|
|
date( 1-1900, UCAL_OCTOBER, 31),
|
1999-10-15 23:16:58 +00:00
|
|
|
FAIL_DATE, // "+1" isn't recognized by US NumberFormat
|
2003-02-21 08:32:22 +00:00
|
|
|
date( 1-1900, UCAL_SEPTEMBER,12),
|
1999-10-15 23:16:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
UnicodeString out;
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool pass = TRUE;
|
1999-10-15 23:16:58 +00:00
|
|
|
for (int32_t i=0; i<STRINGS_COUNT; ++i) {
|
|
|
|
UnicodeString str(STRINGS[i]);
|
|
|
|
UDate expected = DATES[i];
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
UDate actual = fmt.parse(str, status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status)) {
|
1999-10-15 23:16:58 +00:00
|
|
|
actual = FAIL_DATE;
|
|
|
|
}
|
|
|
|
UnicodeString actStr;
|
|
|
|
if (actual == FAIL_DATE) {
|
|
|
|
actStr.append("null");
|
|
|
|
} else {
|
|
|
|
// Yuck: See j25
|
|
|
|
((DateFormat*)&dispFmt)->format(actual, actStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expected == actual) {
|
|
|
|
out.append(str + " => " + actStr + "\n");
|
|
|
|
} else {
|
|
|
|
UnicodeString expStr;
|
|
|
|
if (expected == FAIL_DATE) {
|
|
|
|
expStr.append("null");
|
|
|
|
} else {
|
|
|
|
// Yuck: See j25
|
|
|
|
((DateFormat*)&dispFmt)->format(expected, expStr);
|
|
|
|
}
|
|
|
|
out.append("FAIL: " + str + " => " + actStr
|
|
|
|
+ ", expected " + expStr + "\n");
|
|
|
|
pass = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pass) {
|
|
|
|
log(out);
|
|
|
|
} else {
|
|
|
|
err(out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-16 01:35:16 +00:00
|
|
|
/**
|
|
|
|
* j32 {JDK Bug 4210209 4209272}
|
|
|
|
* DateFormat cannot parse Feb 29 2000 when setLenient(false)
|
|
|
|
*/
|
|
|
|
void
|
1999-12-22 22:57:04 +00:00
|
|
|
DateFormatRegressionTest::Test4210209(void) {
|
1999-10-16 01:35:16 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UnicodeString pattern("MMM d, yyyy");
|
2002-04-11 18:36:11 +00:00
|
|
|
SimpleDateFormat sfmt(pattern, Locale::getUS(), status);
|
|
|
|
SimpleDateFormat sdisp("MMM dd yyyy GG", Locale::getUS(), status);
|
1999-10-16 01:35:16 +00:00
|
|
|
DateFormat& fmt = *(DateFormat*)&sfmt; // Yuck: See j25
|
|
|
|
DateFormat& disp = *(DateFormat*)&sdisp; // Yuck: See j25
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status)) {
|
1999-10-16 01:35:16 +00:00
|
|
|
errln("Couldn't create SimpleDateFormat");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Calendar* calx = (Calendar*)fmt.getCalendar(); // cast away const!
|
|
|
|
calx->setLenient(FALSE);
|
2003-02-21 08:32:22 +00:00
|
|
|
UDate d = date(2000-1900, UCAL_FEBRUARY, 29);
|
1999-10-16 01:35:16 +00:00
|
|
|
UnicodeString s, ss;
|
|
|
|
fmt.format(d, s);
|
|
|
|
logln(disp.format(d, ss.remove()) + " f> " + pattern +
|
|
|
|
" => \"" + s + "\"");
|
|
|
|
ParsePosition pos(0);
|
|
|
|
d = fmt.parse(s, pos);
|
|
|
|
logln(UnicodeString("\"") + s + "\" p> " + pattern +
|
|
|
|
" => " + disp.format(d, ss.remove()));
|
|
|
|
logln(UnicodeString("Parse pos = ") + pos.getIndex() +
|
|
|
|
", error pos = " + pos.getErrorIndex());
|
|
|
|
if (pos.getErrorIndex() != -1) {
|
|
|
|
errln(UnicodeString("FAIL: Error index should be -1"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// The underlying bug is in GregorianCalendar. If the following lines
|
|
|
|
// succeed, the bug is fixed. If the bug isn't fixed, they will throw
|
|
|
|
// an exception.
|
|
|
|
GregorianCalendar cal(status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status)) {
|
1999-10-16 01:35:16 +00:00
|
|
|
errln("FAIL: Unable to create Calendar");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cal.clear();
|
|
|
|
cal.setLenient(FALSE);
|
2003-02-21 08:32:22 +00:00
|
|
|
cal.set(2000, UCAL_FEBRUARY, 29); // This should work!
|
1999-10-16 01:35:16 +00:00
|
|
|
logln(UnicodeString("Attempt to set Calendar to Feb 29 2000: ") +
|
|
|
|
disp.format(cal.getTime(status), ss.remove()));
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status)) {
|
1999-10-16 01:35:16 +00:00
|
|
|
errln("FAIL: Unable to set Calendar to Feb 29 2000");
|
|
|
|
}
|
|
|
|
}
|
1999-10-15 23:16:58 +00:00
|
|
|
|
2000-11-13 21:03:06 +00:00
|
|
|
void DateFormatRegressionTest::Test714(void)
|
|
|
|
{
|
|
|
|
//try {
|
|
|
|
UDate d(978103543000.);
|
|
|
|
DateFormat *fmt = DateFormat::createDateTimeInstance(DateFormat::NONE,
|
|
|
|
DateFormat::MEDIUM,
|
2002-04-11 18:36:11 +00:00
|
|
|
Locale::getUS());
|
2000-11-13 21:03:06 +00:00
|
|
|
UnicodeString s;
|
|
|
|
UnicodeString tests =
|
|
|
|
(UnicodeString) "7:25:43 AM" ;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
fmt->format (d,s);
|
|
|
|
if(U_FAILURE(status))
|
|
|
|
{
|
|
|
|
errln((UnicodeString) "Fail, errmsg " + u_errorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(s != tests)
|
|
|
|
{
|
|
|
|
errln((UnicodeString) "Fail: " + s + " != " + tests);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
logln("OK: " + s + " == " + tests);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete fmt;
|
|
|
|
}
|
|
|
|
|
2003-06-06 01:48:24 +00:00
|
|
|
class Test1684Data {
|
|
|
|
public:
|
|
|
|
int32_t year;
|
|
|
|
int32_t month;
|
|
|
|
int32_t date;
|
|
|
|
int32_t womyear;
|
|
|
|
int32_t wommon;
|
|
|
|
int32_t wom;
|
|
|
|
int32_t dow;
|
|
|
|
UnicodeString data;
|
|
|
|
UnicodeString normalized;
|
|
|
|
|
|
|
|
Test1684Data(int32_t xyear, int32_t xmonth, int32_t xdate,
|
|
|
|
int32_t xwomyear, int32_t xwommon, int32_t xwom, int32_t xdow,
|
|
|
|
const char *xdata, const char *xnormalized) :
|
|
|
|
year(xyear),
|
|
|
|
month(xmonth-1),
|
|
|
|
date(xdate),
|
|
|
|
womyear(xwomyear),
|
|
|
|
wommon(xwommon-1),
|
|
|
|
wom(xwom),
|
|
|
|
dow(xdow),
|
|
|
|
data(xdata,""),
|
|
|
|
normalized((xnormalized==NULL)?xdata:xnormalized,"")
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
void DateFormatRegressionTest::Test1684(void)
|
|
|
|
{
|
|
|
|
// July 2001 August 2001 January 2002
|
|
|
|
// Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
|
|
|
|
// 1 2 3 4 5 6 7 1 2 3 4 1 2 3 4 5
|
|
|
|
// 8 9 10 11 12 13 14 5 6 7 8 9 10 11 6 7 8 9 10 11 12
|
|
|
|
// 15 16 17 18 19 20 21 12 13 14 15 16 17 18 13 14 15 16 17 18 19
|
|
|
|
// 22 23 24 25 26 27 28 19 20 21 22 23 24 25 20 21 22 23 24 25 26
|
|
|
|
// 29 30 31 26 27 28 29 30 31 27 28 29 30 31
|
|
|
|
Test1684Data *tests[] = {
|
|
|
|
new Test1684Data(2001, 8, 6, 2001,8,2,UCAL_MONDAY, "2001 08 02 Mon", NULL),
|
|
|
|
new Test1684Data(2001, 8, 7, 2001,8,2,UCAL_TUESDAY, "2001 08 02 Tue", NULL),
|
|
|
|
new Test1684Data(2001, 8, 5,/*12,*/ 2001,8,2,UCAL_SUNDAY, "2001 08 02 Sun", NULL),
|
|
|
|
new Test1684Data(2001, 8,6, /*7, 30,*/ 2001,7,6,UCAL_MONDAY, "2001 07 06 Mon", "2001 08 02 Mon"),
|
|
|
|
new Test1684Data(2001, 8,7, /*7, 31,*/ 2001,7,6,UCAL_TUESDAY, "2001 07 06 Tue", "2001 08 02 Tue"),
|
|
|
|
new Test1684Data(2001, 8, 5, 2001,7,6,UCAL_SUNDAY, "2001 07 06 Sun", "2001 08 02 Sun"),
|
|
|
|
new Test1684Data(2001, 7, 30, 2001,8,1,UCAL_MONDAY, "2001 08 01 Mon", "2001 07 05 Mon"),
|
|
|
|
new Test1684Data(2001, 7, 31, 2001,8,1,UCAL_TUESDAY, "2001 08 01 Tue", "2001 07 05 Tue"),
|
|
|
|
new Test1684Data(2001, 7,29, /*8, 5,*/ 2001,8,1,UCAL_SUNDAY, "2001 08 01 Sun", "2001 07 05 Sun"),
|
|
|
|
new Test1684Data(2001, 12, 31, 2001,12,6,UCAL_MONDAY, "2001 12 06 Mon", NULL),
|
|
|
|
new Test1684Data(2002, 1, 1, 2002,1,1,UCAL_TUESDAY, "2002 01 01 Tue", NULL),
|
|
|
|
new Test1684Data(2002, 1, 2, 2002,1,1,UCAL_WEDNESDAY, "2002 01 01 Wed", NULL),
|
|
|
|
new Test1684Data(2002, 1, 3, 2002,1,1,UCAL_THURSDAY, "2002 01 01 Thu", NULL),
|
|
|
|
new Test1684Data(2002, 1, 4, 2002,1,1,UCAL_FRIDAY, "2002 01 01 Fri", NULL),
|
|
|
|
new Test1684Data(2002, 1, 5, 2002,1,1,UCAL_SATURDAY, "2002 01 01 Sat", NULL),
|
|
|
|
new Test1684Data(2001,12,30, /*2002, 1, 6,*/ 2002,1,1,UCAL_SUNDAY, "2002 01 01 Sun", "2001 12 06 Sun")
|
|
|
|
};
|
|
|
|
|
2003-06-11 23:15:40 +00:00
|
|
|
#define kTest1684Count ((int32_t)(sizeof(tests)/sizeof(tests[0])))
|
2003-06-06 01:48:24 +00:00
|
|
|
|
|
|
|
int32_t pass = 0, error = 0, warning = 0;
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UnicodeString pattern("yyyy MM WW EEE","");
|
|
|
|
Calendar *cal = new GregorianCalendar(status);
|
|
|
|
SimpleDateFormat *sdf = new SimpleDateFormat(pattern,status);
|
|
|
|
cal->setFirstDayOfWeek(UCAL_SUNDAY);
|
|
|
|
cal->setMinimalDaysInFirstWeek(1);
|
|
|
|
|
|
|
|
sdf->adoptCalendar(cal);
|
|
|
|
|
|
|
|
cal = sdf->getCalendar()->clone(); // sdf may have deleted calendar
|
|
|
|
|
|
|
|
if(!cal || !sdf || U_FAILURE(status)) {
|
|
|
|
errln(UnicodeString("Error setting up test: ") + u_errorName(status));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < kTest1684Count; ++i) {
|
|
|
|
Test1684Data &test = *(tests[i]);
|
|
|
|
logln(UnicodeString("#") + i + UnicodeString("\n-----\nTesting round trip of ") + test.year +
|
|
|
|
" " + (test.month + 1) +
|
|
|
|
" " + test.date +
|
|
|
|
" (written as) " + test.data);
|
|
|
|
|
|
|
|
cal->clear();
|
|
|
|
cal->set(test.year, test.month, test.date);
|
|
|
|
UDate ms = cal->getTime(status);
|
|
|
|
|
|
|
|
cal->clear();
|
|
|
|
cal->set(UCAL_YEAR, test.womyear);
|
|
|
|
cal->set(UCAL_MONTH, test.wommon);
|
|
|
|
cal->set(UCAL_WEEK_OF_MONTH, test.wom);
|
|
|
|
cal->set(UCAL_DAY_OF_WEEK, test.dow);
|
|
|
|
UDate ms2 = cal->getTime(status);
|
|
|
|
|
|
|
|
if (ms2 != ms) {
|
|
|
|
errln((UnicodeString)"\nError: GregorianUCAL_DOM gave " + ms +
|
|
|
|
"\n GregorianUCAL_WOM gave " + ms2);
|
|
|
|
error++;
|
|
|
|
} else {
|
|
|
|
pass++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ms2 = sdf->parse(test.data, status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("parse exception: " + UnicodeString(u_errorName(status)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ms2!=ms) {
|
|
|
|
errln((UnicodeString)"\nError: GregorianCalendar gave " + ms +
|
|
|
|
"\n SimpleDateFormat.parse gave " + ms2);
|
|
|
|
error++;
|
|
|
|
} else {
|
|
|
|
pass++;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString result;
|
|
|
|
sdf->format(ms, result);
|
|
|
|
if (result != test.normalized) {
|
|
|
|
errln("\nWarning: format of '" + test.data + "' gave" +
|
|
|
|
"\n '" + result + "'" +
|
|
|
|
"\n expected '" + test.normalized + "'");
|
|
|
|
warning++;
|
|
|
|
} else {
|
|
|
|
pass++;
|
|
|
|
}
|
|
|
|
|
|
|
|
UDate ms3;
|
|
|
|
ms3 = sdf->parse(result, status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("parse exception 2: " + (UnicodeString)u_errorName(status));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ms3!=ms) {
|
|
|
|
error++;
|
|
|
|
errln((UnicodeString)"\nError: Re-parse of '" + result + "' gave time of " +
|
|
|
|
"\n " + ms3 +
|
|
|
|
"\n not " + ms);
|
|
|
|
} else {
|
|
|
|
pass++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString info
|
|
|
|
= UnicodeString("Passed: ") + pass + ", Warnings: " + warning + ", Errors: " + error;
|
|
|
|
if (error > 0) {
|
|
|
|
errln(info);
|
|
|
|
} else {
|
|
|
|
logln(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0;i<kTest1684Count;i++) {
|
|
|
|
delete tests[i];
|
|
|
|
}
|
|
|
|
delete cal;
|
|
|
|
delete sdf;
|
|
|
|
}
|
|
|
|
|
2002-09-21 00:43:14 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
//eof
|