1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 1996-2015, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
10 #include "unicode/utypes.h"
12 #if !UCONFIG_NO_FORMATTING
14 #include "unicode/udat.h"
16 #include "unicode/uloc.h"
17 #include "unicode/datefmt.h"
18 #include "unicode/timezone.h"
19 #include "unicode/smpdtfmt.h"
20 #include "unicode/fieldpos.h"
21 #include "unicode/parsepos.h"
22 #include "unicode/calendar.h"
23 #include "unicode/numfmt.h"
24 #include "unicode/dtfmtsym.h"
25 #include "unicode/ustring.h"
26 #include "unicode/udisplaycontext.h"
27 #include "unicode/ufieldpositer.h"
28 #include "unicode/ucasemap.h"
36 * Verify that fmt is a SimpleDateFormat. Invalid error if not.
37 * @param fmt the UDateFormat, definitely a DateFormat, maybe something else
38 * @param status error code, will be set to failure if there is a familure or the fmt is NULL.
40 static void verifyIsSimpleDateFormat(const UDateFormat
* fmt
, UErrorCode
*status
) {
41 if(U_SUCCESS(*status
) &&
42 dynamic_cast<const SimpleDateFormat
*>(reinterpret_cast<const DateFormat
*>(fmt
))==NULL
) {
43 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
47 // This mirrors the correspondence between the
48 // SimpleDateFormat::fgPatternIndexToDateFormatField and
49 // SimpleDateFormat::fgPatternIndexToCalendarField arrays.
50 static UCalendarDateFields gDateFieldMapping
[] = {
51 UCAL_ERA
, // UDAT_ERA_FIELD = 0
52 UCAL_YEAR
, // UDAT_YEAR_FIELD = 1
53 UCAL_MONTH
, // UDAT_MONTH_FIELD = 2
54 UCAL_DATE
, // UDAT_DATE_FIELD = 3
55 UCAL_HOUR_OF_DAY
, // UDAT_HOUR_OF_DAY1_FIELD = 4
56 UCAL_HOUR_OF_DAY
, // UDAT_HOUR_OF_DAY0_FIELD = 5
57 UCAL_MINUTE
, // UDAT_MINUTE_FIELD = 6
58 UCAL_SECOND
, // UDAT_SECOND_FIELD = 7
59 UCAL_MILLISECOND
, // UDAT_FRACTIONAL_SECOND_FIELD = 8
60 UCAL_DAY_OF_WEEK
, // UDAT_DAY_OF_WEEK_FIELD = 9
61 UCAL_DAY_OF_YEAR
, // UDAT_DAY_OF_YEAR_FIELD = 10
62 UCAL_DAY_OF_WEEK_IN_MONTH
, // UDAT_DAY_OF_WEEK_IN_MONTH_FIELD = 11
63 UCAL_WEEK_OF_YEAR
, // UDAT_WEEK_OF_YEAR_FIELD = 12
64 UCAL_WEEK_OF_MONTH
, // UDAT_WEEK_OF_MONTH_FIELD = 13
65 UCAL_AM_PM
, // UDAT_AM_PM_FIELD = 14
66 UCAL_HOUR
, // UDAT_HOUR1_FIELD = 15
67 UCAL_HOUR
, // UDAT_HOUR0_FIELD = 16
68 UCAL_ZONE_OFFSET
, // UDAT_TIMEZONE_FIELD = 17
69 UCAL_YEAR_WOY
, // UDAT_YEAR_WOY_FIELD = 18
70 UCAL_DOW_LOCAL
, // UDAT_DOW_LOCAL_FIELD = 19
71 UCAL_EXTENDED_YEAR
, // UDAT_EXTENDED_YEAR_FIELD = 20
72 UCAL_JULIAN_DAY
, // UDAT_JULIAN_DAY_FIELD = 21
73 UCAL_MILLISECONDS_IN_DAY
, // UDAT_MILLISECONDS_IN_DAY_FIELD = 22
74 UCAL_ZONE_OFFSET
, // UDAT_TIMEZONE_RFC_FIELD = 23 (also UCAL_DST_OFFSET)
75 UCAL_ZONE_OFFSET
, // UDAT_TIMEZONE_GENERIC_FIELD = 24 (also UCAL_DST_OFFSET)
76 UCAL_DOW_LOCAL
, // UDAT_STANDALONE_DAY_FIELD = 25
77 UCAL_MONTH
, // UDAT_STANDALONE_MONTH_FIELD = 26
78 UCAL_MONTH
, // UDAT_QUARTER_FIELD = 27
79 UCAL_MONTH
, // UDAT_STANDALONE_QUARTER_FIELD = 28
80 UCAL_ZONE_OFFSET
, // UDAT_TIMEZONE_SPECIAL_FIELD = 29 (also UCAL_DST_OFFSET)
81 UCAL_YEAR
, // UDAT_YEAR_NAME_FIELD = 30
82 UCAL_ZONE_OFFSET
, // UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD = 31 (also UCAL_DST_OFFSET)
83 UCAL_ZONE_OFFSET
, // UDAT_TIMEZONE_ISO_FIELD = 32 (also UCAL_DST_OFFSET)
84 UCAL_ZONE_OFFSET
, // UDAT_TIMEZONE_ISO_LOCAL_FIELD = 33 (also UCAL_DST_OFFSET)
85 UCAL_EXTENDED_YEAR
, // UDAT_RELATED_YEAR_FIELD = 34 (not an exact match)
86 UCAL_FIELD_COUNT
, // UDAT_FIELD_COUNT = 35
87 // UCAL_IS_LEAP_MONTH is not the target of a mapping
90 U_CAPI UCalendarDateFields U_EXPORT2
91 udat_toCalendarDateField(UDateFormatField field
) {
92 return gDateFieldMapping
[field
];
95 /* For now- one opener. */
96 static UDateFormatOpener gOpener
= NULL
;
98 U_INTERNAL
void U_EXPORT2
99 udat_registerOpener(UDateFormatOpener opener
, UErrorCode
*status
)
101 if(U_FAILURE(*status
)) return;
106 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
111 U_INTERNAL UDateFormatOpener U_EXPORT2
112 udat_unregisterOpener(UDateFormatOpener opener
, UErrorCode
*status
)
114 if(U_FAILURE(*status
)) return NULL
;
115 UDateFormatOpener oldOpener
= NULL
;
117 if(gOpener
==NULL
|| gOpener
!=opener
) {
118 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
129 U_CAPI UDateFormat
* U_EXPORT2
130 udat_open(UDateFormatStyle timeStyle
,
131 UDateFormatStyle dateStyle
,
135 const UChar
*pattern
,
136 int32_t patternLength
,
140 if(U_FAILURE(*status
)) {
143 if(gOpener
!=NULL
) { // if it's registered
144 fmt
= (DateFormat
*) (*gOpener
)(timeStyle
,dateStyle
,locale
,tzID
,tzIDLength
,pattern
,patternLength
,status
);
146 return (UDateFormat
*)fmt
;
147 } // else fall through.
149 if(timeStyle
!= UDAT_PATTERN
) {
151 fmt
= DateFormat::createDateTimeInstance((DateFormat::EStyle
)dateStyle
,
152 (DateFormat::EStyle
)timeStyle
);
155 fmt
= DateFormat::createDateTimeInstance((DateFormat::EStyle
)dateStyle
,
156 (DateFormat::EStyle
)timeStyle
,
161 UnicodeString
pat((UBool
)(patternLength
== -1), pattern
, patternLength
);
164 fmt
= new SimpleDateFormat(pat
, *status
);
167 fmt
= new SimpleDateFormat(pat
, Locale(locale
), *status
);
172 *status
= U_MEMORY_ALLOCATION_ERROR
;
177 TimeZone
*zone
= TimeZone::createTimeZone(UnicodeString((UBool
)(tzIDLength
== -1), tzID
, tzIDLength
));
179 *status
= U_MEMORY_ALLOCATION_ERROR
;
183 fmt
->adoptTimeZone(zone
);
186 return (UDateFormat
*)fmt
;
190 U_CAPI
void U_EXPORT2
191 udat_close(UDateFormat
* format
)
193 delete (DateFormat
*)format
;
196 U_CAPI UDateFormat
* U_EXPORT2
197 udat_clone(const UDateFormat
*fmt
,
200 if(U_FAILURE(*status
)) return 0;
202 Format
*res
= ((DateFormat
*)fmt
)->clone();
205 *status
= U_MEMORY_ALLOCATION_ERROR
;
209 return (UDateFormat
*) res
;
212 U_CAPI
int32_t U_EXPORT2
213 udat_format( const UDateFormat
* format
,
216 int32_t resultLength
,
217 UFieldPosition
* position
,
220 if(U_FAILURE(*status
)) {
223 if (result
== NULL
? resultLength
!= 0 : resultLength
< 0) {
224 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
229 if (result
!= NULL
) {
230 // NULL destination for pure preflighting: empty dummy string
231 // otherwise, alias the destination buffer
232 res
.setTo(result
, 0, resultLength
);
238 fp
.setField(position
->field
);
240 ((DateFormat
*)format
)->format(dateToFormat
, res
, fp
);
243 position
->beginIndex
= fp
.getBeginIndex();
244 position
->endIndex
= fp
.getEndIndex();
247 return res
.extract(result
, resultLength
, *status
);
250 U_CAPI
int32_t U_EXPORT2
251 udat_formatCalendar(const UDateFormat
* format
,
254 int32_t resultLength
,
255 UFieldPosition
* position
,
258 if(U_FAILURE(*status
)) {
261 if (result
== NULL
? resultLength
!= 0 : resultLength
< 0) {
262 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
267 if (result
!= NULL
) {
268 // NULL destination for pure preflighting: empty dummy string
269 // otherwise, alias the destination buffer
270 res
.setTo(result
, 0, resultLength
);
276 fp
.setField(position
->field
);
278 ((DateFormat
*)format
)->format(*(Calendar
*)calendar
, res
, fp
);
281 position
->beginIndex
= fp
.getBeginIndex();
282 position
->endIndex
= fp
.getEndIndex();
285 return res
.extract(result
, resultLength
, *status
);
288 U_CAPI
int32_t U_EXPORT2
289 udat_formatForFields( const UDateFormat
* format
,
292 int32_t resultLength
,
293 UFieldPositionIterator
* fpositer
,
296 if(U_FAILURE(*status
)) {
299 if (result
== NULL
? resultLength
!= 0 : resultLength
< 0) {
300 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
305 if (result
!= NULL
) {
306 // NULL destination for pure preflighting: empty dummy string
307 // otherwise, alias the destination buffer
308 res
.setTo(result
, 0, resultLength
);
311 ((DateFormat
*)format
)->format(dateToFormat
, res
, (FieldPositionIterator
*)fpositer
, *status
);
313 return res
.extract(result
, resultLength
, *status
);
316 U_CAPI
int32_t U_EXPORT2
317 udat_formatCalendarForFields(const UDateFormat
* format
,
320 int32_t resultLength
,
321 UFieldPositionIterator
* fpositer
,
324 if(U_FAILURE(*status
)) {
327 if (result
== NULL
? resultLength
!= 0 : resultLength
< 0) {
328 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
333 if (result
!= NULL
) {
334 // NULL destination for pure preflighting: empty dummy string
335 // otherwise, alias the destination buffer
336 res
.setTo(result
, 0, resultLength
);
339 ((DateFormat
*)format
)->format(*(Calendar
*)calendar
, res
, (FieldPositionIterator
*)fpositer
, *status
);
341 return res
.extract(result
, resultLength
, *status
);
344 U_CAPI UDate U_EXPORT2
345 udat_parse( const UDateFormat
* format
,
351 if(U_FAILURE(*status
)) return (UDate
)0;
353 const UnicodeString
src((UBool
)(textLength
== -1), text
, textLength
);
355 int32_t stackParsePos
= 0;
358 if(parsePos
== NULL
) {
359 parsePos
= &stackParsePos
;
362 pp
.setIndex(*parsePos
);
364 res
= ((DateFormat
*)format
)->parse(src
, pp
);
366 if(pp
.getErrorIndex() == -1)
367 *parsePos
= pp
.getIndex();
369 *parsePos
= pp
.getErrorIndex();
370 *status
= U_PARSE_ERROR
;
376 U_CAPI
void U_EXPORT2
377 udat_parseCalendar(const UDateFormat
* format
,
384 if(U_FAILURE(*status
)) return;
386 const UnicodeString
src((UBool
)(textLength
== -1), text
, textLength
);
388 int32_t stackParsePos
= 0;
390 if(parsePos
== NULL
) {
391 parsePos
= &stackParsePos
;
394 pp
.setIndex(*parsePos
);
396 ((DateFormat
*)format
)->parse(src
, *(Calendar
*)calendar
, pp
);
398 if(pp
.getErrorIndex() == -1)
399 *parsePos
= pp
.getIndex();
401 *parsePos
= pp
.getErrorIndex();
402 *status
= U_PARSE_ERROR
;
406 U_CAPI UBool U_EXPORT2
407 udat_isLenient(const UDateFormat
* fmt
)
409 return ((DateFormat
*)fmt
)->isLenient();
412 U_CAPI
void U_EXPORT2
413 udat_setLenient( UDateFormat
* fmt
,
416 ((DateFormat
*)fmt
)->setLenient(isLenient
);
419 U_DRAFT UBool U_EXPORT2
420 udat_getBooleanAttribute(const UDateFormat
* fmt
,
421 UDateFormatBooleanAttribute attr
,
424 if(U_FAILURE(*status
)) return FALSE
;
425 return ((DateFormat
*)fmt
)->getBooleanAttribute(attr
, *status
);
429 U_DRAFT
void U_EXPORT2
430 udat_setBooleanAttribute(UDateFormat
*fmt
,
431 UDateFormatBooleanAttribute attr
,
435 if(U_FAILURE(*status
)) return;
436 ((DateFormat
*)fmt
)->setBooleanAttribute(attr
, newValue
, *status
);
439 U_CAPI
const UCalendar
* U_EXPORT2
440 udat_getCalendar(const UDateFormat
* fmt
)
442 return (const UCalendar
*) ((DateFormat
*)fmt
)->getCalendar();
445 U_CAPI
void U_EXPORT2
446 udat_setCalendar(UDateFormat
* fmt
,
447 const UCalendar
* calendarToSet
)
449 ((DateFormat
*)fmt
)->setCalendar(*((Calendar
*)calendarToSet
));
452 U_DRAFT
const UNumberFormat
* U_EXPORT2
453 udat_getNumberFormatForField(const UDateFormat
* fmt
, UChar field
)
455 UErrorCode status
= U_ZERO_ERROR
;
456 verifyIsSimpleDateFormat(fmt
, &status
);
457 if (U_FAILURE(status
)) return (const UNumberFormat
*) ((DateFormat
*)fmt
)->getNumberFormat();
458 return (const UNumberFormat
*) ((SimpleDateFormat
*)fmt
)->getNumberFormatForField(field
);
461 U_CAPI
const UNumberFormat
* U_EXPORT2
462 udat_getNumberFormat(const UDateFormat
* fmt
)
464 return (const UNumberFormat
*) ((DateFormat
*)fmt
)->getNumberFormat();
467 U_DRAFT
void U_EXPORT2
468 udat_adoptNumberFormatForFields( UDateFormat
* fmt
,
470 UNumberFormat
* numberFormatToSet
,
473 verifyIsSimpleDateFormat(fmt
, status
);
474 if (U_FAILURE(*status
)) return;
477 UnicodeString
overrideFields(fields
);
478 ((SimpleDateFormat
*)fmt
)->adoptNumberFormat(overrideFields
, (NumberFormat
*)numberFormatToSet
, *status
);
482 U_CAPI
void U_EXPORT2
483 udat_setNumberFormat(UDateFormat
* fmt
,
484 const UNumberFormat
* numberFormatToSet
)
486 ((DateFormat
*)fmt
)->setNumberFormat(*((NumberFormat
*)numberFormatToSet
));
489 U_DRAFT
void U_EXPORT2
490 udat_adoptNumberFormat( UDateFormat
* fmt
,
491 UNumberFormat
* numberFormatToAdopt
)
493 ((DateFormat
*)fmt
)->adoptNumberFormat((NumberFormat
*)numberFormatToAdopt
);
496 U_CAPI
const char* U_EXPORT2
497 udat_getAvailable(int32_t index
)
499 return uloc_getAvailable(index
);
502 U_CAPI
int32_t U_EXPORT2
503 udat_countAvailable()
505 return uloc_countAvailable();
508 U_CAPI UDate U_EXPORT2
509 udat_get2DigitYearStart( const UDateFormat
*fmt
,
512 verifyIsSimpleDateFormat(fmt
, status
);
513 if(U_FAILURE(*status
)) return (UDate
)0;
514 return ((SimpleDateFormat
*)fmt
)->get2DigitYearStart(*status
);
517 U_CAPI
void U_EXPORT2
518 udat_set2DigitYearStart( UDateFormat
*fmt
,
522 verifyIsSimpleDateFormat(fmt
, status
);
523 if(U_FAILURE(*status
)) return;
524 ((SimpleDateFormat
*)fmt
)->set2DigitYearStart(d
, *status
);
527 U_CAPI
int32_t U_EXPORT2
528 udat_toPattern( const UDateFormat
*fmt
,
531 int32_t resultLength
,
534 if(U_FAILURE(*status
)) {
537 if (result
== NULL
? resultLength
!= 0 : resultLength
< 0) {
538 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
543 if (result
!= NULL
) {
544 // NULL destination for pure preflighting: empty dummy string
545 // otherwise, alias the destination buffer
546 res
.setTo(result
, 0, resultLength
);
549 const DateFormat
*df
=reinterpret_cast<const DateFormat
*>(fmt
);
550 const SimpleDateFormat
*sdtfmt
=dynamic_cast<const SimpleDateFormat
*>(df
);
551 const RelativeDateFormat
*reldtfmt
;
554 sdtfmt
->toLocalizedPattern(res
, *status
);
556 sdtfmt
->toPattern(res
);
557 } else if (!localized
&& (reldtfmt
=dynamic_cast<const RelativeDateFormat
*>(df
))!=NULL
) {
558 reldtfmt
->toPattern(res
, *status
);
560 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
564 return res
.extract(result
, resultLength
, *status
);
567 // TODO: should this take an UErrorCode?
568 // A: Yes. Of course.
569 U_CAPI
void U_EXPORT2
570 udat_applyPattern( UDateFormat
*format
,
572 const UChar
*pattern
,
573 int32_t patternLength
)
575 const UnicodeString
pat((UBool
)(patternLength
== -1), pattern
, patternLength
);
576 UErrorCode status
= U_ZERO_ERROR
;
578 verifyIsSimpleDateFormat(format
, &status
);
579 if(U_FAILURE(status
)) {
584 ((SimpleDateFormat
*)format
)->applyLocalizedPattern(pat
, status
);
586 ((SimpleDateFormat
*)format
)->applyPattern(pat
);
590 static DateFormatSymbols::ECapitalizationContextUsageType
capUsageFromSymbolType(UDateFormatSymbolType type
)
592 DateFormatSymbols::ECapitalizationContextUsageType capContextUsageType
= DateFormatSymbols::kCapContextUsageOther
;
595 capContextUsageType
= DateFormatSymbols::kCapContextUsageEraWide
;
598 capContextUsageType
= DateFormatSymbols::kCapContextUsageEraAbbrev
;
601 case UDAT_SHORT_MONTHS
:
602 capContextUsageType
= DateFormatSymbols::kCapContextUsageMonthFormat
;
604 case UDAT_STANDALONE_MONTHS
:
605 case UDAT_STANDALONE_SHORT_MONTHS
:
606 capContextUsageType
= DateFormatSymbols::kCapContextUsageMonthStandalone
;
608 case UDAT_NARROW_MONTHS
:
609 case UDAT_STANDALONE_NARROW_MONTHS
:
610 capContextUsageType
= DateFormatSymbols::kCapContextUsageMonthNarrow
;
613 case UDAT_SHORT_WEEKDAYS
:
614 case UDAT_SHORTER_WEEKDAYS
:
615 capContextUsageType
= DateFormatSymbols::kCapContextUsageDayFormat
;
617 case UDAT_STANDALONE_WEEKDAYS
:
618 case UDAT_STANDALONE_SHORT_WEEKDAYS
:
619 case UDAT_STANDALONE_SHORTER_WEEKDAYS
:
620 capContextUsageType
= DateFormatSymbols::kCapContextUsageDayStandalone
;
622 case UDAT_STANDALONE_NARROW_WEEKDAYS
:
623 case UDAT_NARROW_WEEKDAYS
:
624 capContextUsageType
= DateFormatSymbols::kCapContextUsageDayNarrow
;
629 return capContextUsageType
;
634 U_CAPI
int32_t U_EXPORT2
635 udat_getSymbols(const UDateFormat
*fmt
,
636 UDateFormatSymbolType type
,
639 int32_t resultLength
,
642 const DateFormatSymbols
*syms
;
643 const SimpleDateFormat
* sdtfmt
;
644 const RelativeDateFormat
* rdtfmt
;
645 BreakIterator
* capitalizationBrkIter
;
646 if ((sdtfmt
= dynamic_cast<const SimpleDateFormat
*>(reinterpret_cast<const DateFormat
*>(fmt
))) != NULL
) {
647 syms
= sdtfmt
->getDateFormatSymbols();
648 capitalizationBrkIter
= sdtfmt
->getCapitalizationBrkIter();
649 } else if ((rdtfmt
= dynamic_cast<const RelativeDateFormat
*>(reinterpret_cast<const DateFormat
*>(fmt
))) != NULL
) {
650 syms
= rdtfmt
->getDateFormatSymbols();
651 capitalizationBrkIter
= rdtfmt
->getCapitalizationBrkIter();
656 const UnicodeString
*res
= NULL
;
660 res
= syms
->getEras(count
);
664 res
= syms
->getEraNames(count
);
668 res
= syms
->getMonths(count
);
671 case UDAT_SHORT_MONTHS
:
672 res
= syms
->getShortMonths(count
);
676 res
= syms
->getWeekdays(count
);
679 case UDAT_SHORT_WEEKDAYS
:
680 res
= syms
->getShortWeekdays(count
);
684 res
= syms
->getAmPmStrings(count
);
687 case UDAT_LOCALIZED_CHARS
:
690 if(!(result
==NULL
&& resultLength
==0)) {
691 // NULL destination for pure preflighting: empty dummy string
692 // otherwise, alias the destination buffer
693 res1
.setTo(result
, 0, resultLength
);
695 syms
->getLocalPatternChars(res1
);
696 return res1
.extract(result
, resultLength
, *status
);
699 case UDAT_NARROW_MONTHS
:
700 res
= syms
->getMonths(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
703 case UDAT_SHORTER_WEEKDAYS
:
704 res
= syms
->getWeekdays(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::SHORT
);
707 case UDAT_NARROW_WEEKDAYS
:
708 res
= syms
->getWeekdays(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
711 case UDAT_STANDALONE_MONTHS
:
712 res
= syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
715 case UDAT_STANDALONE_SHORT_MONTHS
:
716 res
= syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
719 case UDAT_STANDALONE_NARROW_MONTHS
:
720 res
= syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::NARROW
);
723 case UDAT_STANDALONE_WEEKDAYS
:
724 res
= syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
727 case UDAT_STANDALONE_SHORT_WEEKDAYS
:
728 res
= syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
731 case UDAT_STANDALONE_SHORTER_WEEKDAYS
:
732 res
= syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::SHORT
);
735 case UDAT_STANDALONE_NARROW_WEEKDAYS
:
736 res
= syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::NARROW
);
740 res
= syms
->getQuarters(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
743 case UDAT_SHORT_QUARTERS
:
744 res
= syms
->getQuarters(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
747 case UDAT_STANDALONE_QUARTERS
:
748 res
= syms
->getQuarters(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
751 case UDAT_STANDALONE_SHORT_QUARTERS
:
752 res
= syms
->getQuarters(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
755 case UDAT_CYCLIC_YEARS_WIDE
:
756 res
= syms
->getYearNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
759 case UDAT_CYCLIC_YEARS_ABBREVIATED
:
760 res
= syms
->getYearNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
763 case UDAT_CYCLIC_YEARS_NARROW
:
764 res
= syms
->getYearNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
767 case UDAT_ZODIAC_NAMES_WIDE
:
768 res
= syms
->getZodiacNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
771 case UDAT_ZODIAC_NAMES_ABBREVIATED
:
772 res
= syms
->getZodiacNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
775 case UDAT_ZODIAC_NAMES_NARROW
:
776 res
= syms
->getZodiacNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
779 case UADAT_CYCLIC_ZODIAC_NAMES
:
780 res
= syms
->getZodiacNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
781 index
= (index
> 0)? (index
- 1) % 12: 0;
787 #if !UCONFIG_NO_BREAK_ITERATION
788 // Apple addition for <rdar://problem/27335144>
789 if (u_islower(res
[index
].char32At(0)) && capitalizationBrkIter
!= NULL
) {
790 UDisplayContext capitalizationContext
= ((const DateFormat
*)fmt
)->getContext(UDISPCTX_TYPE_CAPITALIZATION
, *status
);
791 UBool titlecase
= FALSE
;
792 switch (capitalizationContext
) {
793 case UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE
:
796 case UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU
:
797 titlecase
= syms
->capitalizeForUsage(capUsageFromSymbolType(type
), 0);
799 case UDISPCTX_CAPITALIZATION_FOR_STANDALONE
:
800 titlecase
= syms
->capitalizeForUsage(capUsageFromSymbolType(type
), 1);
803 // titlecase = FALSE;
807 UnicodeString
symbolToModify(res
[index
]);
808 BreakIterator
* capBrkIterToUse
= capitalizationBrkIter
->clone();
809 if (capBrkIterToUse
!= NULL
) {
810 Locale locale
= capBrkIterToUse
->getLocale(ULOC_ACTUAL_LOCALE
, *status
);
811 if (U_SUCCESS(*status
)) {
812 symbolToModify
.toTitle(capBrkIterToUse
, locale
, U_TITLECASE_NO_LOWERCASE
| U_TITLECASE_NO_BREAK_ADJUSTMENT
);
813 delete capBrkIterToUse
;
814 return symbolToModify
.extract(result
, resultLength
, *status
);
816 delete capBrkIterToUse
;
821 return res
[index
].extract(result
, resultLength
, *status
);
826 // TODO: also needs an errorCode.
827 U_CAPI
int32_t U_EXPORT2
828 udat_countSymbols( const UDateFormat
*fmt
,
829 UDateFormatSymbolType type
)
831 const DateFormatSymbols
*syms
;
832 const SimpleDateFormat
* sdtfmt
;
833 const RelativeDateFormat
* rdtfmt
;
834 if ((sdtfmt
= dynamic_cast<const SimpleDateFormat
*>(reinterpret_cast<const DateFormat
*>(fmt
))) != NULL
) {
835 syms
= sdtfmt
->getDateFormatSymbols();
836 } else if ((rdtfmt
= dynamic_cast<const RelativeDateFormat
*>(reinterpret_cast<const DateFormat
*>(fmt
))) != NULL
) {
837 syms
= rdtfmt
->getDateFormatSymbols();
845 syms
->getEras(count
);
849 syms
->getMonths(count
);
852 case UDAT_SHORT_MONTHS
:
853 syms
->getShortMonths(count
);
857 syms
->getWeekdays(count
);
860 case UDAT_SHORT_WEEKDAYS
:
861 syms
->getShortWeekdays(count
);
865 syms
->getAmPmStrings(count
);
868 case UDAT_LOCALIZED_CHARS
:
873 syms
->getEraNames(count
);
876 case UDAT_NARROW_MONTHS
:
877 syms
->getMonths(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
880 case UDAT_SHORTER_WEEKDAYS
:
881 syms
->getWeekdays(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::SHORT
);
884 case UDAT_NARROW_WEEKDAYS
:
885 syms
->getWeekdays(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
888 case UDAT_STANDALONE_MONTHS
:
889 syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
892 case UDAT_STANDALONE_SHORT_MONTHS
:
893 syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
896 case UDAT_STANDALONE_NARROW_MONTHS
:
897 syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::NARROW
);
900 case UDAT_STANDALONE_WEEKDAYS
:
901 syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
904 case UDAT_STANDALONE_SHORT_WEEKDAYS
:
905 syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
908 case UDAT_STANDALONE_SHORTER_WEEKDAYS
:
909 syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::SHORT
);
912 case UDAT_STANDALONE_NARROW_WEEKDAYS
:
913 syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::NARROW
);
917 syms
->getQuarters(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
920 case UDAT_SHORT_QUARTERS
:
921 syms
->getQuarters(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
924 case UDAT_STANDALONE_QUARTERS
:
925 syms
->getQuarters(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
928 case UDAT_STANDALONE_SHORT_QUARTERS
:
929 syms
->getQuarters(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
932 case UDAT_CYCLIC_YEARS_WIDE
:
933 syms
->getYearNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
936 case UDAT_CYCLIC_YEARS_ABBREVIATED
:
937 syms
->getYearNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
940 case UDAT_CYCLIC_YEARS_NARROW
:
941 syms
->getYearNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
944 case UDAT_ZODIAC_NAMES_WIDE
:
945 syms
->getZodiacNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
948 case UDAT_ZODIAC_NAMES_ABBREVIATED
:
949 syms
->getZodiacNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
952 case UDAT_ZODIAC_NAMES_NARROW
:
953 syms
->getZodiacNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
956 case UADAT_CYCLIC_ZODIAC_NAMES
:
957 syms
->getZodiacNames(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
968 * This DateFormatSymbolsSingleSetter class is a friend of DateFormatSymbols
969 * solely for the purpose of avoiding to clone the array of strings
970 * just to modify one of them and then setting all of them back.
971 * For example, the old code looked like this:
973 * res = syms->getMonths(count);
974 * array = new UnicodeString[count];
976 * *status = U_MEMORY_ALLOCATION_ERROR;
979 * uprv_arrayCopy(res, array, count);
981 * array[index] = val;
982 * syms->setMonths(array, count);
985 * Even worse, the old code actually cloned the entire DateFormatSymbols object,
986 * cloned one value array, changed one value, and then made the SimpleDateFormat
987 * replace its DateFormatSymbols object with the new one.
991 class DateFormatSymbolsSingleSetter
/* not : public UObject because all methods are static */ {
994 setSymbol(UnicodeString
*array
, int32_t count
, int32_t index
,
995 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
999 errorCode
=U_INDEX_OUTOFBOUNDS_ERROR
;
1000 } else if(value
==NULL
) {
1001 errorCode
=U_ILLEGAL_ARGUMENT_ERROR
;
1003 array
[index
].setTo(value
, valueLength
);
1009 setEra(DateFormatSymbols
*syms
, int32_t index
,
1010 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1012 setSymbol(syms
->fEras
, syms
->fErasCount
, index
, value
, valueLength
, errorCode
);
1016 setEraName(DateFormatSymbols
*syms
, int32_t index
,
1017 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1019 setSymbol(syms
->fEraNames
, syms
->fEraNamesCount
, index
, value
, valueLength
, errorCode
);
1023 setMonth(DateFormatSymbols
*syms
, int32_t index
,
1024 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1026 setSymbol(syms
->fMonths
, syms
->fMonthsCount
, index
, value
, valueLength
, errorCode
);
1030 setShortMonth(DateFormatSymbols
*syms
, int32_t index
,
1031 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1033 setSymbol(syms
->fShortMonths
, syms
->fShortMonthsCount
, index
, value
, valueLength
, errorCode
);
1037 setNarrowMonth(DateFormatSymbols
*syms
, int32_t index
,
1038 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1040 setSymbol(syms
->fNarrowMonths
, syms
->fNarrowMonthsCount
, index
, value
, valueLength
, errorCode
);
1044 setStandaloneMonth(DateFormatSymbols
*syms
, int32_t index
,
1045 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1047 setSymbol(syms
->fStandaloneMonths
, syms
->fStandaloneMonthsCount
, index
, value
, valueLength
, errorCode
);
1051 setStandaloneShortMonth(DateFormatSymbols
*syms
, int32_t index
,
1052 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1054 setSymbol(syms
->fStandaloneShortMonths
, syms
->fStandaloneShortMonthsCount
, index
, value
, valueLength
, errorCode
);
1058 setStandaloneNarrowMonth(DateFormatSymbols
*syms
, int32_t index
,
1059 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1061 setSymbol(syms
->fStandaloneNarrowMonths
, syms
->fStandaloneNarrowMonthsCount
, index
, value
, valueLength
, errorCode
);
1065 setWeekday(DateFormatSymbols
*syms
, int32_t index
,
1066 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1068 setSymbol(syms
->fWeekdays
, syms
->fWeekdaysCount
, index
, value
, valueLength
, errorCode
);
1072 setShortWeekday(DateFormatSymbols
*syms
, int32_t index
,
1073 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1075 setSymbol(syms
->fShortWeekdays
, syms
->fShortWeekdaysCount
, index
, value
, valueLength
, errorCode
);
1079 setShorterWeekday(DateFormatSymbols
*syms
, int32_t index
,
1080 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1082 setSymbol(syms
->fShorterWeekdays
, syms
->fShorterWeekdaysCount
, index
, value
, valueLength
, errorCode
);
1086 setNarrowWeekday(DateFormatSymbols
*syms
, int32_t index
,
1087 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1089 setSymbol(syms
->fNarrowWeekdays
, syms
->fNarrowWeekdaysCount
, index
, value
, valueLength
, errorCode
);
1093 setStandaloneWeekday(DateFormatSymbols
*syms
, int32_t index
,
1094 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1096 setSymbol(syms
->fStandaloneWeekdays
, syms
->fStandaloneWeekdaysCount
, index
, value
, valueLength
, errorCode
);
1100 setStandaloneShortWeekday(DateFormatSymbols
*syms
, int32_t index
,
1101 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1103 setSymbol(syms
->fStandaloneShortWeekdays
, syms
->fStandaloneShortWeekdaysCount
, index
, value
, valueLength
, errorCode
);
1107 setStandaloneShorterWeekday(DateFormatSymbols
*syms
, int32_t index
,
1108 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1110 setSymbol(syms
->fStandaloneShorterWeekdays
, syms
->fStandaloneShorterWeekdaysCount
, index
, value
, valueLength
, errorCode
);
1114 setStandaloneNarrowWeekday(DateFormatSymbols
*syms
, int32_t index
,
1115 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1117 setSymbol(syms
->fStandaloneNarrowWeekdays
, syms
->fStandaloneNarrowWeekdaysCount
, index
, value
, valueLength
, errorCode
);
1121 setQuarter(DateFormatSymbols
*syms
, int32_t index
,
1122 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1124 setSymbol(syms
->fQuarters
, syms
->fQuartersCount
, index
, value
, valueLength
, errorCode
);
1128 setShortQuarter(DateFormatSymbols
*syms
, int32_t index
,
1129 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1131 setSymbol(syms
->fShortQuarters
, syms
->fShortQuartersCount
, index
, value
, valueLength
, errorCode
);
1135 setStandaloneQuarter(DateFormatSymbols
*syms
, int32_t index
,
1136 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1138 setSymbol(syms
->fStandaloneQuarters
, syms
->fStandaloneQuartersCount
, index
, value
, valueLength
, errorCode
);
1142 setStandaloneShortQuarter(DateFormatSymbols
*syms
, int32_t index
,
1143 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1145 setSymbol(syms
->fStandaloneShortQuarters
, syms
->fStandaloneShortQuartersCount
, index
, value
, valueLength
, errorCode
);
1149 setShortYearNames(DateFormatSymbols
*syms
, int32_t index
,
1150 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1152 setSymbol(syms
->fShortYearNames
, syms
->fShortYearNamesCount
, index
, value
, valueLength
, errorCode
);
1156 setShortZodiacNames(DateFormatSymbols
*syms
, int32_t index
,
1157 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1159 setSymbol(syms
->fShortZodiacNames
, syms
->fShortZodiacNamesCount
, index
, value
, valueLength
, errorCode
);
1163 setAmPm(DateFormatSymbols
*syms
, int32_t index
,
1164 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1166 setSymbol(syms
->fAmPms
, syms
->fAmPmsCount
, index
, value
, valueLength
, errorCode
);
1170 setLocalPatternChars(DateFormatSymbols
*syms
,
1171 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
1173 setSymbol(&syms
->fLocalPatternChars
, 1, 0, value
, valueLength
, errorCode
);
1179 U_CAPI
void U_EXPORT2
1180 udat_setSymbols( UDateFormat
*format
,
1181 UDateFormatSymbolType type
,
1184 int32_t valueLength
,
1187 verifyIsSimpleDateFormat(format
, status
);
1188 if(U_FAILURE(*status
)) return;
1190 DateFormatSymbols
*syms
= (DateFormatSymbols
*)((SimpleDateFormat
*)format
)->getDateFormatSymbols();
1194 DateFormatSymbolsSingleSetter::setEra(syms
, index
, value
, valueLength
, *status
);
1197 case UDAT_ERA_NAMES
:
1198 DateFormatSymbolsSingleSetter::setEraName(syms
, index
, value
, valueLength
, *status
);
1202 DateFormatSymbolsSingleSetter::setMonth(syms
, index
, value
, valueLength
, *status
);
1205 case UDAT_SHORT_MONTHS
:
1206 DateFormatSymbolsSingleSetter::setShortMonth(syms
, index
, value
, valueLength
, *status
);
1209 case UDAT_NARROW_MONTHS
:
1210 DateFormatSymbolsSingleSetter::setNarrowMonth(syms
, index
, value
, valueLength
, *status
);
1213 case UDAT_STANDALONE_MONTHS
:
1214 DateFormatSymbolsSingleSetter::setStandaloneMonth(syms
, index
, value
, valueLength
, *status
);
1217 case UDAT_STANDALONE_SHORT_MONTHS
:
1218 DateFormatSymbolsSingleSetter::setStandaloneShortMonth(syms
, index
, value
, valueLength
, *status
);
1221 case UDAT_STANDALONE_NARROW_MONTHS
:
1222 DateFormatSymbolsSingleSetter::setStandaloneNarrowMonth(syms
, index
, value
, valueLength
, *status
);
1226 DateFormatSymbolsSingleSetter::setWeekday(syms
, index
, value
, valueLength
, *status
);
1229 case UDAT_SHORT_WEEKDAYS
:
1230 DateFormatSymbolsSingleSetter::setShortWeekday(syms
, index
, value
, valueLength
, *status
);
1233 case UDAT_SHORTER_WEEKDAYS
:
1234 DateFormatSymbolsSingleSetter::setShorterWeekday(syms
, index
, value
, valueLength
, *status
);
1237 case UDAT_NARROW_WEEKDAYS
:
1238 DateFormatSymbolsSingleSetter::setNarrowWeekday(syms
, index
, value
, valueLength
, *status
);
1241 case UDAT_STANDALONE_WEEKDAYS
:
1242 DateFormatSymbolsSingleSetter::setStandaloneWeekday(syms
, index
, value
, valueLength
, *status
);
1245 case UDAT_STANDALONE_SHORT_WEEKDAYS
:
1246 DateFormatSymbolsSingleSetter::setStandaloneShortWeekday(syms
, index
, value
, valueLength
, *status
);
1249 case UDAT_STANDALONE_SHORTER_WEEKDAYS
:
1250 DateFormatSymbolsSingleSetter::setStandaloneShorterWeekday(syms
, index
, value
, valueLength
, *status
);
1253 case UDAT_STANDALONE_NARROW_WEEKDAYS
:
1254 DateFormatSymbolsSingleSetter::setStandaloneNarrowWeekday(syms
, index
, value
, valueLength
, *status
);
1258 DateFormatSymbolsSingleSetter::setQuarter(syms
, index
, value
, valueLength
, *status
);
1261 case UDAT_SHORT_QUARTERS
:
1262 DateFormatSymbolsSingleSetter::setShortQuarter(syms
, index
, value
, valueLength
, *status
);
1265 case UDAT_STANDALONE_QUARTERS
:
1266 DateFormatSymbolsSingleSetter::setStandaloneQuarter(syms
, index
, value
, valueLength
, *status
);
1269 case UDAT_STANDALONE_SHORT_QUARTERS
:
1270 DateFormatSymbolsSingleSetter::setStandaloneShortQuarter(syms
, index
, value
, valueLength
, *status
);
1273 case UDAT_CYCLIC_YEARS_ABBREVIATED
:
1274 DateFormatSymbolsSingleSetter::setShortYearNames(syms
, index
, value
, valueLength
, *status
);
1277 case UDAT_ZODIAC_NAMES_ABBREVIATED
:
1278 DateFormatSymbolsSingleSetter::setShortZodiacNames(syms
, index
, value
, valueLength
, *status
);
1282 DateFormatSymbolsSingleSetter::setAmPm(syms
, index
, value
, valueLength
, *status
);
1285 case UDAT_LOCALIZED_CHARS
:
1286 DateFormatSymbolsSingleSetter::setLocalPatternChars(syms
, value
, valueLength
, *status
);
1290 *status
= U_UNSUPPORTED_ERROR
;
1296 U_CAPI
const char* U_EXPORT2
1297 udat_getLocaleByType(const UDateFormat
*fmt
,
1298 ULocDataLocaleType type
,
1302 if (U_SUCCESS(*status
)) {
1303 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
1307 return ((Format
*)fmt
)->getLocaleID(type
, *status
);
1310 U_CAPI
void U_EXPORT2
1311 udat_setContext(UDateFormat
* fmt
, UDisplayContext value
, UErrorCode
* status
)
1313 if (U_FAILURE(*status
)) {
1316 ((DateFormat
*)fmt
)->setContext(value
, *status
);
1320 U_CAPI UDisplayContext U_EXPORT2
1321 udat_getContext(const UDateFormat
* fmt
, UDisplayContextType type
, UErrorCode
* status
)
1323 if (U_FAILURE(*status
)) {
1324 return (UDisplayContext
)0;
1326 return ((const DateFormat
*)fmt
)->getContext(type
, *status
);
1331 * Verify that fmt is a RelativeDateFormat. Invalid error if not.
1332 * @param fmt the UDateFormat, definitely a DateFormat, maybe something else
1333 * @param status error code, will be set to failure if there is a familure or the fmt is NULL.
1335 static void verifyIsRelativeDateFormat(const UDateFormat
* fmt
, UErrorCode
*status
) {
1336 if(U_SUCCESS(*status
) &&
1337 dynamic_cast<const RelativeDateFormat
*>(reinterpret_cast<const DateFormat
*>(fmt
))==NULL
) {
1338 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
1343 U_CAPI
int32_t U_EXPORT2
1344 udat_toPatternRelativeDate(const UDateFormat
*fmt
,
1346 int32_t resultLength
,
1349 verifyIsRelativeDateFormat(fmt
, status
);
1350 if(U_FAILURE(*status
)) {
1353 if (result
== NULL
? resultLength
!= 0 : resultLength
< 0) {
1354 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
1358 UnicodeString datePattern
;
1359 if (result
!= NULL
) {
1360 // NULL destination for pure preflighting: empty dummy string
1361 // otherwise, alias the destination buffer
1362 datePattern
.setTo(result
, 0, resultLength
);
1364 ((RelativeDateFormat
*)fmt
)->toPatternDate(datePattern
, *status
);
1365 return datePattern
.extract(result
, resultLength
, *status
);
1368 U_CAPI
int32_t U_EXPORT2
1369 udat_toPatternRelativeTime(const UDateFormat
*fmt
,
1371 int32_t resultLength
,
1374 verifyIsRelativeDateFormat(fmt
, status
);
1375 if(U_FAILURE(*status
)) {
1378 if (result
== NULL
? resultLength
!= 0 : resultLength
< 0) {
1379 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
1383 UnicodeString timePattern
;
1384 if (result
!= NULL
) {
1385 // NULL destination for pure preflighting: empty dummy string
1386 // otherwise, alias the destination buffer
1387 timePattern
.setTo(result
, 0, resultLength
);
1389 ((RelativeDateFormat
*)fmt
)->toPatternTime(timePattern
, *status
);
1390 return timePattern
.extract(result
, resultLength
, *status
);
1393 U_CAPI
void U_EXPORT2
1394 udat_applyPatternRelative(UDateFormat
*format
,
1395 const UChar
*datePattern
,
1396 int32_t datePatternLength
,
1397 const UChar
*timePattern
,
1398 int32_t timePatternLength
,
1401 verifyIsRelativeDateFormat(format
, status
);
1402 if(U_FAILURE(*status
)) return;
1403 const UnicodeString
datePat((UBool
)(datePatternLength
== -1), datePattern
, datePatternLength
);
1404 const UnicodeString
timePat((UBool
)(timePatternLength
== -1), timePattern
, timePatternLength
);
1405 ((RelativeDateFormat
*)format
)->applyPatterns(datePat
, timePat
, *status
);
1408 #endif /* #if !UCONFIG_NO_FORMATTING */