Search in sources :

Example 6 with PatternInfo

use of android.icu.text.DateIntervalInfo.PatternInfo in project j2objc by google.

the class DateIntervalFormatTest method TestSetIntervalPatternNoSideEffect.

@Test
public void TestSetIntervalPatternNoSideEffect() {
    PatternInfo patternInfo = new DateIntervalInfo(ULocale.ENGLISH).getIntervalPattern("yMd", Calendar.DATE);
    String expectedPattern = patternInfo.getFirstPart() + patternInfo.getSecondPart();
    new DateIntervalInfo(ULocale.ENGLISH).setIntervalPattern("yMd", Calendar.DATE, "M/d/y \u2013 d");
    patternInfo = new DateIntervalInfo(ULocale.ENGLISH).getIntervalPattern("yMd", Calendar.DATE);
    String actualPattern = patternInfo.getFirstPart() + patternInfo.getSecondPart();
    assertEquals("setIntervalPattern should not have side effects", expectedPattern, actualPattern);
}
Also used : DateIntervalInfo(android.icu.text.DateIntervalInfo) PatternInfo(android.icu.text.DateIntervalInfo.PatternInfo) Test(org.junit.Test)

Example 7 with PatternInfo

use of android.icu.text.DateIntervalInfo.PatternInfo in project j2objc by google.

the class DateIntervalFormat method getPatterns.

/**
 * @deprecated This API is ICU internal only.
 * @hide original deprecated declaration
 * @hide draft / provisional / internal are hidden on Android
 */
@Deprecated
public String getPatterns(Calendar fromCalendar, Calendar toCalendar, Output<String> part2) {
    // First, find the largest different calendar field.
    int field;
    if (fromCalendar.get(Calendar.ERA) != toCalendar.get(Calendar.ERA)) {
        field = Calendar.ERA;
    } else if (fromCalendar.get(Calendar.YEAR) != toCalendar.get(Calendar.YEAR)) {
        field = Calendar.YEAR;
    } else if (fromCalendar.get(Calendar.MONTH) != toCalendar.get(Calendar.MONTH)) {
        field = Calendar.MONTH;
    } else if (fromCalendar.get(Calendar.DATE) != toCalendar.get(Calendar.DATE)) {
        field = Calendar.DATE;
    } else if (fromCalendar.get(Calendar.AM_PM) != toCalendar.get(Calendar.AM_PM)) {
        field = Calendar.AM_PM;
    } else if (fromCalendar.get(Calendar.HOUR) != toCalendar.get(Calendar.HOUR)) {
        field = Calendar.HOUR;
    } else if (fromCalendar.get(Calendar.MINUTE) != toCalendar.get(Calendar.MINUTE)) {
        field = Calendar.MINUTE;
    } else if (fromCalendar.get(Calendar.SECOND) != toCalendar.get(Calendar.SECOND)) {
        field = Calendar.SECOND;
    } else {
        return null;
    }
    PatternInfo intervalPattern = fIntervalPatterns.get(DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field]);
    part2.value = intervalPattern.getSecondPart();
    return intervalPattern.getFirstPart();
}
Also used : PatternInfo(android.icu.text.DateIntervalInfo.PatternInfo)

Example 8 with PatternInfo

use of android.icu.text.DateIntervalInfo.PatternInfo in project j2objc by google.

the class DateIntervalFormat method genFallbackPattern.

/*
     * Generate fall back interval pattern given a calendar field,
     * a skeleton, and a date time pattern generator
     * @param field      the largest different calendar field
     * @param skeleton   a skeleton
     * @param dtpng      date time pattern generator
     * @param intervalPatterns interval patterns
     */
private void genFallbackPattern(int field, String skeleton, Map<String, PatternInfo> intervalPatterns, DateTimePatternGenerator dtpng) {
    String pattern = dtpng.getBestPattern(skeleton);
    // for fall back interval patterns,
    // the first part of the pattern is empty,
    // the second part of the pattern is the full-pattern
    // should be used in fall-back.
    PatternInfo ptn = new PatternInfo(null, pattern, fInfo.getDefaultOrder());
    intervalPatterns.put(DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field], ptn);
}
Also used : PatternInfo(android.icu.text.DateIntervalInfo.PatternInfo)

Example 9 with PatternInfo

use of android.icu.text.DateIntervalInfo.PatternInfo in project j2objc by google.

the class DateIntervalFormat method initializePattern.

/*
     *  Below are for generating interval patterns locale to the formatter 
     */
/*
     * Initialize interval patterns locale to this formatter.
     */
private void initializePattern(ICUCache<String, Map<String, PatternInfo>> cache) {
    String fullPattern = fDateFormat.toPattern();
    ULocale locale = fDateFormat.getLocale();
    String key = null;
    Map<String, PatternInfo> patterns = null;
    if (cache != null) {
        if (fSkeleton != null) {
            key = locale.toString() + "+" + fullPattern + "+" + fSkeleton;
        } else {
            key = locale.toString() + "+" + fullPattern;
        }
        patterns = cache.get(key);
    }
    if (patterns == null) {
        Map<String, PatternInfo> intervalPatterns = initializeIntervalPattern(fullPattern, locale);
        patterns = Collections.unmodifiableMap(intervalPatterns);
        if (cache != null) {
            cache.put(key, patterns);
        }
    }
    fIntervalPatterns = patterns;
}
Also used : ULocale(android.icu.util.ULocale) PatternInfo(android.icu.text.DateIntervalInfo.PatternInfo)

Aggregations

PatternInfo (android.icu.text.DateIntervalInfo.PatternInfo)9 DateIntervalInfo (android.icu.text.DateIntervalInfo)2 ULocale (android.icu.util.ULocale)2 Test (org.junit.Test)2 DateFormat (android.icu.text.DateFormat)1 DateIntervalFormat (android.icu.text.DateIntervalFormat)1 SimpleDateFormat (android.icu.text.SimpleDateFormat)1 Calendar (android.icu.util.Calendar)1 DateInterval (android.icu.util.DateInterval)1 FieldPosition (java.text.FieldPosition)1 HashMap (java.util.HashMap)1