+U_CAPI URelativeDateTimeFormatter* U_EXPORT2
+ureldatefmt_open( const char* locale,
+ UNumberFormat* nfToAdopt,
+ UDateRelativeDateTimeFormatterStyle width,
+ UDisplayContext capitalizationContext,
+ UErrorCode* status )
+{
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ LocalPointer<RelativeDateTimeFormatter> formatter(new RelativeDateTimeFormatter(Locale(locale),
+ (NumberFormat*)nfToAdopt, width,
+ capitalizationContext, *status), *status);
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ return (URelativeDateTimeFormatter*)formatter.orphan();
+}
+
+U_CAPI void U_EXPORT2
+ureldatefmt_close(URelativeDateTimeFormatter *reldatefmt)
+{
+ delete (RelativeDateTimeFormatter*)reldatefmt;
+}
+
+U_CAPI int32_t U_EXPORT2
+ureldatefmt_formatNumeric( const URelativeDateTimeFormatter* reldatefmt,
+ double offset,
+ URelativeDateTimeUnit unit,
+ UChar* result,
+ int32_t resultCapacity,
+ UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ if (result == NULL ? resultCapacity != 0 : resultCapacity < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ UnicodeString res;
+ if (result != NULL) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer (copied from udat_format)
+ res.setTo(result, 0, resultCapacity);
+ }
+ ((RelativeDateTimeFormatter*)reldatefmt)->formatNumeric(offset, unit, res, *status);
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ return res.extract(result, resultCapacity, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+ureldatefmt_format( const URelativeDateTimeFormatter* reldatefmt,
+ double offset,
+ URelativeDateTimeUnit unit,
+ UChar* result,
+ int32_t resultCapacity,
+ UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ if (result == NULL ? resultCapacity != 0 : resultCapacity < 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ UnicodeString res;
+ if (result != NULL) {
+ // NULL destination for pure preflighting: empty dummy string
+ // otherwise, alias the destination buffer (copied from udat_format)
+ res.setTo(result, 0, resultCapacity);
+ }
+ ((RelativeDateTimeFormatter*)reldatefmt)->format(offset, unit, res, *status);
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ return res.extract(result, resultCapacity, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+ureldatefmt_combineDateAndTime( const URelativeDateTimeFormatter* reldatefmt,
+ const UChar * relativeDateString,
+ int32_t relativeDateStringLen,
+ const UChar * timeString,
+ int32_t timeStringLen,
+ UChar* result,
+ int32_t resultCapacity,
+ UErrorCode* status )
+{
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ if (result == NULL ? resultCapacity != 0 : resultCapacity < 0 ||
+ (relativeDateString == NULL ? relativeDateStringLen != 0 : relativeDateStringLen < -1) ||
+ (timeString == NULL ? timeStringLen != 0 : timeStringLen < -1)) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ UnicodeString relDateStr((UBool)(relativeDateStringLen == -1), relativeDateString, relativeDateStringLen);
+ UnicodeString timeStr((UBool)(timeStringLen == -1), timeString, timeStringLen);
+ UnicodeString res(result, 0, resultCapacity);
+ ((RelativeDateTimeFormatter*)reldatefmt)->combineDateAndTime(relDateStr, timeStr, res, *status);
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ return res.extract(result, resultCapacity, *status);
+}
+
+#endif /* !UCONFIG_NO_FORMATTING */