Logo Search packages:      
Sourcecode: icu version File versions

UBool DateIntervalFormat::setIntervalPattern ( UCalendarDateFields  field,
const UnicodeString skeleton,
const UnicodeString bestSkeleton,
int8_t  differenceInfo,
UnicodeString extendedSkeleton = NULL,
UnicodeString extendedBestSkeleton = NULL 
) [private]

Generate interval pattern from existing resource

It not only save the interval patterns, but also return the extended skeleton and its best match skeleton.

Parameters:
field largest different calendar field
skeleton skeleton
bestSkeleton the best match skeleton which has interval pattern defined in resource
differenceInfo the difference between skeleton and best skeleton 0 means the best matched skeleton is the same as input skeleton 1 means the fields are the same, but field width are different 2 means the only difference between fields are v/z, -1 means there are other fields difference
extendedSkeleton extended skeleton
extendedBestSkeleton extended best match skeleton
Returns:
whether the interval pattern is found through extending skeleton or not. TRUE if interval pattern is found by extending skeleton, FALSE otherwise.

For internal use only.

ICU 4.0

Generate interval pattern from existing resource

It not only save the interval patterns, but also return the extended skeleton and its best match skeleton.

Parameters:
field largest different calendar field
skeleton skeleton
bestSkeleton the best match skeleton which has interval pattern defined in resource
differenceInfo the difference between skeleton and best skeleton 0 means the best matched skeleton is the same as input skeleton 1 means the fields are the same, but field width are different 2 means the only difference between fields are v/z, -1 means there are other fields difference
extendedSkeleton extended skeleton
extendedBestSkeleton extended best match skeleton
Returns:
whether the interval pattern is found through extending skeleton or not. TRUE if interval pattern is found by extending skeleton, FALSE otherwise. ICU 4.0

Definition at line 1075 of file dtitvfmt.cpp.

References adjustFieldWidth(), FALSE, fInfo, DateIntervalInfo::getBestSkeleton(), DateIntervalInfo::getIntervalPattern(), UnicodeString::insert(), UnicodeString::isEmpty(), SimpleDateFormat::isFieldUnitIgnored(), TRUE, U_ZERO_ERROR, UCAL_AM_PM, and UCAL_HOUR.

Referenced by concatSingleDate2TimeInterval(), setIntervalPattern(), and setSeparateDateTimePtn().

                                                                            {
    UErrorCode status = U_ZERO_ERROR;
    // following getIntervalPattern() should not generate error status
    UnicodeString pattern;
    fInfo->getIntervalPattern(*bestSkeleton, field, pattern, status);
    if ( pattern.isEmpty() ) {
        // single date
        if ( SimpleDateFormat::isFieldUnitIgnored(*bestSkeleton, field) ) {
            // do nothing, format will handle it
            return false;
        }

        // for 24 hour system, interval patterns in resource file
        // might not include pattern when am_pm differ, 
        // which should be the same as hour differ.
        // add it here for simplicity
        if ( field == UCAL_AM_PM ) {
            fInfo->getIntervalPattern(*bestSkeleton, UCAL_HOUR, pattern,status);
            if ( !pattern.isEmpty() ) {
                setIntervalPattern(field, pattern);
            }
            return false;
        } 
        // else, looking for pattern when 'y' differ for 'dMMMM' skeleton,
        // first, get best match pattern "MMMd",
        // since there is no pattern for 'y' differs for skeleton 'MMMd',
        // need to look for it from skeleton 'yMMMd',
        // if found, adjust field width in interval pattern from
        // "MMM" to "MMMM".
        UChar fieldLetter = fgCalendarFieldToPatternLetter[field];
        if ( extendedSkeleton ) {
            *extendedSkeleton = *skeleton;
            *extendedBestSkeleton = *bestSkeleton;
            extendedSkeleton->insert(0, fieldLetter);
            extendedBestSkeleton->insert(0, fieldLetter);
            // for example, looking for patterns when 'y' differ for
            // skeleton "MMMM". 
            fInfo->getIntervalPattern(*extendedBestSkeleton,field,pattern,status);
            if ( pattern.isEmpty() && differenceInfo == 0 ) {
                // if there is no skeleton "yMMMM" defined,
                // look for the best match skeleton, for example: "yMMM" 
                const UnicodeString* tmpBest = fInfo->getBestSkeleton(
                                        *extendedBestSkeleton, differenceInfo);
                if ( tmpBest != 0 && differenceInfo != -1 ) {
                    fInfo->getIntervalPattern(*tmpBest, field, pattern, status);
                    bestSkeleton = tmpBest;
                }
            }
        }
    } 
    if ( !pattern.isEmpty() ) {
        if ( differenceInfo != 0 ) {
            UnicodeString adjustIntervalPattern;
            adjustFieldWidth(*skeleton, *bestSkeleton, pattern, differenceInfo,
                              adjustIntervalPattern);
            setIntervalPattern(field, adjustIntervalPattern);
        } else {
            setIntervalPattern(field, pattern);
        }
        if ( extendedSkeleton && !extendedSkeleton->isEmpty() ) {
            return TRUE;
        }
    }
    return FALSE;
}


Generated by  Doxygen 1.6.0   Back to index