diff --git a/icu4c/source/i18n/smpdtfmt.cpp b/icu4c/source/i18n/smpdtfmt.cpp index 1d5da91ed78..1602a0f822a 100644 --- a/icu4c/source/i18n/smpdtfmt.cpp +++ b/icu4c/source/i18n/smpdtfmt.cpp @@ -1135,9 +1135,22 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo, } break; - // for "EEE", write out the abbreviated day-of-the-week name - // for "EEEE", write out the wide day-of-the-week name - // for "EEEEE", use the narrow day-of-the-week name + // for "ee" or "e", use local numeric day-of-the-week + // for "EEEEE" or "eeeee", write out the narrow day-of-the-week name + // for "EEEE" or "eeee", write out the wide day-of-the-week name + // for "EEE" or "EE" or "E" or "eee", write out the abbreviated day-of-the-week name + case UDAT_DOW_LOCAL_FIELD: + if ( count < 3 ) { + zeroPaddingNumber(appendTo, value, 1, maxIntCount); + break; + } + // fall through to EEEEE-EEE handling, but for that we don't want local day-of-week, + // we want standard day-of-week, so first fix value to work for EEEEE-EEE. + value = cal.get(UCAL_DAY_OF_WEEK, status); + if (U_FAILURE(status)) { + return; + } + // fall through, do not break here case UDAT_DAY_OF_WEEK_FIELD: if (count == 5) _appendSymbol(appendTo, value, fSymbols->fNarrowWeekdays, diff --git a/icu4c/source/test/cintltst/cdtrgtst.c b/icu4c/source/test/cintltst/cdtrgtst.c index 5c649fd8b16..eede36a88bb 100644 --- a/icu4c/source/test/cintltst/cdtrgtst.c +++ b/icu4c/source/test/cintltst/cdtrgtst.c @@ -41,6 +41,7 @@ void addDateForRgrTest(TestNode** root) addTest(root, &Test4162071, "tsformat/cdtrgtst/Test4162071"); addTest(root, &Test714, "tsformat/cdtrgtst/Test714"); addTest(root, &TestJ6072, "tsformat/cdtrgtst/TestJ6072"); + addTest(root, &TestJ5726, "tsformat/cdtrgtst/TestJ5726"); } /** @@ -501,24 +502,24 @@ void Test714(void) } static const UDate july022008 = 1.215e+12; /* 02 July 2008 5:00 AM PDT (approx ICU 4.0 release date :-) */ -static const UChar zonePST[] = { 'P','S','T',0 }; -static const UChar dmyGGGPattern[] = { 'd','d',' ','M','M','M',' ','y','y','y','y',' ','G','G','G',0 }; -static const UChar dmyGGGGGPattern[] = { 'd','d',' ','M','M','M',' ','y','y','y','y',' ','G','G','G','G','G',0 }; -static const UChar dmyGGGText[] = { '0','2',' ','J','u','l',' ','2','0','0','8',' ','A','D',0 }; -static const UChar dmyGGGGGText[] = { '0','2',' ','J','u','l',' ','2','0','0','8',' ','A',0 }; +static const UChar zonePST[] = { 0x50,0x53,0x54,0 }; /* "PST" */ +static const UChar dmyGGGPattern[] = { 0x64,0x64,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0x20,0x47,0x47,0x47,0 }; /* "dd MMM yyyy GGG" */ +static const UChar dmyGGGGGPattern[] = { 0x64,0x64,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0x20,0x47,0x47,0x47,0x47,0x47,0 }; /* "dd MMM yyyy GGGGG" */ +static const UChar dmyGGGText[] = { 0x30,0x32,0x20,0x4A,0x75,0x6C,0x20,0x32,0x30,0x30,0x38,0x20,0x41,0x44,0 }; /* "02 Jul 2008 AD" */ +static const UChar dmyGGGGGText[] = { 0x30,0x32,0x20,0x4A,0x75,0x6C,0x20,0x32,0x30,0x30,0x38,0x20,0x41,0 }; /* "02 Jul 2008 A" */ static const double dayMillisec = 8.64e+07; -enum { kdmyGnTextMaxChars = 64 }; +enum { DATE_TEXT_MAX_CHARS = 64 }; void TestJ6072(void) { UErrorCode status = U_ZERO_ERROR; UDateFormat * dtfmt = udat_open(UDAT_LONG, UDAT_LONG, "en", zonePST, -1, NULL, 0, &status); if ( U_SUCCESS(status) ) { - UChar dmyGnText[kdmyGnTextMaxChars]; + UChar dmyGnText[DATE_TEXT_MAX_CHARS]; int32_t dmyGnTextLen; UDate dateResult; udat_applyPattern(dtfmt, FALSE, dmyGGGPattern, -1); - dmyGnTextLen = udat_format(dtfmt, july022008, dmyGnText, kdmyGnTextMaxChars, NULL, &status); + dmyGnTextLen = udat_format(dtfmt, july022008, dmyGnText, DATE_TEXT_MAX_CHARS, NULL, &status); if ( U_FAILURE(status) ) { log_err("FAIL: udat_format with GGG: %s\n", myErrorName(status) ); status = U_ZERO_ERROR; @@ -534,7 +535,7 @@ void TestJ6072(void) } udat_applyPattern(dtfmt, FALSE, dmyGGGGGPattern, -1); - dmyGnTextLen = udat_format(dtfmt, july022008, dmyGnText, kdmyGnTextMaxChars, NULL, &status); + dmyGnTextLen = udat_format(dtfmt, july022008, dmyGnText, DATE_TEXT_MAX_CHARS, NULL, &status); if ( U_FAILURE(status) ) { log_err("FAIL: udat_format with GGGGG: %s\n", myErrorName(status) ); status = U_ZERO_ERROR; @@ -555,6 +556,58 @@ void TestJ6072(void) } } +typedef struct { + const UChar * pattern; + const UChar * text; + const char * label; +} DatePatternAndText; +static const UChar eMyPattern[] = { 0x65,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "e MMM yyyy" */ +static const UChar eeMyPattern[] = { 0x65,0x65,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "ee MMM yyyy" */ +static const UChar eMyText[] = { 0x33,0x20,0x4A,0x75,0x6C,0x20,0x32,0x30,0x30,0x38,0 }; /* "3 Jul 2008" */ +static const UChar eeeMyPattern[] = { 0x65,0x65,0x65,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "eee MMM yyyy" */ +static const UChar EEEMyPattern[] = { 0x45,0x45,0x45,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "EEE MMM yyyy" */ +static const UChar EEMyPattern[] = { 0x45,0x45,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "EE MMM yyyy" */ +static const UChar eeeMyText[] = { 0x57,0x65,0x64,0x20,0x4A,0x75,0x6C,0x20,0x32,0x30,0x30,0x38,0 }; /* "Wed Jul 2008" */ +static const UChar eeeeMyPattern[] = { 0x65,0x65,0x65,0x65,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "eeee MMM yyyy" */ +static const UChar eeeeMyText[] = { 0x57,0x65,0x64,0x6E,0x65,0x73,0x64,0x61,0x79,0x20,0x4A,0x75,0x6C,0x20,0x32,0x30,0x30,0x38,0 }; /* "Wednesday Jul 2008" */ +static const UChar eeeeeMyPattern[] = { 0x65,0x65,0x65,0x65,0x65,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "eeeee MMM yyyy" */ +static const UChar eeeeeMyText[] = { 0x57,0x20,0x4A,0x75,0x6C,0x20,0x32,0x30,0x30,0x38,0 }; /* "W Jul 2008" */ + +static const DatePatternAndText datePatternsAndText[] = { + { eMyPattern, eMyText, "e" }, + { eeMyPattern, eMyText, "ee" }, + { eeeMyPattern, eeeMyText, "eee" }, + { EEEMyPattern, eeeMyText, "EEE" }, + { EEMyPattern, eeeMyText, "EE" }, + { eeeeMyPattern, eeeeMyText, "eeee" }, + { eeeeeMyPattern, eeeeeMyText, "eeeee" }, + { NULL, NULL, NULL } +}; +void TestJ5726(void) +{ + UErrorCode status = U_ZERO_ERROR; + UDateFormat * dtfmt = udat_open(UDAT_LONG, UDAT_LONG, "en", zonePST, -1, NULL, 0, &status); + if ( U_SUCCESS(status) ) { + const DatePatternAndText *patTextPtr; + for (patTextPtr = datePatternsAndText; patTextPtr->pattern != NULL; ++patTextPtr) { + UChar dmyGnText[DATE_TEXT_MAX_CHARS]; + int32_t dmyGnTextLen; + + udat_applyPattern(dtfmt, FALSE, patTextPtr->pattern, -1); + dmyGnTextLen = udat_format(dtfmt, july022008, dmyGnText, DATE_TEXT_MAX_CHARS, NULL, &status); + if ( U_FAILURE(status) ) { + 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 ); + } + } + udat_close(dtfmt); + } else { + log_err("FAIL: udat_open fails: %s\n", myErrorName(status)); + } +} + /*INTERNAL FUNCTION USED */ UChar* myFormatit(UDateFormat* datdef, UDate d1) diff --git a/icu4c/source/test/cintltst/cdtrgtst.h b/icu4c/source/test/cintltst/cdtrgtst.h index b60b4178a76..d46173930b6 100644 --- a/icu4c/source/test/cintltst/cdtrgtst.h +++ b/icu4c/source/test/cintltst/cdtrgtst.h @@ -35,6 +35,7 @@ void Test4162071(void); void Test714(void); void TestJ6072(void); + void TestJ5726(void); /** * test subroutine diff --git a/icu4c/source/test/intltest/dtfmttst.cpp b/icu4c/source/test/intltest/dtfmttst.cpp index 3c64d58d632..67ed619eb7e 100644 --- a/icu4c/source/test/intltest/dtfmttst.cpp +++ b/icu4c/source/test/intltest/dtfmttst.cpp @@ -379,7 +379,7 @@ void DateFormatTest::TestFieldPosition() { "Wed", "225", "2", "33", "3", "PM", "2", "2", "PDT", "1997", "4", "1997", "2450674", "52452513", "-0700", "PT", "4", "8", "3", "3","PDT", "Anno Domini", "1997", "August", "0013", "0014", "0014", "0034", "0012", "5130", - "Wednesday", "0225", "0002", "0033", "0003", "PM", "0002", "0002", "Pacific Daylight Time", "1997", "0004", "1997", "2450674", "52452513", "GMT-07:00", + "Wednesday", "0225", "0002", "0033", "0003", "PM", "0002", "0002", "Pacific Daylight Time", "1997", "Wednesday", "1997", "2450674", "52452513", "GMT-07:00", "Pacific Time", "Wednesday", "August", "3rd quarter", "3rd quarter", "United States (Los Angeles)" };