ICU-6157 update after 1st round code review

X-SVN-Rev: 24200
This commit is contained in:
Xiaomei Ji 2008-06-16 22:32:36 +00:00
parent 7f5016dd78
commit 0ad3aff9b2
12 changed files with 1640 additions and 509 deletions

View File

@ -20,7 +20,7 @@ UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateInterval)
//DateInterval::DateInterval(){}
DateInterval::DateInterval(const UDate from, const UDate to)
DateInterval::DateInterval(UDate from, UDate to)
: fromDate(from),
toDate(to)
{}
@ -45,6 +45,17 @@ DateInterval::operator=(const DateInterval& other) {
}
DateInterval*
DateInterval::clone() const {
return new DateInterval(*this);
}
UBool
DateInterval::operator==(const DateInterval& other) const {
return ( fromDate == other.fromDate && toDate == other.toDate );
}
U_NAMESPACE_END

View File

@ -25,7 +25,7 @@ U_NAMESPACE_BEGIN
/**
* This class represents date interval.
* This class represents a date interval.
* It is a pair of UDate representing from UDate 1 to UDate 2.
* @draft ICU 4.0
**/
@ -33,18 +33,18 @@ class U_COMMON_API DateInterval : public UObject {
public:
/**
* Constructor given from date and to date.
* Construct a DateInterval given a from date and a to date.
* @param fromDate The from date in date interval.
* @param toDate The to date in date interval.
* @draft ICU 4.0
*/
DateInterval(const UDate fromDate, const UDate toDate);
DateInterval(UDate fromDate, UDate toDate);
/**
* destructor
* @draft ICU 4.0
*/
~DateInterval();
virtual ~DateInterval();
/**
* Get the from date.
@ -105,7 +105,7 @@ public:
* @return TRUE if the two DateIntervals are the same
* @draft ICU 4.0
*/
UBool operator==(const DateInterval& other) const;
virtual UBool operator==(const DateInterval& other) const;
/**
* Non-equality operator
@ -121,7 +121,7 @@ public:
* @return a cloned DateInterval
* @draft ICU 4.0
*/
DateInterval* clone() const;
virtual DateInterval* clone() const;
private:
/**
@ -148,25 +148,12 @@ DateInterval::getToDate() const {
}
inline UBool
DateInterval::operator==(const DateInterval& other) const {
return ( fromDate == other.fromDate && toDate == other.toDate );
}
inline UBool
DateInterval::operator!=(const DateInterval& other) const {
return ( !operator==(other) );
}
inline DateInterval*
DateInterval::clone() const {
return new DateInterval(*this);
}
U_NAMESPACE_END
#endif

View File

@ -278,17 +278,24 @@ DateFormat::createInstance()
//----------------------------------------------------------------------
DateFormat* U_EXPORT2
DateFormat::createPatternInstance(const UnicodeString& skeleton,
const Locale& locale)
const Locale& locale,
UErrorCode& status)
{
UErrorCode status = U_ZERO_ERROR;
if ( U_FAILURE(status) ) {
return NULL;
}
DateTimePatternGenerator* dtptg =
DateTimePatternGenerator::createInstance(locale, status);
if ( dtptg == NULL || U_FAILURE(status) ) {
if ( dtptg == NULL ) {
status = U_MEMORY_ALLOCATION_ERROR;
delete dtptg;
return NULL;
}
if ( U_FAILURE(status) ) {
delete dtptg;
return NULL;
}
const UnicodeString pattern = dtptg->getBestPattern(skeleton, status);
delete dtptg;

View File

@ -15,6 +15,7 @@
//FIXME: put in compilation
//#define DTITVFMT_DEBUG 1
#include "cstring.h"
#include "unicode/msgfmt.h"
#include "unicode/dtptngen.h"
#include "unicode/dtitvinf.h"
@ -73,10 +74,7 @@ DateIntervalFormat* U_EXPORT2
DateIntervalFormat::createInstance(const UnicodeString& skeleton,
const Locale& locale,
UErrorCode& status) {
if ( U_FAILURE(status) ) {
return NULL;
}
DateFormat* dtfmt = DateFormat::createPatternInstance(skeleton, locale);
DateFormat* dtfmt = DateFormat::createPatternInstance(skeleton, locale, status);
#ifdef DTITVFMT_DEBUG
char result[1000];
@ -98,7 +96,7 @@ DateIntervalFormat::createInstance(const UnicodeString& skeleton,
DateIntervalFormat* U_EXPORT2
DateIntervalFormat::createInstance(const UnicodeString& skeleton,
DateIntervalInfo* dtitvinf,
const DateIntervalInfo& dtitvinf,
UErrorCode& status) {
return createInstance(skeleton, Locale::getDefault(), dtitvinf, status);
}
@ -107,14 +105,11 @@ DateIntervalFormat::createInstance(const UnicodeString& skeleton,
DateIntervalFormat* U_EXPORT2
DateIntervalFormat::createInstance(const UnicodeString& skeleton,
const Locale& locale,
DateIntervalInfo* dtitvinf,
const DateIntervalInfo& dtitvinf,
UErrorCode& status) {
if ( U_FAILURE(status) ) {
delete dtitvinf;
return NULL;
}
DateFormat* dtfmt = DateFormat::createPatternInstance(skeleton, locale);
return create(dtfmt, dtitvinf, &skeleton, status);
DateFormat* dtfmt = DateFormat::createPatternInstance(skeleton, locale, status);
DateIntervalInfo* ptn = dtitvinf.clone();
return create(dtfmt, ptn, &skeleton, status);
}
@ -229,7 +224,6 @@ DateIntervalFormat::operator==(const Format& other) const {
UnicodeString&
DateIntervalFormat::format(const Formattable& obj,
UnicodeString& appendTo,
@ -283,7 +277,8 @@ DateIntervalFormat::format(Calendar& fromCalendar,
// not support different calendar types and time zones
//if ( fromCalendar.getType() != toCalendar.getType() ) {
if ( !fromCalendar.isEquivalentTo(toCalendar) ) {
if ( !fromCalendar.isEquivalentTo(toCalendar) ||
uprv_strcmp(fromCalendar.getType(), "gregorian") ) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return appendTo;
}
@ -323,7 +318,8 @@ DateIntervalFormat::format(Calendar& fromCalendar,
return fDateFormat->format(fromCalendar, appendTo, pos);
}
// following will not set wrong status
// following call should not set wrong status,
// all the pass-in fields are valid till here
int32_t itvPtnIndex = DateIntervalInfo::calendarFieldToIntervalIndex(field,
status);
const PatternInfo& intervalPattern = fIntervalPatterns[itvPtnIndex];
@ -380,76 +376,38 @@ void
DateIntervalFormat::parseObject(const UnicodeString& /* source */,
Formattable& /* result */,
ParsePosition& /* parse_pos */) const {
// FIXME: THERE is no error code,
// then, where to set the not-supported error
// parseObject(const UnicodeString&, Formattable&, UErrorCode&) const
// will set status as U_INVALID_FORMAT_ERROR if
// parse_pos is still 0
}
const DateIntervalInfo*
DateIntervalFormat::getDateIntervalInfo() const {
return fInfo;
}
void
DateIntervalFormat::setDateFormat(const DateFormat& newDateFormat,
UErrorCode& status) {
if ( U_FAILURE(status) ) {
return;
}
if ( newDateFormat.getDynamicClassID() == SimpleDateFormat::getStaticClassID() ) {
delete fDateFormat;
delete fFromCalendar;
delete fToCalendar;
fDateFormat = new SimpleDateFormat((SimpleDateFormat&)newDateFormat);
if ( fDateFormat && fDateFormat->getCalendar() ) {
fFromCalendar = fDateFormat->getCalendar()->clone();
fToCalendar = fDateFormat->getCalendar()->clone();
} else {
fFromCalendar = NULL;
fToCalendar = NULL;
}
if ( fInfo ) {
initializePattern(status);
}
} else {
status = U_ILLEGAL_ARGUMENT_ERROR;
DateIntervalFormat::setDateIntervalInfo(const DateIntervalInfo& newItvPattern,
UErrorCode& status) {
delete fInfo;
fInfo = new DateIntervalInfo(newItvPattern);
if ( fDateFormat ) {
initializePattern(status);
}
}
void
DateIntervalFormat::adoptDateFormat(DateFormat* newDateFormat,
UErrorCode& status) {
if ( U_FAILURE(status) ) {
return;
}
if ( newDateFormat->getDynamicClassID() == SimpleDateFormat::getStaticClassID() ) {
delete fDateFormat;
delete fFromCalendar;
delete fToCalendar;
fDateFormat = (SimpleDateFormat*)newDateFormat;
if ( fDateFormat && fDateFormat->getCalendar() ) {
fFromCalendar = fDateFormat->getCalendar()->clone();
fToCalendar = fDateFormat->getCalendar()->clone();
} else {
fFromCalendar = NULL;
fToCalendar = NULL;
}
if ( fInfo ) {
initializePattern(status);
}
} else {
status = U_ILLEGAL_ARGUMENT_ERROR;
}
const DateFormat*
DateIntervalFormat::getDateFormat() const {
return fDateFormat;
}
DateIntervalFormat::DateIntervalFormat(DateFormat* dtfmt,
DateIntervalInfo* dtItvInfo,
UErrorCode& status)
{
DateIntervalFormat(dtfmt, dtItvInfo, NULL, status);
}
DateIntervalFormat::DateIntervalFormat(DateFormat* dtfmt,
DateIntervalInfo* dtItvInfo,
const UnicodeString* skeleton,
@ -488,15 +446,6 @@ DateIntervalFormat::DateIntervalFormat(DateFormat* dtfmt,
DateIntervalFormat* U_EXPORT2
DateIntervalFormat::create(DateFormat* dtfmt,
DateIntervalInfo* dtItvInfo,
UErrorCode& status) {
return create(dtfmt, dtItvInfo, NULL, status);
}
DateIntervalFormat* U_EXPORT2
DateIntervalFormat::create(DateFormat* dtfmt,
DateIntervalInfo* dtitvinf,
@ -554,7 +503,9 @@ DateIntervalFormat::create(DateFormat* dtfmt,
*/
void
DateIntervalFormat::initializePattern(UErrorCode& status) {
// FIXME: WHY can not getLocale()
if ( U_FAILURE(status) ) {
return;
}
const Locale& locale = fDateFormat->getSmpFmtLocale();
DateTimePatternGenerator* dtpng = DateTimePatternGenerator::createInstance(locale, status);
if ( U_FAILURE(status) ) {
@ -708,6 +659,12 @@ DateIntervalFormat::initializePattern(UErrorCode& status) {
// calendar, that is why need to get the CalendarData here.
CalendarData* calData = new CalendarData(locale, NULL, status);
if ( U_FAILURE(status) ) {
delete calData;
delete dtpng;
return;
}
if ( calData == NULL ) {
status = U_MEMORY_ALLOCATION_ERROR;
delete dtpng;
@ -848,8 +805,6 @@ DateIntervalFormat::getDateTimeSkeleton(const UnicodeString& skeleton,
if ( ECount != 0 ) {
if ( ECount <= 3 ) {
normalizedDateSkeleton.append(CAP_E);
normalizedDateSkeleton.append(CAP_E);
normalizedDateSkeleton.append(CAP_E);
} else {
int32_t i;
for ( i = 0; i < ECount && i < MAX_E_COUNT; ++i ) {
@ -929,6 +884,18 @@ DateIntervalFormat::setSeparateDateTimePtn(
int8_t differenceInfo = 0;
const UnicodeString* bestSkeleton = fInfo->getBestSkeleton(*skeleton,
differenceInfo);
/* best skeleton could be NULL.
For example: in "ca" resource file,
interval format is defined as following
intervalFormats{
fallback{"{0} - {1}"}
}
there is no skeletons/interval patterns defined,
and the best skeleton match could be NULL
*/
if ( bestSkeleton == NULL ) {
return false;
}
// difference:
// 0 means the best matched skeleton is the same as input skeleton
@ -995,9 +962,12 @@ DateIntervalFormat::setPatternInfo(UCalendarDateFields field,
// the second part of the pattern is the full-pattern
// should be used in fall-back.
UErrorCode status = U_ZERO_ERROR;
// following will not set any wrong status.
// following should not set any wrong status.
int32_t itvPtnIndex = DateIntervalInfo::calendarFieldToIntervalIndex(field,
status);
if ( U_FAILURE(status) ) {
return;
}
PatternInfo& ptn = fIntervalPatterns[itvPtnIndex];
if ( firstPart ) {
ptn.firstPart = *firstPart;
@ -1224,6 +1194,9 @@ DateIntervalFormat::fallbackFormat(Calendar& fromCalendar,
UnicodeString& appendTo,
FieldPosition& pos,
UErrorCode& status) const {
if ( U_FAILURE(status) ) {
return appendTo;
}
// the fall back
// no need delete earlierDate and laterDate since they are adopted
UnicodeString* earlierDate = new UnicodeString();
@ -1237,10 +1210,9 @@ DateIntervalFormat::fallbackFormat(Calendar& fromCalendar,
UnicodeString fallback;
MessageFormat::format(fallbackPattern, fmtArray, 2, fallback, status);
if ( U_FAILURE(status) ) {
return appendTo;
if ( U_SUCCESS(status) ) {
appendTo.append(fallback);
}
appendTo.append(fallback);
return appendTo;
}
@ -1373,12 +1345,12 @@ DateIntervalFormat::concatSingleDate2TimeInterval(const UChar* format,
const UnicodeString& datePattern,
UCalendarDateFields field,
UErrorCode& status) {
// following should not set wrong status
int32_t itvPtnIndex = DateIntervalInfo::calendarFieldToIntervalIndex(field,
status);
if ( U_FAILURE(status) ) {
return;
}
// following will not set wrong status
int32_t itvPtnIndex = DateIntervalInfo::calendarFieldToIntervalIndex(field,
status);
PatternInfo& timeItvPtnInfo = fIntervalPatterns[itvPtnIndex];
if ( !timeItvPtnInfo.firstPart.isEmpty() ) {
// UnicodeString allocated here is adopted, so no need to delete

View File

@ -13,7 +13,7 @@
#if !UCONFIG_NO_FORMATTING
//FIXME: how to define it in compiler time
//FIXME: define it in compiler time
//#define DTITVINF_DEBUG 0
@ -41,8 +41,10 @@ U_NAMESPACE_BEGIN
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateIntervalInfo)
static const char gIntervalDateTimePatternTag[]="IntervalDateTimePatterns";
static const char gFallbackPatternTag[]="Fallback";
static const char gCalendarTag[]="calendar";
static const char gGregorianTag[]="gregorian";
static const char gIntervalDateTimePatternTag[]="intervalFormats";
static const char gFallbackPatternTag[]="fallback";
// {0}
static const UChar gFirstPattern[] = {LEFT_CURLY_BRACKET, DIGIT_ZERO, RIGHT_CURLY_BRACKET, 0};
@ -59,9 +61,6 @@ DateIntervalInfo::DateIntervalInfo(UErrorCode& status)
fFirstDateInPtnIsLaterDate(false),
fIntervalPatterns(NULL)
{
if ( U_FAILURE(status) ) {
return;
}
fIntervalPatterns = initHash(status);
}
@ -72,9 +71,6 @@ DateIntervalInfo::DateIntervalInfo(const Locale& locale, UErrorCode& status)
fFirstDateInPtnIsLaterDate(false),
fIntervalPatterns(NULL)
{
if ( U_FAILURE(status) ) {
return;
}
initializeData(locale, status);
}
@ -85,9 +81,6 @@ DateIntervalInfo::setIntervalPattern(const UnicodeString& skeleton,
UCalendarDateFields lrgDiffCalUnit,
const UnicodeString& intervalPattern,
UErrorCode& status) {
if ( U_FAILURE(status) ) {
return;
}
if ( lrgDiffCalUnit == UCAL_HOUR_OF_DAY ) {
setIntervalPatternInternally(skeleton, UCAL_AM_PM, intervalPattern, status);
@ -134,9 +127,6 @@ DateIntervalInfo::operator=(const DateIntervalInfo& dtitvinf) {
UErrorCode status = U_ZERO_ERROR;
deleteHash(fIntervalPatterns);
fIntervalPatterns = initHash(status);
if ( U_FAILURE(status) ) {
return *this;
}
copyHash(dtitvinf.fIntervalPatterns, fIntervalPatterns, status);
if ( U_FAILURE(status) ) {
return *this;
@ -198,105 +188,115 @@ DateIntervalInfo::getIntervalPattern(const UnicodeString& skeleton,
void
DateIntervalInfo::initializeData(const Locale& locale, UErrorCode& status)
DateIntervalInfo::initializeData(const Locale& locale, UErrorCode& err)
{
fIntervalPatterns = initHash(status);
if ( U_FAILURE(status) ) {
return;
}
CalendarData* calData = new CalendarData(locale, NULL, status);
if ( calData == NULL ) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
fIntervalPatterns = initHash(err);
if ( U_FAILURE(err) ) {
return;
}
const char *locName = locale.getName();
char parentLocale[50];
int32_t locNameLen;
uprv_strcpy(parentLocale, locName);
UErrorCode status = U_ZERO_ERROR;
Hashtable skeletonSet(TRUE, status);
if ( U_FAILURE(status) ) {
return;
}
do {
UResourceBundle *rb, *calBundle, *gregorianBundle, *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,
gIntervalDateTimePatternTag, NULL, &status);
const UResourceBundle* itvDtPtnResource = calData->getByKey(
gIntervalDateTimePatternTag, status);
// look for fallback first, since it establishes the default order
const UChar* resStr;
int32_t resStrLen = 0;
resStr = ures_getStringByKeyWithFallback(itvDtPtnResource,
if ( U_SUCCESS(status) ) {
// look for fallback first, since it establishes the default order
const UChar* resStr;
int32_t resStrLen = 0;
resStr = ures_getStringByKeyWithFallback(itvDtPtnResource,
gFallbackPatternTag,
&resStrLen, &status);
if ( U_FAILURE(status) ) {
delete calData;
return;
if ( U_SUCCESS(status) ) {
UnicodeString pattern = UnicodeString(TRUE, resStr, resStrLen);
setFallbackIntervalPattern(pattern);
}
int32_t size = ures_getSize(itvDtPtnResource);
int32_t index;
for ( index = 0; index < size; ++index ) {
UResourceBundle* oneRes = ures_getByIndex(itvDtPtnResource, index,
NULL, &status);
if ( U_SUCCESS(status) ) {
const char* skeleton = ures_getKey(oneRes);
if ( skeleton == NULL ||
skeletonSet.geti(UnicodeString(skeleton)) == 1 ) {
ures_close(oneRes);
continue;
}
skeletonSet.puti(UnicodeString(skeleton), 1, status);
if ( uprv_strcmp(skeleton, gFallbackPatternTag) == 0 ) {
ures_close(oneRes);
continue; // fallback
}
UResourceBundle* intervalPatterns = ures_getByKey(
itvDtPtnResource, skeleton, NULL, &status);
if ( U_FAILURE(status) ) {
ures_close(intervalPatterns);
ures_close(oneRes);
break;
}
if ( intervalPatterns == NULL ) {
ures_close(intervalPatterns);
ures_close(oneRes);
continue;
}
const UChar* pattern;
const char* key;
int32_t ptLength;
int32_t ptnNum = ures_getSize(intervalPatterns);
int32_t ptnIndex;
for ( ptnIndex = 0; ptnIndex < ptnNum; ++ptnIndex ) {
pattern = ures_getNextString(intervalPatterns, &ptLength, &key,
&status);
if ( U_FAILURE(status) ) {
break;
}
UCalendarDateFields calendarField = UCAL_FIELD_COUNT;
if ( !uprv_strcmp(key, "y") ) {
calendarField = UCAL_YEAR;
} else if ( !uprv_strcmp(key, "M") ) {
calendarField = UCAL_MONTH;
} else if ( !uprv_strcmp(key, "d") ) {
calendarField = UCAL_DATE;
} else if ( !uprv_strcmp(key, "a") ) {
calendarField = UCAL_AM_PM;
} else if ( !uprv_strcmp(key, "h") ) {
calendarField = UCAL_HOUR;
} else if ( !uprv_strcmp(key, "m") ) {
calendarField = UCAL_MINUTE;
}
if ( calendarField != UCAL_FIELD_COUNT ) {
setIntervalPatternInternally(skeleton, calendarField, pattern,status);
}
}
ures_close(intervalPatterns);
}
ures_close(oneRes);
}
}
UnicodeString pattern = UnicodeString(TRUE, resStr, resStrLen);
setFallbackIntervalPattern(pattern);
int32_t size = ures_getSize(itvDtPtnResource);
int32_t index;
for ( index = 0; index < size; ++index ) {
UResourceBundle* oneRes = ures_getByIndex(itvDtPtnResource, index,
NULL, &status);
if ( U_FAILURE(status) ) {
delete calData;
return;
}
const char* skeleton = ures_getKey(oneRes);
ures_close(oneRes);
if ( skeleton == NULL ) {
status = U_MISSING_RESOURCE_ERROR;
delete calData;
return;
}
if ( uprv_strcmp(skeleton, gFallbackPatternTag) == 0 ) {
continue; // fallback
}
UResourceBundle* intervalPatterns = ures_getByKey(itvDtPtnResource,
skeleton, NULL, &status);
if ( U_FAILURE(status) ) {
delete calData;
return;
}
// return if interval patterns for skeleton not found
if ( intervalPatterns == NULL ) {
status = U_MISSING_RESOURCE_ERROR;
delete calData;
return;
}
const UChar* pattern;
const char* key;
int32_t ptLength;
int32_t ptnNum = ures_getSize(intervalPatterns);
int32_t ptnIndex;
for ( ptnIndex = 0; ptnIndex < ptnNum; ++ptnIndex ) {
pattern = ures_getNextString(intervalPatterns, &ptLength, &key,
&status);
if ( U_FAILURE(status) ) {
delete calData;
return;
}
UCalendarDateFields calendarField = UCAL_FIELD_COUNT;
if ( !uprv_strcmp(key, "y") ) {
calendarField = UCAL_YEAR;
} else if ( !uprv_strcmp(key, "M") ) {
calendarField = UCAL_MONTH;
} else if ( !uprv_strcmp(key, "d") ) {
calendarField = UCAL_DATE;
} else if ( !uprv_strcmp(key, "a") ) {
calendarField = UCAL_AM_PM;
} else if ( !uprv_strcmp(key, "h") ) {
calendarField = UCAL_HOUR;
} else if ( !uprv_strcmp(key, "m") ) {
calendarField = UCAL_MINUTE;
}
if ( calendarField != UCAL_FIELD_COUNT ) {
setIntervalPatternInternally(skeleton, calendarField, pattern,status);
}
}
ures_close(intervalPatterns);
}
delete calData;
ures_close(itvDtPtnResource);
ures_close(gregorianBundle);
ures_close(calBundle);
ures_close(rb);
status = U_ZERO_ERROR;
locNameLen = uloc_getParent(parentLocale, parentLocale,50,&status);
} while ( locNameLen > 0 );
}
@ -488,9 +488,13 @@ DateIntervalInfo::getBestSkeleton(const UnicodeString& skeleton,
DateIntervalInfo::IntervalPatternIndex
DateIntervalInfo::calendarFieldToIntervalIndex(UCalendarDateFields field,
UErrorCode& status) {
IntervalPatternIndex index = kIPI_ERA;
if ( U_FAILURE(status) ) {
return kIPI_MAX_INDEX;
}
IntervalPatternIndex index = kIPI_MAX_INDEX;
switch ( field ) {
case UCAL_ERA:
index = kIPI_ERA;
break;
case UCAL_YEAR:
index = kIPI_YEAR;
@ -568,7 +572,9 @@ U_CALLCONV hashTableValueComparator(UHashTok val1, UHashTok val2) {
Hashtable*
DateIntervalInfo::initHash(UErrorCode& status) {
if ( U_FAILURE(status) ) {
return NULL;
}
Hashtable* hTable;
if ( (hTable = new Hashtable(TRUE, status)) == NULL ) {
status = U_MEMORY_ALLOCATION_ERROR;
@ -583,6 +589,9 @@ void
DateIntervalInfo::copyHash(const Hashtable* source,
Hashtable* target,
UErrorCode& status) {
if ( U_FAILURE(status) ) {
return;
}
int32_t pos = -1;
const UHashElement* element = NULL;
if ( source ) {

View File

@ -586,6 +586,7 @@ SimpleDateFormat::format(const Formattable& obj,
* the larger the level, the smaller the field unit.
* For example, UCAL_ERA level is 0, UCAL_YEAR level is 10,
* UCAL_MONTH level is 20.
* NOTE: if new fields adds in, the table needs to update.
*/
const int32_t
SimpleDateFormat::fgCalendarFieldToLevel[] =
@ -601,6 +602,10 @@ SimpleDateFormat::fgCalendarFieldToLevel[] =
};
/* Map calendar field LETTER into calendar field level.
* the larger the level, the smaller the field unit.
* NOTE: if new fields adds in, the table needs to update.
*/
const int32_t
SimpleDateFormat::fgPatternCharToLevel[] = {
// A B C D E F G H I J K L M N O
@ -2485,6 +2490,7 @@ SimpleDateFormat::isFieldUnitIgnored(const UnicodeString& pattern,
ch = pattern[i];
if (ch != prevCh && count > 0) {
level = fgPatternCharToLevel[prevCh - PATTERN_CHAR_BASE];
// the larger the level, the smaller the field unit.
if ( fieldLevel <= level ) {
return FALSE;
}

View File

@ -429,12 +429,16 @@ public:
*
* @param skeleton the skeleton on which date format based.
* @param locale the given locale.
* @param status Output param to be set to success/failure code.
* If it is failure, the returned date formatter will
* be NULL.
* @return a simple date formatter which the caller owns.
* @internal ICU 4.0
*/
static DateFormat* U_EXPORT2 createPatternInstance(
const UnicodeString& skeleton,
const Locale& locale);
const Locale& locale,
UErrorCode& status);
/**
* Creates a time formatter with the given formatting style for the given

View File

@ -7,8 +7,8 @@
*******************************************************************************
*/
#ifndef DTITVFMT_H__
#define DTITVFMT_H__
#ifndef __DTITVFMT_H__
#define __DTITVFMT_H__
#include "unicode/utypes.h"
@ -32,6 +32,8 @@ 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.
*
* <P>
* Date interval means from one date to another date,
@ -70,10 +72,14 @@ U_NAMESPACE_BEGIN
* <li>
* only keeps the field pattern letter and ignores all other parts
* in a pattern, such as space, punctuations, and string literals.
* </li>
* <li>
* hides the order of fields.
* </li>
* <li>
* might hide a field's pattern letter length.
* </li>
* </ol>
*
* For those non-digit calendar fields, the pattern letter length is
* important, such as MMM, MMMM, and MMMMM; EEE and EEEE,
@ -96,6 +102,11 @@ U_NAMESPACE_BEGIN
*
* For example: the largest different calendar fields between "Jan 10, 2007"
* and "Feb 20, 2008" is year.
*
* <P>
* For other calendar fields, the compact interval formatting is not
* supported. And the interval format will be fall back to fall-back
* patterns, which is mostly "{date0} - {date1}".
*
* <P>
* There is a set of pre-defined static skeleton strings.
@ -126,21 +137,23 @@ U_NAMESPACE_BEGIN
*
* <P>
* For the combination of date and time,
* The rule to genearte interval patterns are:
* <ul>
* The rule to generate interval patterns are:
* <ol>
* <li>
* 1) when the year, month, or day differs, falls back to fall-back
* when the year, month, or day differs, falls back to fall-back
* interval pattern, which mostly is the concatenate the two original
* expressions with a separator between,
* For example, interval pattern from "Jan 10, 2007 10:10 am"
* to "Jan 11, 2007 10:10am" is
* "Jan 10, 2007 10:10 am - Jan 11, 2007 10:10am"
* </li>
* <li>
* 2) otherwise, present the date followed by the range expression
* otherwise, present the date followed by the range expression
* for the time.
* For example, interval pattern from "Jan 10, 2007 10:10 am"
* to "Jan 10, 2007 11:10am" is "Jan 10, 2007 10:10 am - 11:10am"
* </ul>
* </li>
* </ol>
*
*
* <P>
@ -157,22 +170,25 @@ U_NAMESPACE_BEGIN
* DateIntervalFormat needs the following information for correct
* formatting: time zone, calendar type, pattern, date format symbols,
* and date interval patterns.
* It can be instantiated in several ways:
* <ul>
* It can be instantiated in 2 ways:
* <ol>
* <li>
* 1. create an instance using default or given locale plus given skeleton.
* create an instance using default or given locale plus given skeleton.
* Users are encouraged to created date interval formatter this way and
* to use the pre-defined skeleton macros, such as
* UDAT_YEAR_NUM_MONTH, which consists the calendar fields and
* the format style.
* 2. create an instance using default or given locale plus given skeleton
* </li>
* <li>
* create an instance using default or given locale plus given skeleton
* plus a given DateIntervalInfo.
* This factory method is for powerful users who want to provide their own
* interval patterns.
* Locale provides the timezone, calendar, and format symbols information.
* Local plus skeleton provides full pattern information.
* DateIntervalInfo provides the date interval patterns.
* <li>
* </li>
* </ol>
*
* <P>
* For the calendar field pattern letter, such as G, y, M, d, a, h, H, m, s etc.
@ -212,7 +228,7 @@ public:
*
* @param skeleton the skeleton on which interval format based.
* @param status output param set to success/failure code on exit
* @return a date time interval formatter whick the caller owns.
* @return a date time interval formatter which the caller owns.
* @draft ICU 4.0
*/
static DateIntervalFormat* U_EXPORT2 createInstance(
@ -221,7 +237,13 @@ public:
/**
* Construct a DateIntervalFormat from skeleton and a given locale.
* <P>
* In this factory method,
* the date interval pattern information is load from resource files.
* Users are encouraged to created date interval formatter this way and
* to use the pre-defined skeleton macros.
*
* <P>
* There are pre-defined skeletons (defined in udate.h) having predefined
* interval patterns in resource files.
* Users are encouraged to use those macros.
@ -238,7 +260,7 @@ public:
* @param skeleton the skeleton on which interval format based.
* @param locale the given locale
* @param status output param set to success/failure code on exit
* @return a date time interval formatter whick the caller owns.
* @return a date time interval formatter which the caller owns.
* @draft ICU 4.0
*/
@ -253,35 +275,38 @@ public:
*
* This is a convenient override of
* createInstance(const UnicodeString& skeleton, const Locale& locale,
* DateIntervalInfo* dtitvinf, UErrorCode&)
* const DateIntervalInfo& dtitvinf, UErrorCode&)
* with the locale value as default locale.
*
* Note: the DateIntervalFormat takes ownership of
* DateIntervalInfo objects.
* Caller should not delete them.
*
* @param skeleton the skeleton on which interval format based.
* @param dtitvinf the DateIntervalInfo object to be adopted.
* @param dtitvinf the DateIntervalInfo object.
* @param status output param set to success/failure code on exit
* @return a date time interval formatter whick the caller owns.
* @return a date time interval formatter which the caller owns.
* @draft ICU 4.0
*/
static DateIntervalFormat* U_EXPORT2 createInstance(
const UnicodeString& skeleton,
DateIntervalInfo* dtitvinf,
const DateIntervalInfo& dtitvinf,
UErrorCode& status);
/**
* Construct a DateIntervalFormat from skeleton
* a DateIntervalInfo, and the given locale.
*
* <P>
* In this factory method, user provides its own date interval pattern
* information, instead of using those pre-defined data in resource file.
* This factory method is for powerful users who want to provide their own
* interval patterns.
* <P>
* There are pre-defined skeletons (defined in udate.h) having predefined
* interval patterns in resource files.
* Users are encouraged to use those macros.
* For example:
* DateIntervalFormat::createInstance(UDAT_MONTH_DAY, status)
*
* the DateIntervalInfo provides the interval patterns.
* The DateIntervalInfo provides the interval patterns.
* and the DateIntervalInfo ownership remains to the caller.
*
* User are encouraged to set default interval pattern in DateIntervalInfo
* as well, if they want to set other interval patterns ( instead of
@ -292,21 +317,17 @@ public:
* If user does not provide default interval pattern, it fallback to
* "{date0} - {date1}"
*
* Note: the DateIntervalFormat takes ownership of
* DateIntervalInfo objects.
* Caller should not delete them.
*
* @param skeleton the skeleton on which interval format based.
* @param locale the given locale
* @param dtitvinf the DateIntervalInfo object to be adopted.
* @param dtitvinf the DateIntervalInfo object.
* @param status output param set to success/failure code on exit
* @return a date time interval formatter whick the caller owns.
* @return a date time interval formatter which the caller owns.
* @draft ICU 4.0
*/
static DateIntervalFormat* U_EXPORT2 createInstance(
const UnicodeString& skeleton,
const Locale& locale,
DateIntervalInfo* dtitvinf,
const DateIntervalInfo& dtitvinf,
UErrorCode& status);
/**
@ -389,9 +410,9 @@ public:
* since calendar is not const in SimpleDateFormat::format(Calendar&),
*
* @param fromCalendar calendar set to the from date in date interval
* to be formatted into date interval stirng
* to be formatted into date interval string
* @param toCalendar calendar set to the to date in date interval
* to be formatted into date interval stirng
* to be formatted into date interval string
* @param appendTo Output parameter to receive result.
* Result is appended to existing contents.
* @param fieldPosition On input: an alignment field, if desired.
@ -409,12 +430,12 @@ public:
UErrorCode& status) const ;
/**
* Parse a string to produce an object. This methods handles parsing of
* Date interval parsing is not supported.
* <P>
* This method should handle parsing of
* date time interval strings into Formattable objects with
* DateInterval type, which is a pair of UDate.
* <P>
* In ICU 4.0, date interval format is not supported.
* <P>
* Before calling, set parse_pos.index to the offset you want to start
* parsing at in the source. After calling, parse_pos.index is the end of
* the text you parsed. If error occurs, index is unchanged.
@ -427,15 +448,12 @@ public:
* @param source The string to be parsed into an object.
* @param result Formattable to be set to the parse result.
* If parse fails, return contents are undefined.
* @param parse_pos The position to start parsing at. Upon return
* this param is set to the position after the
* last character successfully parsed. If the
* source is not parsed successfully, this param
* will remain unchanged.
* @param parse_pos The position to start parsing at. Since no parsing
* is supported, upon return this param is unchanged.
* @return A newly created Formattable* object, or NULL
* on failure. The caller owns this and should
* delete it when done.
* @draft ICU 4.0
* @internal ICU 4.0
*/
virtual void parseObject(const UnicodeString& source,
Formattable& result,
@ -444,7 +462,7 @@ public:
/**
* Gets the date time interval patterns.
* @return a copy of the date time interval patterns associated with
* @return the date time interval patterns associated with
* this date interval formatter.
* @draft ICU 4.0
*/
@ -460,54 +478,14 @@ public:
void setDateIntervalInfo(const DateIntervalInfo& newIntervalPatterns,
UErrorCode& status);
/**
* Set the date time interval patterns.
* The caller no longer owns the DateIntervalInfo object and
* should not delete it after making this call.
* @param newIntervalPatterns the given interval patterns to copy.
* @param status output param set to success/failure code on exit
* @draft ICU 4.0
*/
void adoptDateIntervalInfo(DateIntervalInfo* newIntervalPatterns,
UErrorCode& status);
/**
* Gets the date formatter
* @return a copy of the date formatter associated with
* this date interval formatter.
* @return the date formatter associated with this date interval formatter.
* @draft ICU 4.0
*/
const DateFormat* getDateFormat(void) const;
/**
* Set the date formatter.
* @param newDateFormat the given date formatter to copy.
* caller needs to make sure that
* it is a SimpleDateFormatter.
* @param status Output param set to success/failure code.
* caller needs to make sure it is SUCCESS
* at the function entrance.
* @draft ICU 4.0
*/
void setDateFormat(const DateFormat& newDateFormat, UErrorCode& status);
/**
* Set the date formatter.
* The caller no longer owns the DateFormat object and
* should not delete it after making this call.
* @param newDateFormat the given date formatter to copy.
* caller needs to make sure that
* it is a SimpleDateFormatter.
* @param status Output param set to success/failure code.
* caller needs to make sure it is SUCCESS
* at the function entrance.
* @draft ICU 4.0
*/
void adoptDateFormat(DateFormat* newDateFormat, UErrorCode& status);
/**
* Return the class ID for this class. This is useful only for comparing to
* a return value from getDynamicClassID(). For example:
@ -561,9 +539,8 @@ private:
* Also, the first date appears in an interval pattern could be
* the earlier date or the later date.
* And such information is saved in the interval pattern as well.
* FIXME: do I need to define an inner class
*/
typedef struct PatternInfo {
struct PatternInfo {
UnicodeString firstPart;
UnicodeString secondPart;
/**
@ -580,31 +557,15 @@ private:
* the interval format is "10 Feb - 10 Jan, 2007"
*/
UBool laterDateFirst;
} PatternInfo;
};
/**
* default constructor
* @draft ICU 4.0
* @internal ICU 4.0
*/
DateIntervalFormat();
/**
* Construct a DateIntervalFormat from DateFormat and a DateIntervalInfo.
*
* This is the convenient override of
* DateIntervalFormat(DateFormat, DateIntervalInfo, UnicodeString)
* with the UnicodeString value as null.
*
* @param dtfmt the SimpleDateFormat object to be adopted.
* @param dtitvinf the DateIntervalInfo object to be adopted.
* @param status output param set to success/failure code on exit
* @draft ICU 4.0
*/
DateIntervalFormat(DateFormat* dtfmt, DateIntervalInfo* dtItvInfo,
UErrorCode& status);
/**
* Construct a DateIntervalFormat from DateFormat,
* a DateIntervalInfo, and skeleton.
@ -622,31 +583,12 @@ private:
* @param dtitvinf the DateIntervalInfo object to be adopted.
* @param skeleton the skeleton of the date formatter
* @param status output param set to success/failure code on exit
* @draft ICU 4.0
* @internal ICU 4.0
*/
DateIntervalFormat(DateFormat* dtfmt, DateIntervalInfo* dtItvInfo,
const UnicodeString* skeleton, UErrorCode& status);
/**
* Construct a DateIntervalFormat from DateFormat
* and a DateIntervalInfo.
*
* It is a wrapper of the constructor.
*
* @param dtfmt the DateFormat object to be adopted.
* @param dtitvinf the DateIntervalInfo object to be adopted.
* @param status Output param set to success/failure code.
* @return a date time interval formatter whick the caller owns.
* @draft ICU 4.0
*/
static DateIntervalFormat* U_EXPORT2 create(DateFormat* dtfmt,
DateIntervalInfo* dtitvinf,
UErrorCode& status);
/**
* Construct a DateIntervalFormat from DateFormat
* and a DateIntervalInfo.
@ -657,8 +599,8 @@ private:
* @param dtitvinf the DateIntervalInfo object to be adopted.
* @param skeleton the skeleton of this formatter.
* @param status Output param set to success/failure code.
* @return a date time interval formatter whick the caller owns.
* @draft ICU 4.0
* @return a date time interval formatter which the caller owns.
* @internal ICU 4.0
*/
static DateIntervalFormat* U_EXPORT2 create(DateFormat* dtfmt,
DateIntervalInfo* dtitvinf,
@ -678,16 +620,16 @@ private:
* full pattern of the date formatter.
*
* @param fromCalendar calendar set to the from date in date interval
* to be formatted into date interval stirng
* to be formatted into date interval string
* @param toCalendar calendar set to the to date in date interval
* to be formatted into date interval stirng
* to be formatted into date interval string
* @param appendTo Output parameter to receive result.
* Result is appended to existing contents.
* @param pos On input: an alignment field, if desired.
* On output: the offsets of the alignment field.
* @param status output param set to success/failure code on exit
* @return Reference to 'appendTo' parameter.
* @draft ICU 4.0
* @internal ICU 4.0
*/
UnicodeString& fallbackFormat(Calendar& fromCalendar,
Calendar& toCalendar,
@ -709,7 +651,7 @@ private:
* For example, it has interval patterns on skeleton "dMy" and "hm",
* but it does not have interval patterns on skeleton "dMyhm".
*
* The rule to genearte interval patterns for both date and time skeleton are
* The rule to generate interval patterns for both date and time skeleton are
* 1) when the year, month, or day differs, concatenate the two original
* expressions with a separator between,
* For example, interval pattern from "Jan 10, 2007 10:10 am"
@ -722,7 +664,7 @@ private:
* to "Jan 10, 2007 11:10am" is
* "Jan 10, 2007 10:10 am - 11:10am"
*
* 2. even a pattern does not request a certion calendar field,
* 2. even a pattern does not request a certain calendar field,
* the interval pattern needs to include such field if such fields are
* different between 2 dates.
* For example, a pattern/skeleton is "hm", but the interval pattern
@ -730,7 +672,7 @@ private:
*
*
* @param status output param set to success/failure code on exit
* @draft ICU 4.0
* @internal ICU 4.0
*/
void initializePattern(UErrorCode& status);
@ -743,7 +685,7 @@ private:
* @param skeleton a skeleton
* @param dtpng date time pattern generator
* @param status output param set to success/failure code on exit
* @draft ICU 4.0
* @internal ICU 4.0
*/
void setFallbackPattern(UCalendarDateFields field,
const UnicodeString& skeleton,
@ -775,7 +717,7 @@ private:
* @param normalizedTime Output parameter for normalized time only
* skeleton.
*
* @draft ICU 4.0
* @internal ICU 4.0
*/
static void U_EXPORT2 getDateTimeSkeleton(const UnicodeString& skeleton,
UnicodeString& date,
@ -807,7 +749,7 @@ private:
* @return whether the resource is found for the skeleton.
* TRUE if interval pattern found for the skeleton,
* FALSE otherwise.
* @draft ICU 4.0
* @internal ICU 4.0
*/
UBool setSeparateDateTimePtn(const UnicodeString& dateSkeleton,
const UnicodeString& timeSkeleton);
@ -837,7 +779,7 @@ private:
* through extending skeleton or not.
* TRUE if interval pattern is found by
* extending skeleton, FALSE otherwise.
* @draft ICU 4.0
* @internal ICU 4.0
*/
UBool setIntervalPattern(UCalendarDateFields field,
const UnicodeString* skeleton,
@ -873,7 +815,7 @@ private:
* 1 means only field width differs
* 2 means v/z exchange
* @param adjustedIntervalPattern adjusted interval pattern
* @draft ICU 4.0
* @internal ICU 4.0
*/
static void U_EXPORT2 adjustFieldWidth(
const UnicodeString& inputSkeleton,
@ -893,7 +835,7 @@ private:
* @param datePattern date pattern
* @param field time calendar field: AM_PM, HOUR, MINUTE
* @param status output param set to success/failure code on exit
* @draft ICU 4.0
* @internal ICU 4.0
*/
void concatSingleDate2TimeInterval(const UChar* format,
int32_t formatLen,
@ -906,7 +848,7 @@ private:
* @param field calendar field need to check
* @param skeleton given skeleton on which to check the calendar field
* @return true if field present in a skeleton.
* @draft ICU 4.0
* @internal ICU 4.0
*/
static UBool U_EXPORT2 fieldExistsInSkeleton(UCalendarDateFields field,
const UnicodeString& skeleton);
@ -916,7 +858,7 @@ private:
* Split interval patterns into 2 part.
* @param intervalPattern interval pattern
* @return the index in interval pattern which split the pattern into 2 part
* @draft ICU 4.0
* @internal ICU 4.0
*/
static int32_t U_EXPORT2 splitPatternInto2Part(const UnicodeString& intervalPattern);
@ -998,40 +940,6 @@ DateIntervalFormat::operator!=(const Format& other) const {
return !operator==(other);
}
inline const DateIntervalInfo*
DateIntervalFormat::getDateIntervalInfo() const {
return fInfo;
}
inline void
DateIntervalFormat::setDateIntervalInfo(const DateIntervalInfo& newItvPattern,
UErrorCode& status) {
delete fInfo;
fInfo = new DateIntervalInfo(newItvPattern);
if ( fDateFormat ) {
initializePattern(status);
}
}
inline void
DateIntervalFormat::adoptDateIntervalInfo(DateIntervalInfo* newItvPattern,
UErrorCode& status) {
delete fInfo;
fInfo = newItvPattern;
if ( fDateFormat ) {
initializePattern(status);
}
}
inline const DateFormat*
DateIntervalFormat::getDateFormat() const {
return fDateFormat;
}
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */

View File

@ -117,7 +117,7 @@ U_CDECL_END
* the first date in the interval pattern for this locale is earlier date.
* If the fallback format is "{1} - {0}", it means the first date is the
* later date.
* For a paticular interval pattern, the default order can be overriden
* For a particular interval pattern, the default order can be overriden
* by prefixing "latestFirst:" or "earliestFirst:" to the interval pattern.
* For example, if the fallback format is "{0}-{1}",
* but for skeleton "yMMMd", the interval pattern when day is different is
@ -144,7 +144,7 @@ U_CDECL_END
* DAY_OF_WEEK, AM_PM, HOUR, HOUR_OF_DAY, and MINUTE.
* Interval patterns when other calendar fields are different is not supported.
* <P>
* DateIntervalInfo objects are clonable.
* DateIntervalInfo objects are cloneable.
* When clients obtain a DateIntervalInfo object,
* they can feel free to modify it as necessary.
* <P>
@ -198,7 +198,7 @@ public:
* @return a copy of the object
* @draft ICU4.0
*/
DateIntervalInfo* clone(void) const;
virtual DateIntervalInfo* clone(void) const;
/**
* Destructor.
@ -215,7 +215,7 @@ public:
* @return true if other is semantically equal to this.
* @stable ICU 4.0
*/
UBool operator==(const DateIntervalInfo& other) const;
virtual UBool operator==(const DateIntervalInfo& other) const;
/**
* Return true if another object is semantically unequal to this one.
@ -237,10 +237,10 @@ public:
* <pre>
* UErrorCode status = U_ZERO_ERROR;
* DateIntervalInfo dIntervalInfo = new DateIntervalInfo();
* dIntervalInfo->setFallbackIntervalPattern("{0} ~ {1}");
* dIntervalInfo->setIntervalPattern("yMd", UCAL_YEAR, "'from' yyyy-M-d 'to' yyyy-M-d", status);
* dIntervalInfo->setIntervalPattern("yMMMd", UCAL_MONTH, "'from' yyyy MMM d 'to' MMM d", status);
* dIntervalInfo->setIntervalPattern("yMMMd", UCAL_DAY, "yyyy MMM d-d", status, status);
* dIntervalInfo->setFallbackIntervalPattern("{0} ~ {1}");
* </pre>
*
* Restriction:
@ -266,7 +266,8 @@ public:
UErrorCode& status);
/**
* Get the interval pattern given the largest different calendar field.
* Get the interval pattern given skeleton and
* the largest different calendar field.
* @param skeleton the skeleton
* @param field the largest different calendar field
* @param status output param set to success/failure code on exit

View File

@ -174,28 +174,19 @@ typedef enum UDateFormatStyle {
/**
* Below are a set of pre-defined skeletons.
* They have pre-defined interval patterns in resource files.
* Users are encouraged to use them in date interval format factory methods.
*
* <P>
* We choose to use predefined skeleton string instead of skeleton enum because
* we need to keep consistency between DateFormat and DateIntervalFormat
* factory methods.
* It is not good to introduce another set of enum for skeleton while having
* UDateFormatStyle for full pattern.
* And it is not good to mix the set of enum for skeleton into UDateFormatStyle.
* So, a new set of pre-defined skeleton is introduced below.
* <P>
*
* A skeleton
* <ul>
* <ol>
* <li>
* 1. only keeps the field pattern letter and ignores all other parts
* only keeps the field pattern letter and ignores all other parts
* in a pattern, such as space, punctuations, and string literals.
* </li>
* <li>
* 2. hides the order of fields.
* hides the order of fields.
* </li>
* <li>
* 3. might hide a field's pattern letter length.
* might hide a field's pattern letter length.
*
* For those non-digit calendar fields, the pattern letter length is
* important, such as MMM, MMMM, and MMMMM; EEE and EEEE,
@ -205,28 +196,8 @@ typedef enum UDateFormatStyle {
* the field pattern length is ignored and the best match, which is defined
* in date time patterns, will be returned without honor the field pattern
* letter length in skeleton.
* </ul>
*
* <P>
* For example, given skeleton YEAR_MONTH_DAY_SHORT_FORMAT, which is "yMd",
* for English, the full pattern is "M/d/yy", which is the short format
* of date pattern having DAY, MONTH, and YEAR.
*
* <P>
* The skeletons defined below consists of the desired calendar field set
* (for example, DAY, MONTH, YEAR) and the format length (long, medium, short)
* used in date time patterns.
*
* For example, skeleton YEAR_MONTH_MEDIUM_FORMAT consists month and year,
* and it's corresponding full pattern is medium format date pattern.
* So, the skeleton is "yMMM", for English, the full pattern is "MMM yyyy",
* which is the format by removing DATE from medium date format.
*
* For example, skeleton YEAR_MONTH_DOW_DAY_MEDIUM_FORMAT consists day, month,
* year, and day-of-week, and it's corresponding full pattern is the medium
* format date pattern. So, the skeleton is "yMMMEEEd", for English,
* the full pattern is "EEE, MMM d, yyyy", which is the medium date format
* plus day-of-week.
* </li>
* </ol>
*
* @draft ICU 4.0
*/
@ -239,6 +210,12 @@ typedef enum UDateFormatStyle {
#define UDAT_ABBR_STANDALONE_MONTH "LLL"
#define UDAT_YEAR_QUARTER "yQQQ"
#define UDAT_YEAR_ABBR_QUARTER "yQ"
/**
* Below are a set of pre-defined skeletons that
* have pre-defined interval patterns in resource files.
* Users are encouraged to use them in date interval format factory methods.
*
*/
#define UDAT_HOUR_MINUTE "hm"
#define UDAT_YEAR "y"
#define UDAT_DAY "d"

File diff suppressed because it is too large Load Diff

View File

@ -27,12 +27,36 @@ public:
void testAPI();
/**
* test formatting
* Test formatting
*/
void testFormat();
/**
* Test formatting using user defined DateIntervalInfo
*/
void testFormatUserDII();
/**
* Stress test -- stress test formatting on 40 locales
*/
void testStress();
private:
void expect(const char** data, int32_t data_length, const Locale& loc,
/**
* Test formatting against expected result
*/
void expect(const char** data, int32_t data_length);
/**
* Test formatting against expected result using user defined
* DateIntervalInfo
*/
void expectUserDII(const char** data, int32_t data_length);
/**
* Stress test formatting
*/
void stress(const char** data, int32_t data_length, const Locale& loc,
const char* locName);
};