mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-09 07:22:11 +00:00
ICU-7616 Enable non-Gregorian calendars for DateIntervalFormat
X-SVN-Rev: 27947
This commit is contained in:
parent
8dc0dfc1f3
commit
f3c6395224
7 changed files with 279 additions and 12 deletions
|
@ -70,6 +70,108 @@ th{
|
|||
"พุทธศักราช",
|
||||
}
|
||||
}
|
||||
intervalFormats{
|
||||
H{
|
||||
H{"H-H"}
|
||||
a{"H-H"}
|
||||
}
|
||||
Hm{
|
||||
H{"H:mm-H:mm"}
|
||||
a{"H:mm-H:mm"}
|
||||
m{"H:mm-H:mm"}
|
||||
}
|
||||
Hmv{
|
||||
H{"H:mm-H:mm v"}
|
||||
a{"H:mm-H:mm v"}
|
||||
m{"H:mm-H:mm v"}
|
||||
}
|
||||
Hv{
|
||||
H{"H-H v"}
|
||||
a{"H-H v"}
|
||||
}
|
||||
M{
|
||||
M{"M-M"}
|
||||
}
|
||||
MEd{
|
||||
M{"E d – E d/M"}
|
||||
d{"E d – E d/M"}
|
||||
}
|
||||
MMM{
|
||||
M{"LLL-LLL"}
|
||||
}
|
||||
MMMEd{
|
||||
M{"E d MMM – E d MMM"}
|
||||
d{"E d – E d MMM"}
|
||||
}
|
||||
MMMM{
|
||||
M{"LLLL-LLLL"}
|
||||
}
|
||||
MMMd{
|
||||
M{"d MMM – d MMM"}
|
||||
d{"d – d MMM"}
|
||||
}
|
||||
Md{
|
||||
M{"d/M - d/M"}
|
||||
d{"d/M - d/M"}
|
||||
}
|
||||
d{
|
||||
d{"d-d"}
|
||||
}
|
||||
fallback{"{0} - {1}"}
|
||||
h{
|
||||
a{"h a - h a"}
|
||||
h{"h-h a"}
|
||||
}
|
||||
hm{
|
||||
a{"h:mm a - h:mm a"}
|
||||
h{"h:mm-h:mm a"}
|
||||
m{"h:mm-h:mm a"}
|
||||
}
|
||||
hmv{
|
||||
a{"h:mm a - h:mm a v"}
|
||||
h{"h:mm-h:mm a v"}
|
||||
m{"h:mm-h:mm a v"}
|
||||
}
|
||||
hv{
|
||||
a{"h a - h a v"}
|
||||
h{"h-h a v"}
|
||||
}
|
||||
y{
|
||||
y{"y-y"}
|
||||
}
|
||||
yM{
|
||||
M{"M/yy – M/yy"}
|
||||
y{"M/yy – M/yy"}
|
||||
}
|
||||
yMEd{
|
||||
M{"E d/M/yy – E d/M/yy"}
|
||||
d{"E d – E d/M/yy"}
|
||||
y{"E d/M/yy – E d/M/yy"}
|
||||
}
|
||||
yMMM{
|
||||
M{"MMM-MMM y"}
|
||||
y{"MMM y - MMM y"}
|
||||
}
|
||||
yMMMEd{
|
||||
M{"E d MMM – E d MMM y"}
|
||||
d{"E d – E d MMM y"}
|
||||
y{"E d MMM y – E d MMM y"}
|
||||
}
|
||||
yMMMM{
|
||||
M{"M–M/yyyy"}
|
||||
y{"M/yyyy – M/yyyy"}
|
||||
}
|
||||
yMMMd{
|
||||
M{"d MMM – d MMM y"}
|
||||
d{"d–d MMM y"}
|
||||
y{"d MMM y – d MMM y"}
|
||||
}
|
||||
yMd{
|
||||
M{"d/M/yy – d/M/yy"}
|
||||
d{"d-d/M/yy"}
|
||||
y{"d/M/yy – d/M/yy"}
|
||||
}
|
||||
}
|
||||
}
|
||||
default{"buddhist"}
|
||||
gregorian{
|
||||
|
|
|
@ -283,8 +283,7 @@ DateIntervalFormat::format(Calendar& fromCalendar,
|
|||
|
||||
// not support different calendar types and time zones
|
||||
//if ( fromCalendar.getType() != toCalendar.getType() ) {
|
||||
if ( !fromCalendar.isEquivalentTo(toCalendar) ||
|
||||
uprv_strcmp(fromCalendar.getType(), "gregorian") ) {
|
||||
if ( !fromCalendar.isEquivalentTo(toCalendar) ) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return appendTo;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
#include "cstring.h"
|
||||
#include "unicode/msgfmt.h"
|
||||
#include "unicode/uloc.h"
|
||||
#include "unicode/ures.h"
|
||||
#include "dtitv_impl.h"
|
||||
#include "hash.h"
|
||||
#include "gregoimp.h"
|
||||
|
@ -208,6 +210,7 @@ DateIntervalInfo::getFallbackIntervalPattern(UnicodeString& result) const {
|
|||
return result;
|
||||
}
|
||||
|
||||
#define ULOC_LOCALE_IDENTIFIER_CAPACITY (ULOC_FULLNAME_CAPACITY + 1 + ULOC_KEYWORD_AND_VALUES_CAPACITY)
|
||||
|
||||
void
|
||||
DateIntervalInfo::initializeData(const Locale& locale, UErrorCode& err)
|
||||
|
@ -225,12 +228,28 @@ DateIntervalInfo::initializeData(const Locale& locale, UErrorCode& err)
|
|||
if ( U_FAILURE(status) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// determine calendar type
|
||||
const char * calendarTypeToUse = gGregorianTag; // initial default
|
||||
char calendarType[ULOC_KEYWORDS_CAPACITY]; // to be filled in with the type to use, if all goes well
|
||||
char localeWithCalendarKey[ULOC_LOCALE_IDENTIFIER_CAPACITY];
|
||||
// obtain a locale that always has the calendar key value that should be used
|
||||
(void)ures_getFunctionalEquivalent(localeWithCalendarKey, ULOC_LOCALE_IDENTIFIER_CAPACITY, NULL,
|
||||
"calendar", "calendar", locName, NULL, FALSE, &status);
|
||||
localeWithCalendarKey[ULOC_LOCALE_IDENTIFIER_CAPACITY-1] = 0; // ensure null termination
|
||||
// now get the calendar key value from that locale
|
||||
int32_t calendarTypeLen = uloc_getKeywordValue(localeWithCalendarKey, "calendar", calendarType, ULOC_KEYWORDS_CAPACITY, &status);
|
||||
if (U_SUCCESS(status) && calendarTypeLen < ULOC_KEYWORDS_CAPACITY) {
|
||||
calendarTypeToUse = calendarType;
|
||||
}
|
||||
status = U_ZERO_ERROR;
|
||||
|
||||
do {
|
||||
UResourceBundle *rb, *calBundle, *gregorianBundle, *itvDtPtnResource;
|
||||
UResourceBundle *rb, *calBundle, *calTypeBundle, *itvDtPtnResource;
|
||||
rb = ures_open(NULL, parentLocale, &status);
|
||||
calBundle = ures_getByKey(rb, gCalendarTag, NULL, &status);
|
||||
gregorianBundle = ures_getByKey(calBundle, gGregorianTag, NULL, &status);
|
||||
itvDtPtnResource = ures_getByKeyWithFallback(gregorianBundle,
|
||||
calTypeBundle = ures_getByKey(calBundle, calendarTypeToUse, NULL, &status);
|
||||
itvDtPtnResource = ures_getByKeyWithFallback(calTypeBundle,
|
||||
gIntervalDateTimePatternTag, NULL, &status);
|
||||
|
||||
if ( U_SUCCESS(status) ) {
|
||||
|
@ -313,7 +332,7 @@ DateIntervalInfo::initializeData(const Locale& locale, UErrorCode& err)
|
|||
}
|
||||
}
|
||||
ures_close(itvDtPtnResource);
|
||||
ures_close(gregorianBundle);
|
||||
ures_close(calTypeBundle);
|
||||
ures_close(calBundle);
|
||||
ures_close(rb);
|
||||
status = U_ZERO_ERROR;
|
||||
|
|
|
@ -34,8 +34,7 @@ U_NAMESPACE_BEGIN
|
|||
/**
|
||||
* DateIntervalFormat is a class for formatting and parsing date
|
||||
* intervals in a language-independent manner.
|
||||
* Date interval formatting is supported in Gregorian calendar only.
|
||||
* And only formatting is supported. Parsing is not supported.
|
||||
* Only formatting is supported, parsing is not supported.
|
||||
*
|
||||
* <P>
|
||||
* Date interval means from one date to another date,
|
||||
|
|
|
@ -151,7 +151,8 @@ U_NAMESPACE_BEGIN
|
|||
* <P>
|
||||
* DateIntervalInfo are not expected to be subclassed.
|
||||
* Data for a calendar is loaded out of resource bundles.
|
||||
* To ICU 4.0, date interval patterns are only supported in Gregorian calendar.
|
||||
* Through ICU 4.4, date interval patterns are only supported in the Gregorian
|
||||
* calendar; non-Gregorian calendars are supported from ICU 4.4.1.
|
||||
* @stable ICU 4.0
|
||||
**/
|
||||
|
||||
|
@ -175,8 +176,8 @@ public:
|
|||
|
||||
/**
|
||||
* Construct DateIntervalInfo for the given locale,
|
||||
* @param locale the interval patterns are loaded from the Gregorian
|
||||
* calendar data in this locale.
|
||||
* @param locale the interval patterns are loaded from the appropriate calendar
|
||||
* data (specified calendar or default calendar) in this locale.
|
||||
* @param status output param set to success/failure code on exit
|
||||
* @stable ICU 4.0
|
||||
*/
|
||||
|
|
|
@ -881,6 +881,51 @@ void DateIntervalFormatTest::testFormat() {
|
|||
"de", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "hv", "10 vorm. Vereinigte Staaten (Los Angeles)",
|
||||
|
||||
"de", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "hz", "10 vorm. GMT-08:00",
|
||||
|
||||
// Thai (default calendar buddhist)
|
||||
|
||||
"th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "EEEEdMMMy", "\\u0E27\\u0E31\\u0E19\\u0E1E\\u0E38\\u0E18 10 \\u0E15.\\u0E04. 2550 \\u2013 \\u0E27\\u0E31\\u0E19\\u0E28\\u0E38\\u0E01\\u0E23\\u0E4C 10 \\u0E15.\\u0E04. 2551",
|
||||
|
||||
|
||||
"th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "dMMM", "10 \\u0E15.\\u0E04. 2550 \\u2013 10 \\u0E15.\\u0E04. 2551",
|
||||
|
||||
"th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "MMMy", "\\u0E15.\\u0E04. 2550 - \\u0E15.\\u0E04. 2551",
|
||||
|
||||
|
||||
"th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "EdMy", "\\u0E1E. 10/10/50 \\u2013 \\u0E28. 10/10/51",
|
||||
|
||||
"th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "dMy", "10/10/50 \\u2013 10/10/51",
|
||||
|
||||
|
||||
"th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "My", "10/50 \\u2013 10/51",
|
||||
|
||||
"th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "EdM", "\\u0E1E. 10/10/50 \\u2013 \\u0E28. 10/10/51",
|
||||
|
||||
|
||||
"th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "y", "2550-2551",
|
||||
|
||||
"th", "2550 10 10 10:10:10", "2551 10 10 10:10:10", "M", "10/50 \\u2013 10/51",
|
||||
|
||||
|
||||
"th", "2550 10 10 10:10:10", "2550 11 10 10:10:10", "EEEEdMMMy", "\\u0E27\\u0E31\\u0E19\\u0E1E\\u0E38\\u0E18 10 \\u0E15.\\u0E04. \\u2013 \\u0E27\\u0E31\\u0E19\\u0E40\\u0E2A\\u0E32\\u0E23\\u0E4C 10 \\u0E1E.\\u0E22. 2550",
|
||||
|
||||
|
||||
"th", "2550 10 10 10:10:10", "2550 11 10 10:10:10", "dMMM", "10 \\u0E15.\\u0E04. \\u2013 10 \\u0E1E.\\u0E22.",
|
||||
|
||||
"th", "2550 10 10 10:10:10", "2550 11 10 10:10:10", "MMMy", "\\u0E15.\\u0E04.-\\u0E1E.\\u0E22. 2550",
|
||||
|
||||
"th", "2550 10 10 10:10:10", "2550 11 10 10:10:10", "dM", "10/10 - 10/11",
|
||||
|
||||
"th", "2550 10 10 10:10:10", "2550 11 10 10:10:10", "My", "10/50 \\u2013 11/50",
|
||||
|
||||
|
||||
"th", "2550 10 10 10:10:10", "2550 11 10 10:10:10", "d", "10/10 - 10/11",
|
||||
|
||||
"th", "2550 10 10 10:10:10", "2550 11 10 10:10:10", "y", "2550",
|
||||
|
||||
|
||||
"th", "2550 10 10 10:10:10", "2550 11 10 10:10:10", "MMM", "\\u0E15.\\u0E04.-\\u0E1E.\\u0E22.",
|
||||
|
||||
};
|
||||
expect(DATA, ARRAY_SIZE(DATA));
|
||||
}
|
||||
|
|
104
icu4c/source/test/testdata/structLocale.txt
vendored
104
icu4c/source/test/testdata/structLocale.txt
vendored
|
@ -4662,7 +4662,109 @@ structLocale:table(nofallback){
|
|||
"",
|
||||
}
|
||||
}
|
||||
}
|
||||
intervalFormats{
|
||||
H{
|
||||
H{""}
|
||||
a{""}
|
||||
}
|
||||
Hm{
|
||||
H{""}
|
||||
a{""}
|
||||
m{""}
|
||||
}
|
||||
Hmv{
|
||||
H{""}
|
||||
a{""}
|
||||
m{""}
|
||||
}
|
||||
Hv{
|
||||
H{""}
|
||||
a{""}
|
||||
}
|
||||
M{
|
||||
M{""}
|
||||
}
|
||||
MEd{
|
||||
M{""}
|
||||
d{""}
|
||||
}
|
||||
MMM{
|
||||
M{""}
|
||||
}
|
||||
MMMEd{
|
||||
M{""}
|
||||
d{""}
|
||||
}
|
||||
MMMM{
|
||||
M{""}
|
||||
}
|
||||
MMMd{
|
||||
M{""}
|
||||
d{""}
|
||||
}
|
||||
Md{
|
||||
M{""}
|
||||
d{""}
|
||||
}
|
||||
d{
|
||||
d{""}
|
||||
}
|
||||
fallback{""}
|
||||
h{
|
||||
a{""}
|
||||
h{""}
|
||||
}
|
||||
hm{
|
||||
a{""}
|
||||
h{""}
|
||||
m{""}
|
||||
}
|
||||
hmv{
|
||||
a{""}
|
||||
h{""}
|
||||
m{""}
|
||||
}
|
||||
hv{
|
||||
a{""}
|
||||
h{""}
|
||||
}
|
||||
y{
|
||||
y{""}
|
||||
}
|
||||
yM{
|
||||
M{""}
|
||||
y{""}
|
||||
}
|
||||
yMEd{
|
||||
M{""}
|
||||
d{""}
|
||||
y{""}
|
||||
}
|
||||
yMMM{
|
||||
M{""}
|
||||
y{""}
|
||||
}
|
||||
yMMMEd{
|
||||
M{""}
|
||||
d{""}
|
||||
y{""}
|
||||
}
|
||||
yMMMM{
|
||||
M{""}
|
||||
y{""}
|
||||
}
|
||||
yMMMd{
|
||||
M{""}
|
||||
d{""}
|
||||
y{""}
|
||||
}
|
||||
yMd{
|
||||
M{""}
|
||||
d{""}
|
||||
y{""}
|
||||
}
|
||||
}
|
||||
}
|
||||
chinese{
|
||||
AmPmMarkers{
|
||||
"",
|
||||
|
|
Loading…
Add table
Reference in a new issue