mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 06:25:30 +00:00
ICU-8366 Added ISO8601 calendar type support.
X-SVN-Rev: 29868
This commit is contained in:
parent
06060e22d7
commit
56ef4e7f1a
3 changed files with 102 additions and 27 deletions
|
@ -155,6 +155,7 @@ static const char * const gCalTypes[] = {
|
|||
"coptic",
|
||||
"ethiopic",
|
||||
"ethiopic-amete-alem",
|
||||
"iso8601",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@ -173,7 +174,8 @@ typedef enum ECalType {
|
|||
CALTYPE_INDIAN,
|
||||
CALTYPE_COPTIC,
|
||||
CALTYPE_ETHIOPIC,
|
||||
CALTYPE_ETHIOPIC_AMETE_ALEM
|
||||
CALTYPE_ETHIOPIC_AMETE_ALEM,
|
||||
CALTYPE_ISO8601,
|
||||
} ECalType;
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
@ -327,6 +329,11 @@ static Calendar *createStandardCalendar(ECalType calType, const Locale &loc, UEr
|
|||
case CALTYPE_ETHIOPIC_AMETE_ALEM:
|
||||
cal = new EthiopicCalendar(loc, status, EthiopicCalendar::AMETE_ALEM_ERA);
|
||||
break;
|
||||
case CALTYPE_ISO8601:
|
||||
cal = new GregorianCalendar(loc, status);
|
||||
cal->setFirstDayOfWeek(UCAL_MONDAY);
|
||||
cal->setMinimalDaysInFirstWeek(4);
|
||||
break;
|
||||
default:
|
||||
status = U_UNSUPPORTED_ERROR;
|
||||
}
|
||||
|
@ -870,6 +877,14 @@ Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& succ
|
|||
fprintf(stderr, "%p: setting week count data to locale %s, actual locale %s\n", c, (const char*)aLocale.getName(), (const char *)actualLoc.getName());
|
||||
#endif
|
||||
c->setWeekData(aLocale, c->getType(), success); // set the correct locale (this was an indirected calendar)
|
||||
|
||||
char keyword[ULOC_FULLNAME_CAPACITY];
|
||||
UErrorCode tmpStatus = U_ZERO_ERROR;
|
||||
l.getKeywordValue("calendar", keyword, ULOC_FULLNAME_CAPACITY, tmpStatus);
|
||||
if (U_SUCCESS(tmpStatus) && uprv_strcmp(keyword, "iso8601") == 0) {
|
||||
c->setFirstDayOfWeek(UCAL_MONDAY);
|
||||
c->setMinimalDaysInFirstWeek(4);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* UCONFIG_NO_SERVICE */
|
||||
|
|
|
@ -236,6 +236,13 @@ void CalendarTest::runIndexedTest( int32_t index, UBool exec, const char* &name,
|
|||
TestTimeStamp();
|
||||
}
|
||||
break;
|
||||
case 26:
|
||||
name = "TestISO8601";
|
||||
if(exec) {
|
||||
logln("TestISO8601---"); logln("");
|
||||
TestISO8601();
|
||||
}
|
||||
break;
|
||||
default: name = ""; break;
|
||||
}
|
||||
}
|
||||
|
@ -1375,7 +1382,7 @@ CalendarTest::TestDOW_LOCALandYEAR_WOY()
|
|||
sdf->applyLocalizedPattern(UnicodeString("JJJJ'-W'ww-ee"), status);
|
||||
if (U_FAILURE(status)) { errln("Couldn't apply localized pattern"); return; }
|
||||
|
||||
cal->clear();
|
||||
cal->clear();
|
||||
cal->set(1997, UCAL_DECEMBER, 25);
|
||||
doYEAR_WOYLoop(cal, sdf, times, status);
|
||||
//loop_addroll(cal, /*sdf,*/ times, UCAL_YEAR_WOY, UCAL_YEAR, status);
|
||||
|
@ -1961,20 +1968,20 @@ void CalendarTest::TestJD()
|
|||
// make sure the ctestfw utilities are in sync with the Calendar
|
||||
void CalendarTest::TestDebug()
|
||||
{
|
||||
for(int32_t t=0;t<=UDBG_ENUM_COUNT;t++) {
|
||||
int32_t count = udbg_enumCount((UDebugEnumType)t);
|
||||
if(count == -1) {
|
||||
logln("enumCount(%d) returned -1", count);
|
||||
continue;
|
||||
}
|
||||
for(int32_t i=0;i<=count;i++) {
|
||||
if(t<=UDBG_HIGHEST_CONTIGUOUS_ENUM && i<count) {
|
||||
if( i!=udbg_enumArrayValue((UDebugEnumType)t, i)) {
|
||||
errln("FAIL: udbg_enumArrayValue(%d,%d) returned %d, expected %d", t, i, udbg_enumArrayValue((UDebugEnumType)t,i), i);
|
||||
}
|
||||
} else {
|
||||
logln("Testing count+1:");
|
||||
}
|
||||
for(int32_t t=0;t<=UDBG_ENUM_COUNT;t++) {
|
||||
int32_t count = udbg_enumCount((UDebugEnumType)t);
|
||||
if(count == -1) {
|
||||
logln("enumCount(%d) returned -1", count);
|
||||
continue;
|
||||
}
|
||||
for(int32_t i=0;i<=count;i++) {
|
||||
if(t<=UDBG_HIGHEST_CONTIGUOUS_ENUM && i<count) {
|
||||
if( i!=udbg_enumArrayValue((UDebugEnumType)t, i)) {
|
||||
errln("FAIL: udbg_enumArrayValue(%d,%d) returned %d, expected %d", t, i, udbg_enumArrayValue((UDebugEnumType)t,i), i);
|
||||
}
|
||||
} else {
|
||||
logln("Testing count+1:");
|
||||
}
|
||||
const char *name = udbg_enumName((UDebugEnumType)t,i);
|
||||
if(name==NULL) {
|
||||
if(i==count || t>UDBG_HIGHEST_CONTIGUOUS_ENUM ) {
|
||||
|
@ -1984,16 +1991,16 @@ void CalendarTest::TestDebug()
|
|||
}
|
||||
name = "(null)";
|
||||
}
|
||||
logln("udbg_enumArrayValue(%d,%d) = %s, returned %d", t, i,
|
||||
name, udbg_enumArrayValue((UDebugEnumType)t,i));
|
||||
logln("udbg_enumString = " + udbg_enumString((UDebugEnumType)t,i));
|
||||
}
|
||||
if(udbg_enumExpectedCount((UDebugEnumType)t) != count && t<=UDBG_HIGHEST_CONTIGUOUS_ENUM) {
|
||||
errln("FAIL: udbg_enumExpectedCount(%d): %d, != UCAL_FIELD_COUNT=%d ", t, udbg_enumExpectedCount((UDebugEnumType)t), count);
|
||||
} else {
|
||||
logln("udbg_ucal_fieldCount: %d, UCAL_FIELD_COUNT=udbg_enumCount %d ", udbg_enumExpectedCount((UDebugEnumType)t), count);
|
||||
}
|
||||
}
|
||||
logln("udbg_enumArrayValue(%d,%d) = %s, returned %d", t, i,
|
||||
name, udbg_enumArrayValue((UDebugEnumType)t,i));
|
||||
logln("udbg_enumString = " + udbg_enumString((UDebugEnumType)t,i));
|
||||
}
|
||||
if(udbg_enumExpectedCount((UDebugEnumType)t) != count && t<=UDBG_HIGHEST_CONTIGUOUS_ENUM) {
|
||||
errln("FAIL: udbg_enumExpectedCount(%d): %d, != UCAL_FIELD_COUNT=%d ", t, udbg_enumExpectedCount((UDebugEnumType)t), count);
|
||||
} else {
|
||||
logln("udbg_ucal_fieldCount: %d, UCAL_FIELD_COUNT=udbg_enumCount %d ", udbg_enumExpectedCount((UDebugEnumType)t), count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -2200,6 +2207,55 @@ void CalendarTest::TestTimeStamp() {
|
|||
delete cal;
|
||||
}
|
||||
|
||||
void CalendarTest::TestISO8601() {
|
||||
const char* TEST_LOCALES[] = {
|
||||
"en_US@calendar=iso8601",
|
||||
"en_US@calendar=Iso8601",
|
||||
"th_TH@calendar=iso8601",
|
||||
"ar_EG@calendar=iso8601",
|
||||
NULL
|
||||
};
|
||||
|
||||
int32_t TEST_DATA[][3] = {
|
||||
{2008, 1, 2008},
|
||||
{2009, 1, 2009},
|
||||
{2010, 53, 2009},
|
||||
{2011, 52, 2010},
|
||||
{2012, 52, 2011},
|
||||
{2013, 1, 2013},
|
||||
{2014, 1, 2014},
|
||||
{0, 0, 0},
|
||||
};
|
||||
|
||||
for (int i = 0; TEST_LOCALES[i] != NULL; i++) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
Calendar *cal = Calendar::createInstance(TEST_LOCALES[i], status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("Error: Failed to create a calendar for locale: %s", TEST_LOCALES[i]);
|
||||
continue;
|
||||
}
|
||||
if (strcmp(cal->getType(), "gregorian") != 0) {
|
||||
errln("Error: Gregorian calendar is not used for locale: %s", TEST_LOCALES[i]);
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; TEST_DATA[j][0] != 0; j++) {
|
||||
cal->set(TEST_DATA[j][0], UCAL_JANUARY, 1);
|
||||
int32_t weekNum = cal->get(UCAL_WEEK_OF_YEAR, status);
|
||||
int32_t weekYear = cal->get(UCAL_YEAR_WOY, status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("Error: Failed to get week of year");
|
||||
break;
|
||||
}
|
||||
if (weekNum != TEST_DATA[j][1] || weekYear != TEST_DATA[j][2]) {
|
||||
errln("Error: Incorrect week of year on January 1st, %d for locale %s: Returned [weekNum=%d, weekYear=%d], Expected [weekNum=%d, weekYear=%d]",
|
||||
TEST_DATA[j][0], TEST_LOCALES[i], weekNum, weekYear, TEST_DATA[j][1], TEST_DATA[j][2]);
|
||||
}
|
||||
}
|
||||
delete cal;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
//eof
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/***********************************************************************
|
||||
* Copyright (c) 1997-2010, International Business Machines Corporation
|
||||
* Copyright (c) 1997-2011, International Business Machines Corporation
|
||||
* and others. All Rights Reserved.
|
||||
***********************************************************************/
|
||||
|
||||
|
@ -224,6 +224,10 @@ public: // package
|
|||
* Test the time stamp array recalculation during heavy Calendar usage
|
||||
*/
|
||||
void TestTimeStamp(void);
|
||||
/**
|
||||
* Test the ISO8601 calendar type
|
||||
*/
|
||||
void TestISO8601(void);
|
||||
};
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
|
Loading…
Add table
Reference in a new issue