+ FieldPositionOnlyHandler handler(pos);
+ handler.setAcceptFirstOnly(TRUE);
+ int8_t ignore;
+
+ Mutex lock(gFormatterMutex());
+ return formatImpl(fromCalendar, toCalendar, appendTo, ignore, handler, status);
+}
+
+
+FormattedDateInterval DateIntervalFormat::formatToValue(
+ Calendar& fromCalendar,
+ Calendar& toCalendar,
+ UErrorCode& status) const {
+ LocalPointer<FormattedDateIntervalData> result(new FormattedDateIntervalData(status), status);
+ if (U_FAILURE(status)) {
+ return FormattedDateInterval(status);
+ }
+ UnicodeString string;
+ int8_t firstIndex;
+ auto handler = result->getHandler(status);
+ handler.setCategory(UFIELD_CATEGORY_DATE);
+ {
+ Mutex lock(gFormatterMutex());
+ formatImpl(fromCalendar, toCalendar, string, firstIndex, handler, status);
+ }
+ handler.getError(status);
+ result->appendString(string, status);
+ if (U_FAILURE(status)) {
+ return FormattedDateInterval(status);
+ }
+
+ // Compute the span fields and sort them into place:
+ if (firstIndex != -1) {
+ result->addOverlapSpans(UFIELD_CATEGORY_DATE_INTERVAL_SPAN, firstIndex, status);
+ result->sort();
+ }
+
+ return FormattedDateInterval(result.orphan());
+}
+
+
+UnicodeString& DateIntervalFormat::formatIntervalImpl(
+ const DateInterval& dtInterval,
+ UnicodeString& appendTo,
+ int8_t& firstIndex,
+ FieldPositionHandler& fphandler,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return appendTo;
+ }
+ if (fFromCalendar == nullptr || fToCalendar == nullptr) {
+ status = U_INVALID_STATE_ERROR;
+ return appendTo;
+ }
+ fFromCalendar->setTime(dtInterval.getFromDate(), status);
+ fToCalendar->setTime(dtInterval.getToDate(), status);
+ return formatImpl(*fFromCalendar, *fToCalendar, appendTo, firstIndex, fphandler, status);
+}
+
+
+UnicodeString&
+DateIntervalFormat::formatImpl(Calendar& fromCalendar,
+ Calendar& toCalendar,
+ UnicodeString& appendTo,
+ int8_t& firstIndex,
+ FieldPositionHandler& fphandler,
+ UErrorCode& status) const {