mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-9914 ICU4C DateIntervalFormat to handle 2 year vs. 4 year formats.
X-SVN-Rev: 33453
This commit is contained in:
parent
b33cab0a51
commit
7e89728836
3 changed files with 80 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2008-2012, International Business Machines Corporation and
|
||||
* Copyright (C) 2008-2013, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*
|
||||
|
@ -863,7 +863,9 @@ DateIntervalFormat::getDateTimeSkeleton(const UnicodeString& skeleton,
|
|||
|
||||
/* generate normalized form for date*/
|
||||
if ( yCount != 0 ) {
|
||||
normalizedDateSkeleton.append(LOW_Y);
|
||||
for (i = 0; i < yCount; ++i) {
|
||||
normalizedDateSkeleton.append(LOW_Y);
|
||||
}
|
||||
}
|
||||
if ( MCount != 0 ) {
|
||||
if ( MCount < 3 ) {
|
||||
|
|
|
@ -47,7 +47,8 @@ void DateIntervalFormatTest::runIndexedTest( int32_t index, UBool exec, const ch
|
|||
TESTCASE(1, testFormat);
|
||||
TESTCASE(2, testFormatUserDII);
|
||||
TESTCASE(3, testSetIntervalPatternNoSideEffect);
|
||||
TESTCASE(4, testStress);
|
||||
TESTCASE(4, testYearFormats);
|
||||
TESTCASE(5, testStress);
|
||||
default: name = ""; break;
|
||||
}
|
||||
}
|
||||
|
@ -1187,6 +1188,75 @@ void DateIntervalFormatTest::testSetIntervalPatternNoSideEffect() {
|
|||
}
|
||||
}
|
||||
|
||||
void DateIntervalFormatTest::testYearFormats() {
|
||||
const Locale &enLocale = Locale::getEnglish();
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalPointer<Calendar> fromTime(Calendar::createInstance(enLocale, status));
|
||||
LocalPointer<Calendar> toTime(Calendar::createInstance(enLocale, status));
|
||||
if (U_FAILURE(status)) {
|
||||
errln("Failure encountered: %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
// April 26, 113. Three digit year so that we can test 2 digit years;
|
||||
// 4 digit years with padded 0's and full years.
|
||||
fromTime->set(113, 3, 26);
|
||||
// April 28, 113.
|
||||
toTime->set(113, 3, 28);
|
||||
{
|
||||
LocalPointer<DateIntervalFormat> dif(DateIntervalFormat::createInstance("yyyyMd", enLocale, status));
|
||||
if (U_FAILURE(status)) {
|
||||
errln("Failure encountered: %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
UnicodeString actual;
|
||||
UnicodeString expected(ctou("4/26/0113 \\u2013 4/28/0113"));
|
||||
FieldPosition pos = 0;
|
||||
dif->format(*fromTime, *toTime, actual, pos, status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("Failure encountered: %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
if (actual != expected) {
|
||||
errln("Expected " + expected + ", got: " + actual);
|
||||
}
|
||||
}
|
||||
{
|
||||
LocalPointer<DateIntervalFormat> dif(DateIntervalFormat::createInstance("yyMd", enLocale, status));
|
||||
if (U_FAILURE(status)) {
|
||||
errln("Failure encountered: %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
UnicodeString actual;
|
||||
UnicodeString expected(ctou("4/26/13 \\u2013 4/28/13"));
|
||||
FieldPosition pos = 0;
|
||||
dif->format(*fromTime, *toTime, actual, pos, status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("Failure encountered: %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
if (actual != expected) {
|
||||
errln("Expected " + expected + ", got: " + actual);
|
||||
}
|
||||
}
|
||||
{
|
||||
LocalPointer<DateIntervalFormat> dif(DateIntervalFormat::createInstance("yMd", enLocale, status));
|
||||
if (U_FAILURE(status)) {
|
||||
errln("Failure encountered: %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
UnicodeString actual;
|
||||
UnicodeString expected(ctou("4/26/113 \\u2013 4/28/113"));
|
||||
FieldPosition pos = 0;
|
||||
dif->format(*fromTime, *toTime, actual, pos, status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln("Failure encountered: %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
if (actual != expected) {
|
||||
errln("Expected " + expected + ", got: " + actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DateIntervalFormatTest::expectUserDII(const char** data,
|
||||
int32_t data_length) {
|
||||
|
|
|
@ -42,6 +42,11 @@ public:
|
|||
*/
|
||||
void testSetIntervalPatternNoSideEffect();
|
||||
|
||||
/**
|
||||
* Tests different year formats.
|
||||
*/
|
||||
void testYearFormats();
|
||||
|
||||
/**
|
||||
* Stress test -- stress test formatting on 40 locales
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue