2 *******************************************************************************
3 * Copyright (C) 1996-2015, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
8 #include "unicode/utypes.h"
10 #if !UCONFIG_NO_FORMATTING
12 #include "unicode/udat.h"
14 #include "unicode/uloc.h"
15 #include "unicode/datefmt.h"
16 #include "unicode/timezone.h"
17 #include "unicode/smpdtfmt.h"
18 #include "unicode/fieldpos.h"
19 #include "unicode/parsepos.h"
20 #include "unicode/calendar.h"
21 #include "unicode/numfmt.h"
22 #include "unicode/dtfmtsym.h"
23 #include "unicode/ustring.h"
24 #include "unicode/udisplaycontext.h"
25 #include "unicode/ufieldpositer.h"
33 * Verify that fmt is a SimpleDateFormat. Invalid error if not.
34 * @param fmt the UDateFormat, definitely a DateFormat, maybe something else
35 * @param status error code, will be set to failure if there is a familure or the fmt is NULL.
37 static void verifyIsSimpleDateFormat(const UDateFormat
* fmt
, UErrorCode
*status
) {
38 if(U_SUCCESS(*status
) &&
39 dynamic_cast<const SimpleDateFormat
*>(reinterpret_cast<const DateFormat
*>(fmt
))==NULL
) {
40 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
44 // This mirrors the correspondence between the
45 // SimpleDateFormat::fgPatternIndexToDateFormatField and
46 // SimpleDateFormat::fgPatternIndexToCalendarField arrays.
47 static UCalendarDateFields gDateFieldMapping
[] = {
48 UCAL_ERA
, // UDAT_ERA_FIELD = 0
49 UCAL_YEAR
, // UDAT_YEAR_FIELD = 1
50 UCAL_MONTH
, // UDAT_MONTH_FIELD = 2
51 UCAL_DATE
, // UDAT_DATE_FIELD = 3
52 UCAL_HOUR_OF_DAY
, // UDAT_HOUR_OF_DAY1_FIELD = 4
53 UCAL_HOUR_OF_DAY
, // UDAT_HOUR_OF_DAY0_FIELD = 5
54 UCAL_MINUTE
, // UDAT_MINUTE_FIELD = 6
55 UCAL_SECOND
, // UDAT_SECOND_FIELD = 7
56 UCAL_MILLISECOND
, // UDAT_FRACTIONAL_SECOND_FIELD = 8
57 UCAL_DAY_OF_WEEK
, // UDAT_DAY_OF_WEEK_FIELD = 9
58 UCAL_DAY_OF_YEAR
, // UDAT_DAY_OF_YEAR_FIELD = 10
59 UCAL_DAY_OF_WEEK_IN_MONTH
, // UDAT_DAY_OF_WEEK_IN_MONTH_FIELD = 11
60 UCAL_WEEK_OF_YEAR
, // UDAT_WEEK_OF_YEAR_FIELD = 12
61 UCAL_WEEK_OF_MONTH
, // UDAT_WEEK_OF_MONTH_FIELD = 13
62 UCAL_AM_PM
, // UDAT_AM_PM_FIELD = 14
63 UCAL_HOUR
, // UDAT_HOUR1_FIELD = 15
64 UCAL_HOUR
, // UDAT_HOUR0_FIELD = 16
65 UCAL_ZONE_OFFSET
, // UDAT_TIMEZONE_FIELD = 17
66 UCAL_YEAR_WOY
, // UDAT_YEAR_WOY_FIELD = 18
67 UCAL_DOW_LOCAL
, // UDAT_DOW_LOCAL_FIELD = 19
68 UCAL_EXTENDED_YEAR
, // UDAT_EXTENDED_YEAR_FIELD = 20
69 UCAL_JULIAN_DAY
, // UDAT_JULIAN_DAY_FIELD = 21
70 UCAL_MILLISECONDS_IN_DAY
, // UDAT_MILLISECONDS_IN_DAY_FIELD = 22
71 UCAL_ZONE_OFFSET
, // UDAT_TIMEZONE_RFC_FIELD = 23 (also UCAL_DST_OFFSET)
72 UCAL_ZONE_OFFSET
, // UDAT_TIMEZONE_GENERIC_FIELD = 24 (also UCAL_DST_OFFSET)
73 UCAL_DOW_LOCAL
, // UDAT_STANDALONE_DAY_FIELD = 25
74 UCAL_MONTH
, // UDAT_STANDALONE_MONTH_FIELD = 26
75 UCAL_MONTH
, // UDAT_QUARTER_FIELD = 27
76 UCAL_MONTH
, // UDAT_STANDALONE_QUARTER_FIELD = 28
77 UCAL_ZONE_OFFSET
, // UDAT_TIMEZONE_SPECIAL_FIELD = 29 (also UCAL_DST_OFFSET)
78 UCAL_YEAR
, // UDAT_YEAR_NAME_FIELD = 30
79 UCAL_ZONE_OFFSET
, // UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD = 31 (also UCAL_DST_OFFSET)
80 UCAL_ZONE_OFFSET
, // UDAT_TIMEZONE_ISO_FIELD = 32 (also UCAL_DST_OFFSET)
81 UCAL_ZONE_OFFSET
, // UDAT_TIMEZONE_ISO_LOCAL_FIELD = 33 (also UCAL_DST_OFFSET)
82 UCAL_EXTENDED_YEAR
, // UDAT_RELATED_YEAR_FIELD = 34 (not an exact match)
83 UCAL_FIELD_COUNT
, // UDAT_FIELD_COUNT = 35
84 // UCAL_IS_LEAP_MONTH is not the target of a mapping
87 U_CAPI UCalendarDateFields U_EXPORT2
88 udat_toCalendarDateField(UDateFormatField field
) {
89 return gDateFieldMapping
[field
];
92 /* For now- one opener. */
93 static UDateFormatOpener gOpener
= NULL
;
95 U_INTERNAL
void U_EXPORT2
96 udat_registerOpener(UDateFormatOpener opener
, UErrorCode
*status
)
98 if(U_FAILURE(*status
)) return;
103 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
108 U_INTERNAL UDateFormatOpener U_EXPORT2
109 udat_unregisterOpener(UDateFormatOpener opener
, UErrorCode
*status
)
111 if(U_FAILURE(*status
)) return NULL
;
112 UDateFormatOpener oldOpener
= NULL
;
114 if(gOpener
==NULL
|| gOpener
!=opener
) {
115 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
126 U_CAPI UDateFormat
* U_EXPORT2
127 udat_open(UDateFormatStyle timeStyle
,
128 UDateFormatStyle dateStyle
,
132 const UChar
*pattern
,
133 int32_t patternLength
,
137 if(U_FAILURE(*status
)) {
140 if(gOpener
!=NULL
) { // if it's registered
141 fmt
= (DateFormat
*) (*gOpener
)(timeStyle
,dateStyle
,locale
,tzID
,tzIDLength
,pattern
,patternLength
,status
);
143 return (UDateFormat
*)fmt
;
144 } // else fall through.
146 if(timeStyle
!= UDAT_PATTERN
) {
148 fmt
= DateFormat::createDateTimeInstance((DateFormat::EStyle
)dateStyle
,
149 (DateFormat::EStyle
)timeStyle
);
152 fmt
= DateFormat::createDateTimeInstance((DateFormat::EStyle
)dateStyle
,
153 (DateFormat::EStyle
)timeStyle
,
158 UnicodeString
pat((UBool
)(patternLength
== -1), pattern
, patternLength
);
161 fmt
= new SimpleDateFormat(pat
, *status
);
164 fmt
= new SimpleDateFormat(pat
, Locale(locale
), *status
);
169 *status
= U_MEMORY_ALLOCATION_ERROR
;
174 TimeZone
*zone
= TimeZone::createTimeZone(UnicodeString((UBool
)(tzIDLength
== -1), tzID
, tzIDLength
));
176 *status
= U_MEMORY_ALLOCATION_ERROR
;
180 fmt
->adoptTimeZone(zone
);
183 return (UDateFormat
*)fmt
;
187 U_CAPI
void U_EXPORT2
188 udat_close(UDateFormat
* format
)
190 delete (DateFormat
*)format
;
193 U_CAPI UDateFormat
* U_EXPORT2
194 udat_clone(const UDateFormat
*fmt
,
197 if(U_FAILURE(*status
)) return 0;
199 Format
*res
= ((DateFormat
*)fmt
)->clone();
202 *status
= U_MEMORY_ALLOCATION_ERROR
;
206 return (UDateFormat
*) res
;
209 U_CAPI
int32_t U_EXPORT2
210 udat_format( const UDateFormat
* format
,
213 int32_t resultLength
,
214 UFieldPosition
* position
,
217 if(U_FAILURE(*status
)) {
220 if (result
== NULL
? resultLength
!= 0 : resultLength
< 0) {
221 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
226 if (result
!= NULL
) {
227 // NULL destination for pure preflighting: empty dummy string
228 // otherwise, alias the destination buffer
229 res
.setTo(result
, 0, resultLength
);
235 fp
.setField(position
->field
);
237 ((DateFormat
*)format
)->format(dateToFormat
, res
, fp
);
240 position
->beginIndex
= fp
.getBeginIndex();
241 position
->endIndex
= fp
.getEndIndex();
244 return res
.extract(result
, resultLength
, *status
);
247 U_CAPI
int32_t U_EXPORT2
248 udat_formatCalendar(const UDateFormat
* format
,
251 int32_t resultLength
,
252 UFieldPosition
* position
,
255 if(U_FAILURE(*status
)) {
258 if (result
== NULL
? resultLength
!= 0 : resultLength
< 0) {
259 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
264 if (result
!= NULL
) {
265 // NULL destination for pure preflighting: empty dummy string
266 // otherwise, alias the destination buffer
267 res
.setTo(result
, 0, resultLength
);
273 fp
.setField(position
->field
);
275 ((DateFormat
*)format
)->format(*(Calendar
*)calendar
, res
, fp
);
278 position
->beginIndex
= fp
.getBeginIndex();
279 position
->endIndex
= fp
.getEndIndex();
282 return res
.extract(result
, resultLength
, *status
);
285 U_CAPI
int32_t U_EXPORT2
286 udat_formatForFields( const UDateFormat
* format
,
289 int32_t resultLength
,
290 UFieldPositionIterator
* fpositer
,
293 if(U_FAILURE(*status
)) {
296 if (result
== NULL
? resultLength
!= 0 : resultLength
< 0) {
297 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
302 if (result
!= NULL
) {
303 // NULL destination for pure preflighting: empty dummy string
304 // otherwise, alias the destination buffer
305 res
.setTo(result
, 0, resultLength
);
308 ((DateFormat
*)format
)->format(dateToFormat
, res
, (FieldPositionIterator
*)fpositer
, *status
);
310 return res
.extract(result
, resultLength
, *status
);
313 U_CAPI
int32_t U_EXPORT2
314 udat_formatCalendarForFields(const UDateFormat
* format
,
317 int32_t resultLength
,
318 UFieldPositionIterator
* fpositer
,
321 if(U_FAILURE(*status
)) {
324 if (result
== NULL
? resultLength
!= 0 : resultLength
< 0) {
325 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
330 if (result
!= NULL
) {
331 // NULL destination for pure preflighting: empty dummy string
332 // otherwise, alias the destination buffer
333 res
.setTo(result
, 0, resultLength
);
336 ((DateFormat
*)format
)->format(*(Calendar
*)calendar
, res
, (FieldPositionIterator
*)fpositer
, *status
);
338 return res
.extract(result
, resultLength
, *status
);
341 U_CAPI UDate U_EXPORT2
342 udat_parse( const UDateFormat
* format
,
348 if(U_FAILURE(*status
)) return (UDate
)0;
350 const UnicodeString
src((UBool
)(textLength
== -1), text
, textLength
);
352 int32_t stackParsePos
= 0;
355 if(parsePos
== NULL
) {
356 parsePos
= &stackParsePos
;
359 pp
.setIndex(*parsePos
);
361 res
= ((DateFormat
*)format
)->parse(src
, pp
);
363 if(pp
.getErrorIndex() == -1)
364 *parsePos
= pp
.getIndex();
366 *parsePos
= pp
.getErrorIndex();
367 *status
= U_PARSE_ERROR
;
373 U_CAPI
void U_EXPORT2
374 udat_parseCalendar(const UDateFormat
* format
,
381 if(U_FAILURE(*status
)) return;
383 const UnicodeString
src((UBool
)(textLength
== -1), text
, textLength
);
385 int32_t stackParsePos
= 0;
387 if(parsePos
== NULL
) {
388 parsePos
= &stackParsePos
;
391 pp
.setIndex(*parsePos
);
393 ((DateFormat
*)format
)->parse(src
, *(Calendar
*)calendar
, pp
);
395 if(pp
.getErrorIndex() == -1)
396 *parsePos
= pp
.getIndex();
398 *parsePos
= pp
.getErrorIndex();
399 *status
= U_PARSE_ERROR
;
403 U_CAPI UBool U_EXPORT2
404 udat_isLenient(const UDateFormat
* fmt
)
406 return ((DateFormat
*)fmt
)->isLenient();
409 U_CAPI
void U_EXPORT2
410 udat_setLenient( UDateFormat
* fmt
,
413 ((DateFormat
*)fmt
)->setLenient(isLenient
);
416 U_DRAFT UBool U_EXPORT2
417 udat_getBooleanAttribute(const UDateFormat
* fmt
,
418 UDateFormatBooleanAttribute attr
,
421 if(U_FAILURE(*status
)) return FALSE
;
422 return ((DateFormat
*)fmt
)->getBooleanAttribute(attr
, *status
);
426 U_DRAFT
void U_EXPORT2
427 udat_setBooleanAttribute(UDateFormat
*fmt
,
428 UDateFormatBooleanAttribute attr
,
432 if(U_FAILURE(*status
)) return;
433 ((DateFormat
*)fmt
)->setBooleanAttribute(attr
, newValue
, *status
);
436 U_CAPI
const UCalendar
* U_EXPORT2
437 udat_getCalendar(const UDateFormat
* fmt
)
439 return (const UCalendar
*) ((DateFormat
*)fmt
)->getCalendar();
442 U_CAPI
void U_EXPORT2
443 udat_setCalendar(UDateFormat
* fmt
,
444 const UCalendar
* calendarToSet
)
446 ((DateFormat
*)fmt
)->setCalendar(*((Calendar
*)calendarToSet
));
449 U_DRAFT
const UNumberFormat
* U_EXPORT2
450 udat_getNumberFormatForField(const UDateFormat
* fmt
, UChar field
)
452 UErrorCode status
= U_ZERO_ERROR
;
453 verifyIsSimpleDateFormat(fmt
, &status
);
454 if (U_FAILURE(status
)) return (const UNumberFormat
*) ((DateFormat
*)fmt
)->getNumberFormat();
455 return (const UNumberFormat
*) ((SimpleDateFormat
*)fmt
)->getNumberFormatForField(field
);
458 U_CAPI
const UNumberFormat
* U_EXPORT2
459 udat_getNumberFormat(const UDateFormat
* fmt
)
461 return (const UNumberFormat
*) ((DateFormat
*)fmt
)->getNumberFormat();
464 U_DRAFT
void U_EXPORT2
465 udat_adoptNumberFormatForFields( UDateFormat
* fmt
,
467 UNumberFormat
* numberFormatToSet
,
470 verifyIsSimpleDateFormat(fmt
, status
);
471 if (U_FAILURE(*status
)) return;
474 UnicodeString
overrideFields(fields
);
475 ((SimpleDateFormat
*)fmt
)->adoptNumberFormat(overrideFields
, (NumberFormat
*)numberFormatToSet
, *status
);
479 U_CAPI
void U_EXPORT2
480 udat_setNumberFormat(UDateFormat
* fmt
,
481 const UNumberFormat
* numberFormatToSet
)
483 ((DateFormat
*)fmt
)->setNumberFormat(*((NumberFormat
*)numberFormatToSet
));
486 U_DRAFT
void U_EXPORT2
487 udat_adoptNumberFormat( UDateFormat
* fmt
,
488 UNumberFormat
* numberFormatToAdopt
)
490 ((DateFormat
*)fmt
)->adoptNumberFormat((NumberFormat
*)numberFormatToAdopt
);
493 U_CAPI
const char* U_EXPORT2
494 udat_getAvailable(int32_t index
)
496 return uloc_getAvailable(index
);
499 U_CAPI
int32_t U_EXPORT2
500 udat_countAvailable()
502 return uloc_countAvailable();
505 U_CAPI UDate U_EXPORT2
506 udat_get2DigitYearStart( const UDateFormat
*fmt
,
509 verifyIsSimpleDateFormat(fmt
, status
);
510 if(U_FAILURE(*status
)) return (UDate
)0;
511 return ((SimpleDateFormat
*)fmt
)->get2DigitYearStart(*status
);
514 U_CAPI
void U_EXPORT2
515 udat_set2DigitYearStart( UDateFormat
*fmt
,
519 verifyIsSimpleDateFormat(fmt
, status
);
520 if(U_FAILURE(*status
)) return;
521 ((SimpleDateFormat
*)fmt
)->set2DigitYearStart(d
, *status
);
524 U_CAPI
int32_t U_EXPORT2
525 udat_toPattern( const UDateFormat
*fmt
,
528 int32_t resultLength
,
531 if(U_FAILURE(*status
)) {
534 if (result
== NULL
? resultLength
!= 0 : resultLength
< 0) {
535 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
540 if (result
!= NULL
) {
541 // NULL destination for pure preflighting: empty dummy string
542 // otherwise, alias the destination buffer
543 res
.setTo(result
, 0, resultLength
);
546 const DateFormat
*df
=reinterpret_cast<const DateFormat
*>(fmt
);
547 const SimpleDateFormat
*sdtfmt
=dynamic_cast<const SimpleDateFormat
*>(df
);
548 const RelativeDateFormat
*reldtfmt
;
551 sdtfmt
->toLocalizedPattern(res
, *status
);
553 sdtfmt
->toPattern(res
);
554 } else if (!localized
&& (reldtfmt
=dynamic_cast<const RelativeDateFormat
*>(df
))!=NULL
) {
555 reldtfmt
->toPattern(res
, *status
);
557 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
561 return res
.extract(result
, resultLength
, *status
);
564 // TODO: should this take an UErrorCode?
565 // A: Yes. Of course.
566 U_CAPI
void U_EXPORT2
567 udat_applyPattern( UDateFormat
*format
,
569 const UChar
*pattern
,
570 int32_t patternLength
)
572 const UnicodeString
pat((UBool
)(patternLength
== -1), pattern
, patternLength
);
573 UErrorCode status
= U_ZERO_ERROR
;
575 verifyIsSimpleDateFormat(format
, &status
);
576 if(U_FAILURE(status
)) {
581 ((SimpleDateFormat
*)format
)->applyLocalizedPattern(pat
, status
);
583 ((SimpleDateFormat
*)format
)->applyPattern(pat
);
587 static DateFormatSymbols::ECapitalizationContextUsageType
capUsageFromSymbolType(UDateFormatSymbolType type
)
589 DateFormatSymbols::ECapitalizationContextUsageType capContextUsageType
= DateFormatSymbols::kCapContextUsageOther
;
592 capContextUsageType
= DateFormatSymbols::kCapContextUsageEraWide
;
595 capContextUsageType
= DateFormatSymbols::kCapContextUsageEraAbbrev
;
598 case UDAT_SHORT_MONTHS
:
599 capContextUsageType
= DateFormatSymbols::kCapContextUsageMonthFormat
;
601 case UDAT_STANDALONE_MONTHS
:
602 case UDAT_STANDALONE_SHORT_MONTHS
:
603 capContextUsageType
= DateFormatSymbols::kCapContextUsageMonthStandalone
;
605 case UDAT_NARROW_MONTHS
:
606 case UDAT_STANDALONE_NARROW_MONTHS
:
607 capContextUsageType
= DateFormatSymbols::kCapContextUsageMonthNarrow
;
610 case UDAT_SHORT_WEEKDAYS
:
611 case UDAT_SHORTER_WEEKDAYS
:
612 capContextUsageType
= DateFormatSymbols::kCapContextUsageDayFormat
;
614 case UDAT_STANDALONE_WEEKDAYS
:
615 case UDAT_STANDALONE_SHORT_WEEKDAYS
:
616 case UDAT_STANDALONE_SHORTER_WEEKDAYS
:
617 capContextUsageType
= DateFormatSymbols::kCapContextUsageDayStandalone
;
619 case UDAT_STANDALONE_NARROW_WEEKDAYS
:
620 case UDAT_NARROW_WEEKDAYS
:
621 capContextUsageType
= DateFormatSymbols::kCapContextUsageDayNarrow
;
626 return capContextUsageType
;
631 U_CAPI
int32_t U_EXPORT2
632 udat_getSymbols(const UDateFormat
*fmt
,
633 UDateFormatSymbolType type
,
636 int32_t resultLength
,
639 const DateFormatSymbols
*syms
;
640 const SimpleDateFormat
* sdtfmt
;
641 const RelativeDateFormat
* rdtfmt
;
642 BreakIterator
* capitalizationBrkIter
;
643 if ((sdtfmt
= dynamic_cast<const SimpleDateFormat
*>(reinterpret_cast<const DateFormat
*>(fmt
))) != NULL
) {
644 syms
= sdtfmt
->getDateFormatSymbols();
645 capitalizationBrkIter
= sdtfmt
->getCapitalizationBrkIter();
646 } else if ((rdtfmt
= dynamic_cast<const RelativeDateFormat
*>(reinterpret_cast<const DateFormat
*>(fmt
))) != NULL
) {
647 syms
= rdtfmt
->getDateFormatSymbols();
648 capitalizationBrkIter
= rdtfmt
->getCapitalizationBrkIter();
653 const UnicodeString
*res
= NULL
;
657 res
= syms
->getEras(count
);
661 res
= syms
->getEraNames(count
);
665 res
= syms
->getMonths(count
);
668 case UDAT_SHORT_MONTHS
:
669 res
= syms
->getShortMonths(count
);
673 res
= syms
->getWeekdays(count
);
676 case UDAT_SHORT_WEEKDAYS
:
677 res
= syms
->getShortWeekdays(count
);
681 res
= syms
->getAmPmStrings(count
);
684 case UDAT_LOCALIZED_CHARS
:
687 if(!(result
==NULL
&& resultLength
==0)) {
688 // NULL destination for pure preflighting: empty dummy string
689 // otherwise, alias the destination buffer
690 res1
.setTo(result
, 0, resultLength
);
692 syms
->getLocalPatternChars(res1
);
693 return res1
.extract(result
, resultLength
, *status
);
696 case UDAT_NARROW_MONTHS
:
697 res
= syms
->getMonths(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
700 case UDAT_SHORTER_WEEKDAYS
:
701 res
= syms
->getWeekdays(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::SHORT
);
704 case UDAT_NARROW_WEEKDAYS
:
705 res
= syms
->getWeekdays(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
708 case UDAT_STANDALONE_MONTHS
:
709 res
= syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
712 case UDAT_STANDALONE_SHORT_MONTHS
:
713 res
= syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
716 case UDAT_STANDALONE_NARROW_MONTHS
:
717 res
= syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::NARROW
);
720 case UDAT_STANDALONE_WEEKDAYS
:
721 res
= syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
724 case UDAT_STANDALONE_SHORT_WEEKDAYS
:
725 res
= syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
728 case UDAT_STANDALONE_SHORTER_WEEKDAYS
:
729 res
= syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::SHORT
);
732 case UDAT_STANDALONE_NARROW_WEEKDAYS
:
733 res
= syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::NARROW
);
737 res
= syms
->getQuarters(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
740 case UDAT_SHORT_QUARTERS
:
741 res
= syms
->getQuarters(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
744 case UDAT_STANDALONE_QUARTERS
:
745 res
= syms
->getQuarters(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
748 case UDAT_STANDALONE_SHORT_QUARTERS
:
749 res
= syms
->getQuarters(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
752 case UDAT_CYCLIC_YEARS_WIDE
:
753 res
= syms
->getYearNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
756 case UDAT_CYCLIC_YEARS_ABBREVIATED
:
757 res
= syms
->getYearNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
760 case UDAT_CYCLIC_YEARS_NARROW
:
761 res
= syms
->getYearNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
764 case UDAT_ZODIAC_NAMES_WIDE
:
765 res
= syms
->getZodiacNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
768 case UDAT_ZODIAC_NAMES_ABBREVIATED
:
769 res
= syms
->getZodiacNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
772 case UDAT_ZODIAC_NAMES_NARROW
:
773 res
= syms
->getZodiacNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
776 case UADAT_CYCLIC_ZODIAC_NAMES
:
777 res
= syms
->getZodiacNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
778 index
= (index
> 0)? (index
- 1) % 12: 0;
784 #if !UCONFIG_NO_BREAK_ITERATION
785 // Apple addition for <rdar://problem/27335144>
786 if (u_islower(res
[index
].char32At(0)) && capitalizationBrkIter
!= NULL
) {
787 UDisplayContext capitalizationContext
= ((const DateFormat
*)fmt
)->getContext(UDISPCTX_TYPE_CAPITALIZATION
, *status
);
788 UBool titlecase
= FALSE
;
789 switch (capitalizationContext
) {
790 case UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE
:
793 case UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU
:
794 titlecase
= syms
->capitalizeForUsage(capUsageFromSymbolType(type
), 0);
796 case UDISPCTX_CAPITALIZATION_FOR_STANDALONE
:
797 titlecase
= syms
->capitalizeForUsage(capUsageFromSymbolType(type
), 1);
800 // titlecase = FALSE;
804 UnicodeString
symbolToModify(res
[index
]);
805 BreakIterator
* capBrkIterToUse
= capitalizationBrkIter
->clone();
806 if (capBrkIterToUse
!= NULL
) {
807 Locale locale
= capBrkIterToUse
->getLocale(ULOC_ACTUAL_LOCALE
, *status
);
808 if (U_SUCCESS(*status
)) {
809 symbolToModify
.toTitle(capBrkIterToUse
, locale
, U_TITLECASE_NO_LOWERCASE
| U_TITLECASE_NO_BREAK_ADJUSTMENT
);
810 delete capBrkIterToUse
;
811 return symbolToModify
.extract(result
, resultLength
, *status
);
813 delete capBrkIterToUse
;
818 return res
[index
].extract(result
, resultLength
, *status
);
823 // TODO: also needs an errorCode.
824 U_CAPI
int32_t U_EXPORT2
825 udat_countSymbols( const UDateFormat
*fmt
,
826 UDateFormatSymbolType type
)
828 const DateFormatSymbols
*syms
;
829 const SimpleDateFormat
* sdtfmt
;
830 const RelativeDateFormat
* rdtfmt
;
831 if ((sdtfmt
= dynamic_cast<const SimpleDateFormat
*>(reinterpret_cast<const DateFormat
*>(fmt
))) != NULL
) {
832 syms
= sdtfmt
->getDateFormatSymbols();
833 } else if ((rdtfmt
= dynamic_cast<const RelativeDateFormat
*>(reinterpret_cast<const DateFormat
*>(fmt
))) != NULL
) {
834 syms
= rdtfmt
->getDateFormatSymbols();
842 syms
->getEras(count
);
846 syms
->getMonths(count
);
849 case UDAT_SHORT_MONTHS
:
850 syms
->getShortMonths(count
);
854 syms
->getWeekdays(count
);
857 case UDAT_SHORT_WEEKDAYS
:
858 syms
->getShortWeekdays(count
);
862 syms
->getAmPmStrings(count
);
865 case UDAT_LOCALIZED_CHARS
:
870 syms
->getEraNames(count
);
873 case UDAT_NARROW_MONTHS
:
874 syms
->getMonths(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
877 case UDAT_SHORTER_WEEKDAYS
:
878 syms
->getWeekdays(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::SHORT
);
881 case UDAT_NARROW_WEEKDAYS
:
882 syms
->getWeekdays(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
885 case UDAT_STANDALONE_MONTHS
:
886 syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
889 case UDAT_STANDALONE_SHORT_MONTHS
:
890 syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
893 case UDAT_STANDALONE_NARROW_MONTHS
:
894 syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::NARROW
);
897 case UDAT_STANDALONE_WEEKDAYS
:
898 syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
901 case UDAT_STANDALONE_SHORT_WEEKDAYS
:
902 syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
905 case UDAT_STANDALONE_SHORTER_WEEKDAYS
:
906 syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::SHORT
);
909 case UDAT_STANDALONE_NARROW_WEEKDAYS
:
910 syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::NARROW
);
914 syms
->getQuarters(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
917 case UDAT_SHORT_QUARTERS
:
918 syms
->getQuarters(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
921 case UDAT_STANDALONE_QUARTERS
:
922 syms
->getQuarters(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
925 case UDAT_STANDALONE_SHORT_QUARTERS
:
926 syms
->getQuarters(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
929 case UDAT_CYCLIC_YEARS_WIDE
:
930 syms
->getYearNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
933 case UDAT_CYCLIC_YEARS_ABBREVIATED
:
934 syms
->getYearNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
937 case UDAT_CYCLIC_YEARS_NARROW
:
938 syms
->getYearNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
941 case UDAT_ZODIAC_NAMES_WIDE
:
942 syms
->getZodiacNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
945 case UDAT_ZODIAC_NAMES_ABBREVIATED
:
946 syms
->getZodiacNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
949 case UDAT_ZODIAC_NAMES_NARROW
:
950 syms
->getZodiacNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
953 case UADAT_CYCLIC_ZODIAC_NAMES
:
954 syms
->getZodiacNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
965 * This DateFormatSymbolsSingleSetter class is a friend of DateFormatSymbols
966 * solely for the purpose of avoiding to clone the array of strings
967 * just to modify one of them and then setting all of them back.
968 * For example, the old code looked like this:
970 * res = syms->getMonths(count);
971 * array = new UnicodeString[count];
973 * *status = U_MEMORY_ALLOCATION_ERROR;
976 * uprv_arrayCopy(res, array, count);
978 * array[index] = val;
979 * syms->setMonths(array, count);
982 * Even worse, the old code actually cloned the entire DateFormatSymbols object,
983 * cloned one value array, changed one value, and then made the SimpleDateFormat
984 * replace its DateFormatSymbols object with the new one.
988 class DateFormatSymbolsSingleSetter
/* not : public UObject because all methods are static */ {
991 setSymbol(UnicodeString
*array
, int32_t count
, int32_t index
,
992 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
996 errorCode
=U_INDEX_OUTOFBOUNDS_ERROR
;
997 } else if(value
==NULL
) {
998 errorCode
=U_ILLEGAL_ARGUMENT_ERROR
;
1000 array
[index
].setTo(value
, valueLength
);
1006 setEra(DateFormatSymbols
*syms
, int32_t index
,
1007 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1009 setSymbol(syms
->fEras
, syms
->fErasCount
, index
, value
, valueLength
, errorCode
);
1013 setEraName(DateFormatSymbols
*syms
, int32_t index
,
1014 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1016 setSymbol(syms
->fEraNames
, syms
->fEraNamesCount
, index
, value
, valueLength
, errorCode
);
1020 setMonth(DateFormatSymbols
*syms
, int32_t index
,
1021 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1023 setSymbol(syms
->fMonths
, syms
->fMonthsCount
, index
, value
, valueLength
, errorCode
);
1027 setShortMonth(DateFormatSymbols
*syms
, int32_t index
,
1028 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1030 setSymbol(syms
->fShortMonths
, syms
->fShortMonthsCount
, index
, value
, valueLength
, errorCode
);
1034 setNarrowMonth(DateFormatSymbols
*syms
, int32_t index
,
1035 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1037 setSymbol(syms
->fNarrowMonths
, syms
->fNarrowMonthsCount
, index
, value
, valueLength
, errorCode
);
1041 setStandaloneMonth(DateFormatSymbols
*syms
, int32_t index
,
1042 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1044 setSymbol(syms
->fStandaloneMonths
, syms
->fStandaloneMonthsCount
, index
, value
, valueLength
, errorCode
);
1048 setStandaloneShortMonth(DateFormatSymbols
*syms
, int32_t index
,
1049 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1051 setSymbol(syms
->fStandaloneShortMonths
, syms
->fStandaloneShortMonthsCount
, index
, value
, valueLength
, errorCode
);
1055 setStandaloneNarrowMonth(DateFormatSymbols
*syms
, int32_t index
,
1056 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1058 setSymbol(syms
->fStandaloneNarrowMonths
, syms
->fStandaloneNarrowMonthsCount
, index
, value
, valueLength
, errorCode
);
1062 setWeekday(DateFormatSymbols
*syms
, int32_t index
,
1063 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1065 setSymbol(syms
->fWeekdays
, syms
->fWeekdaysCount
, index
, value
, valueLength
, errorCode
);
1069 setShortWeekday(DateFormatSymbols
*syms
, int32_t index
,
1070 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1072 setSymbol(syms
->fShortWeekdays
, syms
->fShortWeekdaysCount
, index
, value
, valueLength
, errorCode
);
1076 setShorterWeekday(DateFormatSymbols
*syms
, int32_t index
,
1077 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1079 setSymbol(syms
->fShorterWeekdays
, syms
->fShorterWeekdaysCount
, index
, value
, valueLength
, errorCode
);
1083 setNarrowWeekday(DateFormatSymbols
*syms
, int32_t index
,
1084 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1086 setSymbol(syms
->fNarrowWeekdays
, syms
->fNarrowWeekdaysCount
, index
, value
, valueLength
, errorCode
);
1090 setStandaloneWeekday(DateFormatSymbols
*syms
, int32_t index
,
1091 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1093 setSymbol(syms
->fStandaloneWeekdays
, syms
->fStandaloneWeekdaysCount
, index
, value
, valueLength
, errorCode
);
1097 setStandaloneShortWeekday(DateFormatSymbols
*syms
, int32_t index
,
1098 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1100 setSymbol(syms
->fStandaloneShortWeekdays
, syms
->fStandaloneShortWeekdaysCount
, index
, value
, valueLength
, errorCode
);
1104 setStandaloneShorterWeekday(DateFormatSymbols
*syms
, int32_t index
,
1105 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1107 setSymbol(syms
->fStandaloneShorterWeekdays
, syms
->fStandaloneShorterWeekdaysCount
, index
, value
, valueLength
, errorCode
);
1111 setStandaloneNarrowWeekday(DateFormatSymbols
*syms
, int32_t index
,
1112 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1114 setSymbol(syms
->fStandaloneNarrowWeekdays
, syms
->fStandaloneNarrowWeekdaysCount
, index
, value
, valueLength
, errorCode
);
1118 setQuarter(DateFormatSymbols
*syms
, int32_t index
,
1119 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1121 setSymbol(syms
->fQuarters
, syms
->fQuartersCount
, index
, value
, valueLength
, errorCode
);
1125 setShortQuarter(DateFormatSymbols
*syms
, int32_t index
,
1126 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1128 setSymbol(syms
->fShortQuarters
, syms
->fShortQuartersCount
, index
, value
, valueLength
, errorCode
);
1132 setStandaloneQuarter(DateFormatSymbols
*syms
, int32_t index
,
1133 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1135 setSymbol(syms
->fStandaloneQuarters
, syms
->fStandaloneQuartersCount
, index
, value
, valueLength
, errorCode
);
1139 setStandaloneShortQuarter(DateFormatSymbols
*syms
, int32_t index
,
1140 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1142 setSymbol(syms
->fStandaloneShortQuarters
, syms
->fStandaloneShortQuartersCount
, index
, value
, valueLength
, errorCode
);
1146 setShortYearNames(DateFormatSymbols
*syms
, int32_t index
,
1147 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1149 setSymbol(syms
->fShortYearNames
, syms
->fShortYearNamesCount
, index
, value
, valueLength
, errorCode
);
1153 setShortZodiacNames(DateFormatSymbols
*syms
, int32_t index
,
1154 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1156 setSymbol(syms
->fShortZodiacNames
, syms
->fShortZodiacNamesCount
, index
, value
, valueLength
, errorCode
);
1160 setAmPm(DateFormatSymbols
*syms
, int32_t index
,
1161 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1163 setSymbol(syms
->fAmPms
, syms
->fAmPmsCount
, index
, value
, valueLength
, errorCode
);
1167 setLocalPatternChars(DateFormatSymbols
*syms
,
1168 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1170 setSymbol(&syms
->fLocalPatternChars
, 1, 0, value
, valueLength
, errorCode
);
1176 U_CAPI
void U_EXPORT2
1177 udat_setSymbols( UDateFormat
*format
,
1178 UDateFormatSymbolType type
,
1181 int32_t valueLength
,
1184 verifyIsSimpleDateFormat(format
, status
);
1185 if(U_FAILURE(*status
)) return;
1187 DateFormatSymbols
*syms
= (DateFormatSymbols
*)((SimpleDateFormat
*)format
)->getDateFormatSymbols();
1191 DateFormatSymbolsSingleSetter::setEra(syms
, index
, value
, valueLength
, *status
);
1194 case UDAT_ERA_NAMES
:
1195 DateFormatSymbolsSingleSetter::setEraName(syms
, index
, value
, valueLength
, *status
);
1199 DateFormatSymbolsSingleSetter::setMonth(syms
, index
, value
, valueLength
, *status
);
1202 case UDAT_SHORT_MONTHS
:
1203 DateFormatSymbolsSingleSetter::setShortMonth(syms
, index
, value
, valueLength
, *status
);
1206 case UDAT_NARROW_MONTHS
:
1207 DateFormatSymbolsSingleSetter::setNarrowMonth(syms
, index
, value
, valueLength
, *status
);
1210 case UDAT_STANDALONE_MONTHS
:
1211 DateFormatSymbolsSingleSetter::setStandaloneMonth(syms
, index
, value
, valueLength
, *status
);
1214 case UDAT_STANDALONE_SHORT_MONTHS
:
1215 DateFormatSymbolsSingleSetter::setStandaloneShortMonth(syms
, index
, value
, valueLength
, *status
);
1218 case UDAT_STANDALONE_NARROW_MONTHS
:
1219 DateFormatSymbolsSingleSetter::setStandaloneNarrowMonth(syms
, index
, value
, valueLength
, *status
);
1223 DateFormatSymbolsSingleSetter::setWeekday(syms
, index
, value
, valueLength
, *status
);
1226 case UDAT_SHORT_WEEKDAYS
:
1227 DateFormatSymbolsSingleSetter::setShortWeekday(syms
, index
, value
, valueLength
, *status
);
1230 case UDAT_SHORTER_WEEKDAYS
:
1231 DateFormatSymbolsSingleSetter::setShorterWeekday(syms
, index
, value
, valueLength
, *status
);
1234 case UDAT_NARROW_WEEKDAYS
:
1235 DateFormatSymbolsSingleSetter::setNarrowWeekday(syms
, index
, value
, valueLength
, *status
);
1238 case UDAT_STANDALONE_WEEKDAYS
:
1239 DateFormatSymbolsSingleSetter::setStandaloneWeekday(syms
, index
, value
, valueLength
, *status
);
1242 case UDAT_STANDALONE_SHORT_WEEKDAYS
:
1243 DateFormatSymbolsSingleSetter::setStandaloneShortWeekday(syms
, index
, value
, valueLength
, *status
);
1246 case UDAT_STANDALONE_SHORTER_WEEKDAYS
:
1247 DateFormatSymbolsSingleSetter::setStandaloneShorterWeekday(syms
, index
, value
, valueLength
, *status
);
1250 case UDAT_STANDALONE_NARROW_WEEKDAYS
:
1251 DateFormatSymbolsSingleSetter::setStandaloneNarrowWeekday(syms
, index
, value
, valueLength
, *status
);
1255 DateFormatSymbolsSingleSetter::setQuarter(syms
, index
, value
, valueLength
, *status
);
1258 case UDAT_SHORT_QUARTERS
:
1259 DateFormatSymbolsSingleSetter::setShortQuarter(syms
, index
, value
, valueLength
, *status
);
1262 case UDAT_STANDALONE_QUARTERS
:
1263 DateFormatSymbolsSingleSetter::setStandaloneQuarter(syms
, index
, value
, valueLength
, *status
);
1266 case UDAT_STANDALONE_SHORT_QUARTERS
:
1267 DateFormatSymbolsSingleSetter::setStandaloneShortQuarter(syms
, index
, value
, valueLength
, *status
);
1270 case UDAT_CYCLIC_YEARS_ABBREVIATED
:
1271 DateFormatSymbolsSingleSetter::setShortYearNames(syms
, index
, value
, valueLength
, *status
);
1274 case UDAT_ZODIAC_NAMES_ABBREVIATED
:
1275 DateFormatSymbolsSingleSetter::setShortZodiacNames(syms
, index
, value
, valueLength
, *status
);
1279 DateFormatSymbolsSingleSetter::setAmPm(syms
, index
, value
, valueLength
, *status
);
1282 case UDAT_LOCALIZED_CHARS
:
1283 DateFormatSymbolsSingleSetter::setLocalPatternChars(syms
, value
, valueLength
, *status
);
1287 *status
= U_UNSUPPORTED_ERROR
;
1293 U_CAPI
const char* U_EXPORT2
1294 udat_getLocaleByType(const UDateFormat
*fmt
,
1295 ULocDataLocaleType type
,
1299 if (U_SUCCESS(*status
)) {
1300 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
1304 return ((Format
*)fmt
)->getLocaleID(type
, *status
);
1307 U_CAPI
void U_EXPORT2
1308 udat_setContext(UDateFormat
* fmt
, UDisplayContext value
, UErrorCode
* status
)
1310 if (U_FAILURE(*status
)) {
1313 ((DateFormat
*)fmt
)->setContext(value
, *status
);
1317 U_CAPI UDisplayContext U_EXPORT2
1318 udat_getContext(const UDateFormat
* fmt
, UDisplayContextType type
, UErrorCode
* status
)
1320 if (U_FAILURE(*status
)) {
1321 return (UDisplayContext
)0;
1323 return ((const DateFormat
*)fmt
)->getContext(type
, *status
);
1328 * Verify that fmt is a RelativeDateFormat. Invalid error if not.
1329 * @param fmt the UDateFormat, definitely a DateFormat, maybe something else
1330 * @param status error code, will be set to failure if there is a familure or the fmt is NULL.
1332 static void verifyIsRelativeDateFormat(const UDateFormat
* fmt
, UErrorCode
*status
) {
1333 if(U_SUCCESS(*status
) &&
1334 dynamic_cast<const RelativeDateFormat
*>(reinterpret_cast<const DateFormat
*>(fmt
))==NULL
) {
1335 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
1340 U_CAPI
int32_t U_EXPORT2
1341 udat_toPatternRelativeDate(const UDateFormat
*fmt
,
1343 int32_t resultLength
,
1346 verifyIsRelativeDateFormat(fmt
, status
);
1347 if(U_FAILURE(*status
)) {
1350 if (result
== NULL
? resultLength
!= 0 : resultLength
< 0) {
1351 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
1355 UnicodeString datePattern
;
1356 if (result
!= NULL
) {
1357 // NULL destination for pure preflighting: empty dummy string
1358 // otherwise, alias the destination buffer
1359 datePattern
.setTo(result
, 0, resultLength
);
1361 ((RelativeDateFormat
*)fmt
)->toPatternDate(datePattern
, *status
);
1362 return datePattern
.extract(result
, resultLength
, *status
);
1365 U_CAPI
int32_t U_EXPORT2
1366 udat_toPatternRelativeTime(const UDateFormat
*fmt
,
1368 int32_t resultLength
,
1371 verifyIsRelativeDateFormat(fmt
, status
);
1372 if(U_FAILURE(*status
)) {
1375 if (result
== NULL
? resultLength
!= 0 : resultLength
< 0) {
1376 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
1380 UnicodeString timePattern
;
1381 if (result
!= NULL
) {
1382 // NULL destination for pure preflighting: empty dummy string
1383 // otherwise, alias the destination buffer
1384 timePattern
.setTo(result
, 0, resultLength
);
1386 ((RelativeDateFormat
*)fmt
)->toPatternTime(timePattern
, *status
);
1387 return timePattern
.extract(result
, resultLength
, *status
);
1390 U_CAPI
void U_EXPORT2
1391 udat_applyPatternRelative(UDateFormat
*format
,
1392 const UChar
*datePattern
,
1393 int32_t datePatternLength
,
1394 const UChar
*timePattern
,
1395 int32_t timePatternLength
,
1398 verifyIsRelativeDateFormat(format
, status
);
1399 if(U_FAILURE(*status
)) return;
1400 const UnicodeString
datePat((UBool
)(datePatternLength
== -1), datePattern
, datePatternLength
);
1401 const UnicodeString
timePat((UBool
)(timePatternLength
== -1), timePattern
, timePatternLength
);
1402 ((RelativeDateFormat
*)format
)->applyPatterns(datePat
, timePat
, *status
);
1405 #endif /* #if !UCONFIG_NO_FORMATTING */