Java Code Examples for android.icu.util.Calendar#AM_PM
The following examples show how to use
android.icu.util.Calendar#AM_PM .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateIntervalFormat.java From j2objc with Apache License 2.0 | 5 votes |
/** * @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(); }
Example 2
Source File: DateIntervalFormat.java From j2objc with Apache License 2.0 | 4 votes |
private SkeletonAndItsBestMatch genIntervalPattern( int field, String skeleton, String bestSkeleton, int differenceInfo, Map<String, PatternInfo> intervalPatterns) { SkeletonAndItsBestMatch retValue = null; PatternInfo pattern = fInfo.getIntervalPattern( bestSkeleton, field); if ( pattern == null ) { // single date if ( SimpleDateFormat.isFieldUnitIgnored(bestSkeleton, field) ) { PatternInfo ptnInfo = new PatternInfo(fDateFormat.toPattern(), null, fInfo.getDefaultOrder()); intervalPatterns.put(DateIntervalInfo. CALENDAR_FIELD_TO_PATTERN_LETTER[field], ptnInfo); return null; } // 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 == Calendar.AM_PM ) { pattern = fInfo.getIntervalPattern(bestSkeleton, Calendar.HOUR); if ( pattern != null ) { // share intervalPatterns.put(DateIntervalInfo. CALENDAR_FIELD_TO_PATTERN_LETTER[field], pattern); } return null; } // 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". String fieldLetter = DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field]; bestSkeleton = fieldLetter + bestSkeleton; skeleton = fieldLetter + skeleton; // for example, looking for patterns when 'y' differ for // skeleton "MMMM". pattern = fInfo.getIntervalPattern(bestSkeleton, field); if ( pattern == null && differenceInfo == 0 ) { // if there is no skeleton "yMMMM" defined, // look for the best match skeleton, for example: "yMMM" BestMatchInfo tmpRetValue = fInfo.getBestSkeleton(skeleton); String tmpBestSkeleton = tmpRetValue.bestMatchSkeleton; differenceInfo = tmpRetValue.bestMatchDistanceInfo; if ( tmpBestSkeleton.length() != 0 && differenceInfo != -1 ) { pattern = fInfo.getIntervalPattern(tmpBestSkeleton, field); bestSkeleton = tmpBestSkeleton; } } if ( pattern != null ) { retValue = new SkeletonAndItsBestMatch(skeleton, bestSkeleton); } } if ( pattern != null ) { if ( differenceInfo != 0 ) { String part1 = adjustFieldWidth(skeleton, bestSkeleton, pattern.getFirstPart(), differenceInfo); String part2 = adjustFieldWidth(skeleton, bestSkeleton, pattern.getSecondPart(), differenceInfo); pattern = new PatternInfo(part1, part2, pattern.firstDateInPtnIsLaterDate()); } else { // pattern is immutable, no need to clone; // pattern = (PatternInfo)pattern.clone(); } intervalPatterns.put( DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field], pattern); } return retValue; }