- fDateFormat->applyPattern(*fTimePattern);
- }
- FieldPosition otherPos;
- otherPos.setField(pos.getField());
- UnicodeString earlierDate;
- fDateFormat->format(fromCalendar, earlierDate, pos);
- UnicodeString laterDate;
- fDateFormat->format(toCalendar, laterDate, otherPos);
- UnicodeString fallbackPattern;
- fInfo->getFallbackIntervalPattern(fallbackPattern);
- adjustPosition(fallbackPattern, earlierDate, pos, laterDate, otherPos, pos);
- UnicodeString fallbackRange;
- SimpleFormatter(fallbackPattern, 2, 2, status).
- format(earlierDate, laterDate, fallbackRange, status);
- if ( U_SUCCESS(status) && formatDatePlusTimeRange ) {
- // fallbackRange has just the time range, need to format the date part and combine that
- UnicodeString dateTimeFormatNoQuote(*fDateTimeFormat);
- dateTimeFormatNoQuote.findAndReplace(UnicodeString(0x0027), UnicodeString());
- fDateFormat->applyPattern(*fDatePattern);
- UnicodeString datePortion;
- otherPos.setBeginIndex(0);
- otherPos.setEndIndex(0);
- fDateFormat->format(fromCalendar, datePortion, otherPos);
- adjustPosition(dateTimeFormatNoQuote, fallbackRange, pos, datePortion, otherPos, pos);
- const UnicodeString *values[2] = {
- &fallbackRange, // {0} is time range
- &datePortion, // {1} is single date portion
- };
- SimpleFormatter(dateTimeFormatNoQuote, 2, 2, status).
- formatAndReplace(values, 2, fallbackRange, NULL, 0, status);
- }
- if ( U_SUCCESS(status) ) {
- appendTo.append(fallbackRange);
- }
- if (formatDatePlusTimeRange) {
+
+ // {0} is time range
+ // {1} is single date portion
+ // TODO(ICU-20406): Use SimpleFormatter Iterator interface when available.
+ if (offsets[0] < offsets[1]) {
+ appendTo.append(patternBody.tempSubStringBetween(0, offsets[0]));
+ fDateFormat->applyPattern(*fTimePattern);
+ fDateFormat->setContext(fCapitalizationContext, status);
+ fallbackFormatRange(fromCalendar, toCalendar, appendTo, firstIndex, fphandler, status);
+ appendTo.append(patternBody.tempSubStringBetween(offsets[0], offsets[1]));
+ fDateFormat->applyPattern(*fDatePattern);
+ fDateFormat->_format(fromCalendar, appendTo, fphandler, status);
+ appendTo.append(patternBody.tempSubStringBetween(offsets[1]));
+ } else {
+ appendTo.append(patternBody.tempSubStringBetween(0, offsets[1]));
+ fDateFormat->applyPattern(*fDatePattern);
+ fDateFormat->setContext(fCapitalizationContext, status);
+ fDateFormat->_format(fromCalendar, appendTo, fphandler, status);
+ appendTo.append(patternBody.tempSubStringBetween(offsets[1], offsets[0]));
+ fDateFormat->applyPattern(*fTimePattern);
+ fDateFormat->setContext(UDISPCTX_CAPITALIZATION_NONE, status);
+ fallbackFormatRange(fromCalendar, toCalendar, appendTo, firstIndex, fphandler, status);
+ appendTo.append(patternBody.tempSubStringBetween(offsets[0]));
+ }
+