From cd3f6237f9997548915aaff1ce06a13012829e1d Mon Sep 17 00:00:00 2001 From: John Emmons Date: Mon, 20 Sep 2010 21:22:31 +0000 Subject: [PATCH] ICU-7652 Get correct week data from territory based locale X-SVN-Rev: 28658 --- icu4c/source/data/misc/likelySubtags.txt | 2 ++ icu4c/source/i18n/calendar.cpp | 26 +++++++++++++++++++++++- icu4c/source/test/cintltst/cdtrgtst.c | 6 +++--- icu4c/source/test/intltest/caltest.cpp | 2 +- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/icu4c/source/data/misc/likelySubtags.txt b/icu4c/source/data/misc/likelySubtags.txt index bc1491080b..892bb04ee5 100644 --- a/icu4c/source/data/misc/likelySubtags.txt +++ b/icu4c/source/data/misc/likelySubtags.txt @@ -93,9 +93,11 @@ likelySubtags:table(nofallback){ ig{"ig_Latn_NG"} ii{"ii_Yiii_CN"} ilo{"ilo_Latn_PH"} + in{"in_Latn_ID"} inh{"inh_Cyrl_RU"} is{"is_Latn_IS"} it{"it_Latn_IT"} + iw{"iw_Hebr_IL"} ja{"ja_Jpan_JP"} jmc{"jmc_Latn_TZ"} jv{"jv_Latn_ID"} diff --git a/icu4c/source/i18n/calendar.cpp b/icu4c/source/i18n/calendar.cpp index b91b2065d6..b09409d835 100644 --- a/icu4c/source/i18n/calendar.cpp +++ b/icu4c/source/i18n/calendar.cpp @@ -3242,7 +3242,31 @@ Calendar::setWeekData(const Locale& desiredLocale, const char *type, UErrorCode& fWeekendCease = UCAL_SUNDAY; fWeekendCeaseMillis = 86400000; // 24*60*60*1000 - CalendarData calData(desiredLocale, type, status); + // Since week and weekend data is territory based instead of language based, + // we may need to tweak the locale that we are using to try to get the appropriate + // values, using the following logic: + // 1). If the locale has a language but no territory, use the territory as defined by + // the likely subtags. + // 2). If the locale has a script designation then we ignore it, + // then remove it ( i.e. "en_Latn_US" becomes "en_US" ) + + char minLocaleID[ULOC_FULLNAME_CAPACITY]; + UErrorCode myStatus = U_ZERO_ERROR; + uloc_minimizeSubtags(desiredLocale.getName(),minLocaleID,ULOC_FULLNAME_CAPACITY,&myStatus); + Locale min = Locale::createFromName(minLocaleID); + Locale useLocale; + if ( uprv_strlen(desiredLocale.getCountry()) == 0 || + uprv_strlen(desiredLocale.getScript()) > 0 && uprv_strlen(min.getScript()) == 0 ) { + char maxLocaleID[ULOC_FULLNAME_CAPACITY]; + myStatus = U_ZERO_ERROR; + uloc_addLikelySubtags(desiredLocale.getName(),maxLocaleID,ULOC_FULLNAME_CAPACITY,&myStatus); + Locale max = Locale::createFromName(maxLocaleID); + useLocale = Locale(max.getLanguage(),max.getCountry()); + } else { + useLocale = Locale(desiredLocale); + } + + CalendarData calData(useLocale, type, status); // If the resource data doesn't seem to be present at all, then use last-resort // hard-coded data. UResourceBundle *dateTimeElements = calData.getByKey(gDateTimeElements, status); diff --git a/icu4c/source/test/cintltst/cdtrgtst.c b/icu4c/source/test/cintltst/cdtrgtst.c index b3ba2fe985..4d605faef1 100644 --- a/icu4c/source/test/cintltst/cdtrgtst.c +++ b/icu4c/source/test/cintltst/cdtrgtst.c @@ -514,8 +514,8 @@ static const UChar edMyPattern[] = { 0x65,0x20,0x64,0x64,0x20,0x4D,0x4D,0x4D static const UChar eedMyPattern[] = { 0x65,0x65,0x20,0x64,0x64,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "ee dd MMM yyyy" */ static const UChar cdMyPattern[] = { 0x63,0x20,0x64,0x64,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "c dd MMM yyyy" */ static const UChar ccdMyPattern[] = { 0x63,0x63,0x20,0x64,0x64,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "cc dd MMM yyyy" */ -static const UChar edMyText[] = { 0x33,0x20,0x30,0x32,0x20,0x4A,0x75,0x6C,0x20,0x32,0x30,0x30,0x38,0 }; /* "3 02 Jul 2008" */ -static const UChar eedMyText[] = { 0x30,0x33,0x20,0x30,0x32,0x20,0x4A,0x75,0x6C,0x20,0x32,0x30,0x30,0x38,0 }; /* "03 02 Jul 2008" */ +static const UChar edMyText[] = { 0x34,0x20,0x30,0x32,0x20,0x4A,0x75,0x6C,0x20,0x32,0x30,0x30,0x38,0 }; /* "3 02 Jul 2008" */ +static const UChar eedMyText[] = { 0x30,0x34,0x20,0x30,0x32,0x20,0x4A,0x75,0x6C,0x20,0x32,0x30,0x30,0x38,0 }; /* "03 02 Jul 2008" */ static const UChar eeedMyPattern[] = { 0x65,0x65,0x65,0x20,0x64,0x64,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "eee dd MMM yyyy" */ static const UChar EEEdMyPattern[] = { 0x45,0x45,0x45,0x20,0x64,0x64,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "EEE dd MMM yyyy" */ static const UChar EEdMyPattern[] = { 0x45,0x45,0x20,0x64,0x64,0x20,0x4D,0x4D,0x4D,0x20,0x79,0x79,0x79,0x79,0 }; /* "EE dd MMM yyyy" */ @@ -526,7 +526,7 @@ static const UChar eeeeedMyPattern[] = { 0x65,0x65,0x65,0x65,0x65,0x20,0x64,0x64 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 ewYText[] = { 0x34,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" */ diff --git a/icu4c/source/test/intltest/caltest.cpp b/icu4c/source/test/intltest/caltest.cpp index 86bdb90caf..bac34354a0 100644 --- a/icu4c/source/test/intltest/caltest.cpp +++ b/icu4c/source/test/intltest/caltest.cpp @@ -1323,7 +1323,7 @@ CalendarTest::TestEpochStartFields() } int32_t CalendarTest::EPOCH_FIELDS[] = { - 1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, - 28800000, 0 + 1, 1970, 0, 53, 0, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, - 28800000, 0 }; // -------------------------------------