+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/********************************************************************************
-* Copyright (C) 2008-2013,2015, International Business Machines Corporation and
+* Copyright (C) 2008-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*
#include "unicode/dtptngen.h"
#include "unicode/udateintervalformat.h"
+#if U_SHOW_CPLUSPLUS_API
U_NAMESPACE_BEGIN
* Result is appended to existing contents.
* @param fieldPosition On input: an alignment field, if desired.
* On output: the offsets of the alignment field.
+ * There may be multiple instances of a given field type
+ * in an interval format; in this case the fieldPosition
+ * offsets refer to the first instance.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
* @stable ICU 4.0
* Result is appended to existing contents.
* @param fieldPosition On input: an alignment field, if desired.
* On output: the offsets of the alignment field.
+ * There may be multiple instances of a given field type
+ * in an interval format; in this case the fieldPosition
+ * offsets refer to the first instance.
* @param status Output param filled with success/failure status.
* @return Reference to 'appendTo' parameter.
* @stable ICU 4.0
* Result is appended to existing contents.
* @param fieldPosition On input: an alignment field, if desired.
* On output: the offsets of the alignment field.
+ * There may be multiple instances of a given field type
+ * in an interval format; in this case the fieldPosition
+ * offsets refer to the first instance.
* @param status Output param filled with success/failure status.
* Caller needs to make sure it is SUCCESS
* at the function entrance
/**
- * Gets the date formatter
+ * Gets the date formatter. The DateIntervalFormat instance continues to own
+ * the returned DateFormatter object, and will use and possibly modify it
+ * during format operations. In a multi-threaded environment, the returned
+ * DateFormat can only be used if it is certain that no other threads are
+ * concurrently using this DateIntervalFormatter, even for nominally const
+ * functions.
+ *
* @return the date formatter associated with this date interval formatter.
* @stable ICU 4.0
*/
/**
* default constructor
- * @internal ICU 4.0
+ * @internal (private)
*/
DateIntervalFormat();
const UnicodeString* skeleton,
UErrorCode& status);
- /**
- * Create a simple date/time formatter from skeleton, given locale,
- * and date time pattern generator.
- *
- * @param skeleton the skeleton on which date format based.
- * @param locale the given locale.
- * @param dtpng the date time pattern generator.
- * @param status Output param to be set to success/failure code.
- * If it is failure, the returned date formatter will
- * be NULL.
- * @return a simple date formatter which the caller owns.
- */
- static SimpleDateFormat* U_EXPORT2 createSDFPatternInstance(
- const UnicodeString& skeleton,
- const Locale& locale,
- DateTimePatternGenerator* dtpng,
- UErrorCode& status);
-
-
/**
* Below are for generating interval patterns local to the formatter
*/
/**
- * @param combiningPattern xxx
- * @param pat0 xxx
- * @param pos0 xxx
- * @param pat1 xxx
- * @param pos1 xxx
- * @param posResult xxx
+ * Provide an updated FieldPosition posResult based on two formats,
+ * the FieldPosition values for each of them, and the pattern used
+ * to combine them. The idea is for posResult to indicate the first
+ * instance (if any) of the specified field in the combined result,
+ * with correct offsets.
+ *
+ * @param combiningPattern Pattern used to combine pat0 and pat1
+ * @param pat0 Formatted date/time value to replace {0}
+ * @param pos0 FieldPosition within pat0
+ * @param pat1 Formatted date/time value to replace {1}
+ * @param pos1 FieldPosition within pat1
+ * @param posResult FieldPosition to be set to the correct
+ * position of the first field instance when
+ * pat0 and pat1 are combined using combiningPattern
*/
static void
adjustPosition(UnicodeString& combiningPattern, // has {0} and {1} in it
FieldPosition& posResult);
-
/**
* Format 2 Calendars using fall-back interval pattern
*
* The full pattern used in this fall-back format is the
* full pattern of the date formatter.
*
+ * gFormatterMutex must already be locked when calling this function.
+ *
* @param fromCalendar calendar set to the from date in date interval
* to be formatted into date interval string
* @param toCalendar calendar set to the to date in date interval
* On output: the offsets of the alignment field.
* @param status output param set to success/failure code on exit
* @return Reference to 'appendTo' parameter.
+ * @internal (private)
*/
UnicodeString& fallbackFormat(Calendar& fromCalendar,
Calendar& toCalendar,
const UnicodeString* secondPart,
UBool laterDateFirst);
+ /**
+ * Format 2 Calendars to produce a string.
+ * Implementation of the similar public format function.
+ * Must be called with gFormatterMutex already locked.
+ *
+ * Note: "fromCalendar" and "toCalendar" are not const,
+ * since calendar is not const in SimpleDateFormat::format(Calendar&),
+ *
+ * @param fromCalendar calendar set to the from date in date interval
+ * to be formatted into date interval string
+ * @param toCalendar calendar set to the to date in date interval
+ * to be formatted into date interval string
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param fieldPosition On input: an alignment field, if desired.
+ * On output: the offsets of the alignment field.
+ * There may be multiple instances of a given field type
+ * in an interval format; in this case the fieldPosition
+ * offsets refer to the first instance.
+ * @param status Output param filled with success/failure status.
+ * Caller needs to make sure it is SUCCESS
+ * at the function entrance
+ * @return Reference to 'appendTo' parameter.
+ * @internal (private)
+ */
+ UnicodeString& formatImpl(Calendar& fromCalendar,
+ Calendar& toCalendar,
+ UnicodeString& appendTo,
+ FieldPosition& fieldPosition,
+ UErrorCode& status) const ;
+
// from calendar field to pattern letter
- static const UChar fgCalendarFieldToPatternLetter[];
+ static const char16_t fgCalendarFieldToPatternLetter[];
/**
Calendar* fFromCalendar;
Calendar* fToCalendar;
- /**
- * Date time pattern generator
- */
- DateTimePatternGenerator* fDtpng;
+ Locale fLocale;
/**
* Following are interval information relevant (locale) to this formatter.
}
U_NAMESPACE_END
+#endif // U_SHOW_CPLUSPLUS_API
#endif /* #if !UCONFIG_NO_FORMATTING */