ICU-7728 Time format using 'S' (fractional seconds) should truncate, not round.

X-SVN-Rev: 28130
This commit is contained in:
Peter Edberg 2010-06-04 00:31:33 +00:00
parent 311eb8cb78
commit 3249dbb71d
3 changed files with 20 additions and 10 deletions

View File

@ -1556,9 +1556,9 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo,
currentNumberFormat->setMinimumIntegerDigits((count > 3) ? 3 : count);
currentNumberFormat->setMaximumIntegerDigits(maxIntCount);
if (count == 1) {
value = (value + 50) / 100;
value /= 100;
} else if (count == 2) {
value = (value + 5) / 10;
value /= 10;
}
FieldPosition p(0);
currentNumberFormat->format(value, appendTo, p);

View File

@ -503,7 +503,7 @@ void Test714(void)
enum { DATE_TEXT_MAX_CHARS = 64 };
static const UChar zonePST[] = { 0x50,0x53,0x54,0 }; /* "PST" */
static const UDate july022008 = 1.215e+12; /* 02 July 2008 5:00 AM PDT (approx ICU 4.0 release date :-) */
static const UDate july022008 = 1215000001979.0; /* 02 July 2008 5:00:01.979 AM PDT (near ICU 4.0 release date :-) */
static const double dayMillisec = 8.64e+07;
static const UChar dMyGGGPattern[] = { 0x64,0x64,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0x20,0x47,0x47,0x47,0 }; /* "dd MMM yyyy GGG" */
@ -524,9 +524,15 @@ static const UChar eeeedMyPattern[] = { 0x65,0x65,0x65,0x65,0x20,0x64,0x64,0x20
static const UChar eeeedMyText[] = { 0x57,0x65,0x64,0x6E,0x65,0x73,0x64,0x61,0x79,0x20,0x30,0x32,0x20,0x4A,0x75,0x6C,0x20,0x32,0x30,0x30,0x38,0 }; /* "Wednesday 02 Jul 2008" */
static const UChar eeeeedMyPattern[] = { 0x65,0x65,0x65,0x65,0x65,0x20,0x64,0x64,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "eeeee dd MMM yyyy" */
static const UChar eeeeedMyText[] = { 0x57,0x20,0x30,0x32,0x20,0x4A,0x75,0x6C,0x20,0x32,0x30,0x30,0x38,0 }; /* "W 02 Jul 2008" */
static const UChar ewYPattern[] = { 0x65,0x20,0x77,0x77,0x20,0x59,0x59,0x59,0x59,0 }; /* "e ww YYYY" */
static const UChar cwYPattern[] = { 0x63,0x20,0x77,0x77,0x20,0x59,0x59,0x59,0x59,0 }; /* "c ww YYYY" */
static const UChar ewYText[] = { 0x33,0x20,0x32,0x37,0x20,0x32,0x30,0x30,0x38,0 }; /* "3 27 2008" */
static const UChar ewYPattern[] = { 0x65,0x20,0x77,0x77,0x20,0x59,0x59,0x59,0x59,0 }; /* "e ww YYYY" */
static const UChar cwYPattern[] = { 0x63,0x20,0x77,0x77,0x20,0x59,0x59,0x59,0x59,0 }; /* "c ww YYYY" */
static const UChar ewYText[] = { 0x33,0x20,0x32,0x37,0x20,0x32,0x30,0x30,0x38,0 }; /* "3 27 2008" */
static const UChar HHmmssPattern[] = { 0x48,0x48,0x3A,0x6D,0x6D,0x3A,0x73,0x73,0 }; /* "HH:mm:ss" */
static const UChar HHmmssText[] = { 0x30,0x35,0x3A,0x30,0x30,0x3A,0x30,0x31,0 }; /* "05:00:01" */
static const UChar ssSPattern[] = { 0x73,0x73,0x2E,0x53,0 }; /* "ss.S" */
static const UChar ssSText[] = { 0x30,0x31,0x2E,0x39,0 }; /* "01.9" */
static const UChar ssSSPattern[] = { 0x73,0x73,0x2E,0x53,0x53,0 }; /* "ss.SS" */
static const UChar ssSSText[] = { 0x30,0x31,0x2E,0x39,0x37,0 }; /* "01.97" */
typedef struct {
const UChar * pattern;
@ -547,6 +553,9 @@ static const DatePatternAndText datePatternsAndText[] = {
{ eeeeedMyPattern, eeeeedMyText, "eeeee dd MMM yyyy" },
{ ewYPattern, ewYText, "e ww YYYY" },
{ cwYPattern, ewYText, "c ww YYYY" },
{ HHmmssPattern, HHmmssText, "* HH:mm:ss" }, /* '*' at start means don't check value from parse (won't be july022008) */
{ ssSPattern, ssSText, "* ss.S" },
{ ssSSPattern, ssSSText, "* ss.SS" },
{ NULL, NULL, NULL }
};
void Test_GEec(void)
@ -557,6 +566,7 @@ void Test_GEec(void)
const DatePatternAndText *patTextPtr;
for (patTextPtr = datePatternsAndText; patTextPtr->pattern != NULL; ++patTextPtr) {
UChar dmyGnText[DATE_TEXT_MAX_CHARS];
char byteText[3*DATE_TEXT_MAX_CHARS];
int32_t dmyGnTextLen;
UDate dateResult;
@ -566,14 +576,14 @@ void Test_GEec(void)
log_err("FAIL: udat_format with %s: %s\n", patTextPtr->label, myErrorName(status) );
status = U_ZERO_ERROR;
} else if ( u_strcmp(dmyGnText, patTextPtr->text) != 0 ) {
log_err("FAIL: udat_format with %s: wrong UChar[] result\n", patTextPtr->label );
log_err("FAIL: udat_format with %s: wrong UChar[] result %s\n", patTextPtr->label, u_austrcpy(byteText,dmyGnText) );
}
dateResult = udat_parse(dtfmt, patTextPtr->text, -1, NULL, &status); /* no time, dateResult != july022008 by some hours */
if ( U_FAILURE(status) ) {
log_err("FAIL: udat_parse with %s: %s\n", patTextPtr->label, myErrorName(status) );
status = U_ZERO_ERROR;
} else if ( july022008 - dateResult > dayMillisec ) {
} else if ( patTextPtr->label[0] != '*' && july022008 - dateResult > dayMillisec ) {
log_err("FAIL: udat_parse with %s: wrong UDate result\n", patTextPtr->label );
}
}

View File

@ -463,8 +463,8 @@ void DateFormatTest::TestGeneral() {
"yyyy MM dd HH:mm:ss.SSS",
// Milliseconds are left-justified, since they format as fractions of a second
"y/M/d H:mm:ss.S", "fp", "2004 03 10 16:36:31.567", "2004/3/10 16:36:31.6", "2004 03 10 16:36:31.600",
"y/M/d H:mm:ss.SS", "fp", "2004 03 10 16:36:31.567", "2004/3/10 16:36:31.57", "2004 03 10 16:36:31.570",
"y/M/d H:mm:ss.S", "fp", "2004 03 10 16:36:31.567", "2004/3/10 16:36:31.5", "2004 03 10 16:36:31.500",
"y/M/d H:mm:ss.SS", "fp", "2004 03 10 16:36:31.567", "2004/3/10 16:36:31.56", "2004 03 10 16:36:31.560",
"y/M/d H:mm:ss.SSS", "F", "2004 03 10 16:36:31.567", "2004/3/10 16:36:31.567",
"y/M/d H:mm:ss.SSSS", "pf", "2004/3/10 16:36:31.5679", "2004 03 10 16:36:31.568", "2004/3/10 16:36:31.5680",
};