2 *******************************************************************************
3 * Copyright (C) 1996-2009, 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"
30 * Verify that fmt is a SimpleDateFormat. Invalid error if not.
31 * @param fmt the UDateFormat, definitely a DateFormat, maybe something else
32 * @param status error code, will be set to failure if there is a familure or the fmt is NULL.
34 static void verifyIsSimpleDateFormat(const UDateFormat
* fmt
, UErrorCode
*status
) {
35 if(!U_FAILURE(*status
) &&
36 ((DateFormat
*)fmt
)->getDynamicClassID()!=SimpleDateFormat::getStaticClassID()) {
37 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
41 U_CAPI UDateFormat
* U_EXPORT2
42 udat_open(UDateFormatStyle timeStyle
,
43 UDateFormatStyle dateStyle
,
48 int32_t patternLength
,
52 if(U_FAILURE(*status
)) {
55 if(timeStyle
!= UDAT_IGNORE
) {
57 fmt
= DateFormat::createDateTimeInstance((DateFormat::EStyle
)dateStyle
,
58 (DateFormat::EStyle
)timeStyle
);
61 fmt
= DateFormat::createDateTimeInstance((DateFormat::EStyle
)dateStyle
,
62 (DateFormat::EStyle
)timeStyle
,
67 UnicodeString
pat((UBool
)(patternLength
== -1), pattern
, patternLength
);
70 fmt
= new SimpleDateFormat(pat
, *status
);
73 fmt
= new SimpleDateFormat(pat
, Locale(locale
), *status
);
78 *status
= U_MEMORY_ALLOCATION_ERROR
;
83 TimeZone
*zone
= TimeZone::createTimeZone(UnicodeString((UBool
)(tzIDLength
== -1), tzID
, tzIDLength
));
85 *status
= U_MEMORY_ALLOCATION_ERROR
;
89 fmt
->adoptTimeZone(zone
);
92 return (UDateFormat
*)fmt
;
97 udat_close(UDateFormat
* format
)
99 delete (DateFormat
*)format
;
102 U_CAPI UDateFormat
* U_EXPORT2
103 udat_clone(const UDateFormat
*fmt
,
106 if(U_FAILURE(*status
)) return 0;
108 /* clone is defined for DateFormat and implemented for all subclasses */
109 Format
*res
= ((DateFormat
*)fmt
)->clone();
112 *status
= U_MEMORY_ALLOCATION_ERROR
;
116 return (UDateFormat
*) res
;
119 U_CAPI
int32_t U_EXPORT2
120 udat_format( const UDateFormat
* format
,
123 int32_t resultLength
,
124 UFieldPosition
* position
,
127 if(U_FAILURE(*status
)) return -1;
130 if(!(result
==NULL
&& resultLength
==0)) {
131 // NULL destination for pure preflighting: empty dummy string
132 // otherwise, alias the destination buffer
133 res
.setTo(result
, 0, resultLength
);
139 fp
.setField(position
->field
);
141 ((DateFormat
*)format
)->format(dateToFormat
, res
, fp
);
144 position
->beginIndex
= fp
.getBeginIndex();
145 position
->endIndex
= fp
.getEndIndex();
148 return res
.extract(result
, resultLength
, *status
);
151 U_CAPI UDate U_EXPORT2
152 udat_parse( const UDateFormat
* format
,
158 if(U_FAILURE(*status
)) return (UDate
)0;
160 const UnicodeString
src((UBool
)(textLength
== -1), text
, textLength
);
162 int32_t stackParsePos
= 0;
165 if(parsePos
== NULL
) {
166 parsePos
= &stackParsePos
;
169 pp
.setIndex(*parsePos
);
171 res
= ((DateFormat
*)format
)->parse(src
, pp
);
173 if(pp
.getErrorIndex() == -1)
174 *parsePos
= pp
.getIndex();
176 *parsePos
= pp
.getErrorIndex();
177 *status
= U_PARSE_ERROR
;
183 U_CAPI
void U_EXPORT2
184 udat_parseCalendar(const UDateFormat
* format
,
191 if(U_FAILURE(*status
)) return;
193 const UnicodeString
src((UBool
)(textLength
== -1), text
, textLength
);
197 pp
.setIndex(*parsePos
);
199 ((DateFormat
*)format
)->parse(src
, *(Calendar
*)calendar
, pp
);
202 if(pp
.getErrorIndex() == -1)
203 *parsePos
= pp
.getIndex();
205 *parsePos
= pp
.getErrorIndex();
206 *status
= U_PARSE_ERROR
;
211 U_CAPI UBool U_EXPORT2
212 udat_isLenient(const UDateFormat
* fmt
)
214 return ((DateFormat
*)fmt
)->isLenient();
217 U_CAPI
void U_EXPORT2
218 udat_setLenient( UDateFormat
* fmt
,
221 ((DateFormat
*)fmt
)->setLenient(isLenient
);
224 U_CAPI
const UCalendar
* U_EXPORT2
225 udat_getCalendar(const UDateFormat
* fmt
)
227 return (const UCalendar
*) ((DateFormat
*)fmt
)->getCalendar();
230 U_CAPI
void U_EXPORT2
231 udat_setCalendar(UDateFormat
* fmt
,
232 const UCalendar
* calendarToSet
)
234 ((DateFormat
*)fmt
)->setCalendar(*((Calendar
*)calendarToSet
));
237 U_CAPI
const UNumberFormat
* U_EXPORT2
238 udat_getNumberFormat(const UDateFormat
* fmt
)
240 return (const UNumberFormat
*) ((DateFormat
*)fmt
)->getNumberFormat();
243 U_CAPI
void U_EXPORT2
244 udat_setNumberFormat(UDateFormat
* fmt
,
245 const UNumberFormat
* numberFormatToSet
)
247 ((DateFormat
*)fmt
)->setNumberFormat(*((NumberFormat
*)numberFormatToSet
));
250 U_CAPI
const char* U_EXPORT2
251 udat_getAvailable(int32_t index
)
253 return uloc_getAvailable(index
);
256 U_CAPI
int32_t U_EXPORT2
257 udat_countAvailable()
259 return uloc_countAvailable();
262 U_CAPI UDate U_EXPORT2
263 udat_get2DigitYearStart( const UDateFormat
*fmt
,
266 verifyIsSimpleDateFormat(fmt
, status
);
267 if(U_FAILURE(*status
)) return (UDate
)0;
268 return ((SimpleDateFormat
*)fmt
)->get2DigitYearStart(*status
);
271 U_CAPI
void U_EXPORT2
272 udat_set2DigitYearStart( UDateFormat
*fmt
,
276 verifyIsSimpleDateFormat(fmt
, status
);
277 if(U_FAILURE(*status
)) return;
278 ((SimpleDateFormat
*)fmt
)->set2DigitYearStart(d
, *status
);
281 U_CAPI
int32_t U_EXPORT2
282 udat_toPattern( const UDateFormat
*fmt
,
285 int32_t resultLength
,
288 if(U_FAILURE(*status
)) return -1;
291 if(!(result
==NULL
&& resultLength
==0)) {
292 // NULL destination for pure preflighting: empty dummy string
293 // otherwise, alias the destination buffer
294 res
.setTo(result
, 0, resultLength
);
297 if ( ((DateFormat
*)fmt
)->getDynamicClassID()==SimpleDateFormat::getStaticClassID() ) {
299 ((SimpleDateFormat
*)fmt
)->toLocalizedPattern(res
, *status
);
301 ((SimpleDateFormat
*)fmt
)->toPattern(res
);
302 } else if ( !localized
&& ((DateFormat
*)fmt
)->getDynamicClassID()==RelativeDateFormat::getStaticClassID() ) {
303 ((RelativeDateFormat
*)fmt
)->toPattern(res
, *status
);
305 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
309 return res
.extract(result
, resultLength
, *status
);
312 // TBD: should this take an UErrorCode?
313 U_CAPI
void U_EXPORT2
314 udat_applyPattern( UDateFormat
*format
,
316 const UChar
*pattern
,
317 int32_t patternLength
)
319 UErrorCode status
= U_ZERO_ERROR
;
320 verifyIsSimpleDateFormat(format
, &status
);
321 if(U_FAILURE(status
)) {
324 const UnicodeString
pat((UBool
)(patternLength
== -1), pattern
, patternLength
);
327 ((SimpleDateFormat
*)format
)->applyLocalizedPattern(pat
, status
);
329 ((SimpleDateFormat
*)format
)->applyPattern(pat
);
332 U_CAPI
int32_t U_EXPORT2
333 udat_getSymbols(const UDateFormat
*fmt
,
334 UDateFormatSymbolType type
,
337 int32_t resultLength
,
340 verifyIsSimpleDateFormat(fmt
, status
);
341 if(U_FAILURE(*status
)) return -1;
343 const DateFormatSymbols
*syms
=
344 ((SimpleDateFormat
*)fmt
)->getDateFormatSymbols();
346 const UnicodeString
*res
= NULL
;
350 res
= syms
->getEras(count
);
354 res
= syms
->getEraNames(count
);
358 res
= syms
->getMonths(count
);
361 case UDAT_SHORT_MONTHS
:
362 res
= syms
->getShortMonths(count
);
366 res
= syms
->getWeekdays(count
);
369 case UDAT_SHORT_WEEKDAYS
:
370 res
= syms
->getShortWeekdays(count
);
374 res
= syms
->getAmPmStrings(count
);
377 case UDAT_LOCALIZED_CHARS
:
380 if(!(result
==NULL
&& resultLength
==0)) {
381 // NULL destination for pure preflighting: empty dummy string
382 // otherwise, alias the destination buffer
383 res1
.setTo(result
, 0, resultLength
);
385 syms
->getLocalPatternChars(res1
);
386 return res1
.extract(result
, resultLength
, *status
);
389 case UDAT_NARROW_MONTHS
:
390 res
= syms
->getMonths(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
393 case UDAT_NARROW_WEEKDAYS
:
394 res
= syms
->getWeekdays(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
397 case UDAT_STANDALONE_MONTHS
:
398 res
= syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
401 case UDAT_STANDALONE_SHORT_MONTHS
:
402 res
= syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
405 case UDAT_STANDALONE_NARROW_MONTHS
:
406 res
= syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::NARROW
);
409 case UDAT_STANDALONE_WEEKDAYS
:
410 res
= syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
413 case UDAT_STANDALONE_SHORT_WEEKDAYS
:
414 res
= syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
417 case UDAT_STANDALONE_NARROW_WEEKDAYS
:
418 res
= syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::NARROW
);
422 res
= syms
->getQuarters(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
425 case UDAT_SHORT_QUARTERS
:
426 res
= syms
->getQuarters(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
429 case UDAT_STANDALONE_QUARTERS
:
430 res
= syms
->getQuarters(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
433 case UDAT_STANDALONE_SHORT_QUARTERS
:
434 res
= syms
->getQuarters(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
440 return res
[index
].extract(result
, resultLength
, *status
);
445 U_CAPI
int32_t U_EXPORT2
446 udat_countSymbols( const UDateFormat
*fmt
,
447 UDateFormatSymbolType type
)
449 UErrorCode status
= U_ZERO_ERROR
;
450 verifyIsSimpleDateFormat(fmt
, &status
);
451 if(U_FAILURE(status
)) {
455 const DateFormatSymbols
*syms
=
456 ((SimpleDateFormat
*)fmt
)->getDateFormatSymbols();
461 syms
->getEras(count
);
465 syms
->getMonths(count
);
468 case UDAT_SHORT_MONTHS
:
469 syms
->getShortMonths(count
);
473 syms
->getWeekdays(count
);
476 case UDAT_SHORT_WEEKDAYS
:
477 syms
->getShortWeekdays(count
);
481 syms
->getAmPmStrings(count
);
484 case UDAT_LOCALIZED_CHARS
:
489 syms
->getEraNames(count
);
492 case UDAT_NARROW_MONTHS
:
493 syms
->getMonths(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
496 case UDAT_NARROW_WEEKDAYS
:
497 syms
->getWeekdays(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::NARROW
);
500 case UDAT_STANDALONE_MONTHS
:
501 syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
504 case UDAT_STANDALONE_SHORT_MONTHS
:
505 syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
508 case UDAT_STANDALONE_NARROW_MONTHS
:
509 syms
->getMonths(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::NARROW
);
512 case UDAT_STANDALONE_WEEKDAYS
:
513 syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
516 case UDAT_STANDALONE_SHORT_WEEKDAYS
:
517 syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
520 case UDAT_STANDALONE_NARROW_WEEKDAYS
:
521 syms
->getWeekdays(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::NARROW
);
525 syms
->getQuarters(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::WIDE
);
528 case UDAT_SHORT_QUARTERS
:
529 syms
->getQuarters(count
, DateFormatSymbols::FORMAT
, DateFormatSymbols::ABBREVIATED
);
532 case UDAT_STANDALONE_QUARTERS
:
533 syms
->getQuarters(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::WIDE
);
536 case UDAT_STANDALONE_SHORT_QUARTERS
:
537 syms
->getQuarters(count
, DateFormatSymbols::STANDALONE
, DateFormatSymbols::ABBREVIATED
);
548 * This DateFormatSymbolsSingleSetter class is a friend of DateFormatSymbols
549 * solely for the purpose of avoiding to clone the array of strings
550 * just to modify one of them and then setting all of them back.
551 * For example, the old code looked like this:
553 * res = syms->getMonths(count);
554 * array = new UnicodeString[count];
556 * *status = U_MEMORY_ALLOCATION_ERROR;
559 * uprv_arrayCopy(res, array, count);
561 * array[index] = val;
562 * syms->setMonths(array, count);
565 * Even worse, the old code actually cloned the entire DateFormatSymbols object,
566 * cloned one value array, changed one value, and then made the SimpleDateFormat
567 * replace its DateFormatSymbols object with the new one.
571 class DateFormatSymbolsSingleSetter
/* not : public UObject because all methods are static */ {
574 setSymbol(UnicodeString
*array
, int32_t count
, int32_t index
,
575 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
579 errorCode
=U_INDEX_OUTOFBOUNDS_ERROR
;
580 } else if(value
==NULL
) {
581 errorCode
=U_ILLEGAL_ARGUMENT_ERROR
;
583 array
[index
].setTo(value
, valueLength
);
589 setEra(DateFormatSymbols
*syms
, int32_t index
,
590 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
592 setSymbol(syms
->fEras
, syms
->fErasCount
, index
, value
, valueLength
, errorCode
);
596 setEraName(DateFormatSymbols
*syms
, int32_t index
,
597 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
599 setSymbol(syms
->fEraNames
, syms
->fEraNamesCount
, index
, value
, valueLength
, errorCode
);
603 setMonth(DateFormatSymbols
*syms
, int32_t index
,
604 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
606 setSymbol(syms
->fMonths
, syms
->fMonthsCount
, index
, value
, valueLength
, errorCode
);
610 setShortMonth(DateFormatSymbols
*syms
, int32_t index
,
611 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
613 setSymbol(syms
->fShortMonths
, syms
->fShortMonthsCount
, index
, value
, valueLength
, errorCode
);
617 setNarrowMonth(DateFormatSymbols
*syms
, int32_t index
,
618 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
620 setSymbol(syms
->fNarrowMonths
, syms
->fNarrowMonthsCount
, index
, value
, valueLength
, errorCode
);
624 setStandaloneMonth(DateFormatSymbols
*syms
, int32_t index
,
625 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
627 setSymbol(syms
->fStandaloneMonths
, syms
->fStandaloneMonthsCount
, index
, value
, valueLength
, errorCode
);
631 setStandaloneShortMonth(DateFormatSymbols
*syms
, int32_t index
,
632 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
634 setSymbol(syms
->fStandaloneShortMonths
, syms
->fStandaloneShortMonthsCount
, index
, value
, valueLength
, errorCode
);
638 setStandaloneNarrowMonth(DateFormatSymbols
*syms
, int32_t index
,
639 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
641 setSymbol(syms
->fStandaloneNarrowMonths
, syms
->fStandaloneNarrowMonthsCount
, index
, value
, valueLength
, errorCode
);
645 setWeekday(DateFormatSymbols
*syms
, int32_t index
,
646 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
648 setSymbol(syms
->fWeekdays
, syms
->fWeekdaysCount
, index
, value
, valueLength
, errorCode
);
652 setShortWeekday(DateFormatSymbols
*syms
, int32_t index
,
653 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
655 setSymbol(syms
->fShortWeekdays
, syms
->fShortWeekdaysCount
, index
, value
, valueLength
, errorCode
);
659 setNarrowWeekday(DateFormatSymbols
*syms
, int32_t index
,
660 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
662 setSymbol(syms
->fNarrowWeekdays
, syms
->fNarrowWeekdaysCount
, index
, value
, valueLength
, errorCode
);
666 setStandaloneWeekday(DateFormatSymbols
*syms
, int32_t index
,
667 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
669 setSymbol(syms
->fStandaloneWeekdays
, syms
->fStandaloneWeekdaysCount
, index
, value
, valueLength
, errorCode
);
673 setStandaloneShortWeekday(DateFormatSymbols
*syms
, int32_t index
,
674 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
676 setSymbol(syms
->fStandaloneShortWeekdays
, syms
->fStandaloneShortWeekdaysCount
, index
, value
, valueLength
, errorCode
);
680 setStandaloneNarrowWeekday(DateFormatSymbols
*syms
, int32_t index
,
681 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
683 setSymbol(syms
->fStandaloneNarrowWeekdays
, syms
->fStandaloneNarrowWeekdaysCount
, index
, value
, valueLength
, errorCode
);
687 setQuarter(DateFormatSymbols
*syms
, int32_t index
,
688 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
690 setSymbol(syms
->fQuarters
, syms
->fQuartersCount
, index
, value
, valueLength
, errorCode
);
694 setShortQuarter(DateFormatSymbols
*syms
, int32_t index
,
695 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
697 setSymbol(syms
->fShortQuarters
, syms
->fShortQuartersCount
, index
, value
, valueLength
, errorCode
);
701 setStandaloneQuarter(DateFormatSymbols
*syms
, int32_t index
,
702 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
704 setSymbol(syms
->fStandaloneQuarters
, syms
->fStandaloneQuartersCount
, index
, value
, valueLength
, errorCode
);
708 setStandaloneShortQuarter(DateFormatSymbols
*syms
, int32_t index
,
709 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
711 setSymbol(syms
->fStandaloneShortQuarters
, syms
->fStandaloneShortQuartersCount
, index
, value
, valueLength
, errorCode
);
715 setAmPm(DateFormatSymbols
*syms
, int32_t index
,
716 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
718 setSymbol(syms
->fAmPms
, syms
->fAmPmsCount
, index
, value
, valueLength
, errorCode
);
722 setLocalPatternChars(DateFormatSymbols
*syms
,
723 const UChar
*value
, int32_t valueLength
, UErrorCode
&errorCode
)
725 setSymbol(&syms
->fLocalPatternChars
, 1, 0, value
, valueLength
, errorCode
);
731 U_CAPI
void U_EXPORT2
732 udat_setSymbols( UDateFormat
*format
,
733 UDateFormatSymbolType type
,
739 verifyIsSimpleDateFormat(format
, status
);
740 if(U_FAILURE(*status
)) return;
742 DateFormatSymbols
*syms
= (DateFormatSymbols
*)((SimpleDateFormat
*)format
)->getDateFormatSymbols();
746 DateFormatSymbolsSingleSetter::setEra(syms
, index
, value
, valueLength
, *status
);
750 DateFormatSymbolsSingleSetter::setEraName(syms
, index
, value
, valueLength
, *status
);
754 DateFormatSymbolsSingleSetter::setMonth(syms
, index
, value
, valueLength
, *status
);
757 case UDAT_SHORT_MONTHS
:
758 DateFormatSymbolsSingleSetter::setShortMonth(syms
, index
, value
, valueLength
, *status
);
761 case UDAT_NARROW_MONTHS
:
762 DateFormatSymbolsSingleSetter::setNarrowMonth(syms
, index
, value
, valueLength
, *status
);
765 case UDAT_STANDALONE_MONTHS
:
766 DateFormatSymbolsSingleSetter::setStandaloneMonth(syms
, index
, value
, valueLength
, *status
);
769 case UDAT_STANDALONE_SHORT_MONTHS
:
770 DateFormatSymbolsSingleSetter::setStandaloneShortMonth(syms
, index
, value
, valueLength
, *status
);
773 case UDAT_STANDALONE_NARROW_MONTHS
:
774 DateFormatSymbolsSingleSetter::setStandaloneNarrowMonth(syms
, index
, value
, valueLength
, *status
);
778 DateFormatSymbolsSingleSetter::setWeekday(syms
, index
, value
, valueLength
, *status
);
781 case UDAT_SHORT_WEEKDAYS
:
782 DateFormatSymbolsSingleSetter::setShortWeekday(syms
, index
, value
, valueLength
, *status
);
785 case UDAT_NARROW_WEEKDAYS
:
786 DateFormatSymbolsSingleSetter::setNarrowWeekday(syms
, index
, value
, valueLength
, *status
);
789 case UDAT_STANDALONE_WEEKDAYS
:
790 DateFormatSymbolsSingleSetter::setStandaloneWeekday(syms
, index
, value
, valueLength
, *status
);
793 case UDAT_STANDALONE_SHORT_WEEKDAYS
:
794 DateFormatSymbolsSingleSetter::setStandaloneShortWeekday(syms
, index
, value
, valueLength
, *status
);
797 case UDAT_STANDALONE_NARROW_WEEKDAYS
:
798 DateFormatSymbolsSingleSetter::setStandaloneNarrowWeekday(syms
, index
, value
, valueLength
, *status
);
802 DateFormatSymbolsSingleSetter::setQuarter(syms
, index
, value
, valueLength
, *status
);
805 case UDAT_SHORT_QUARTERS
:
806 DateFormatSymbolsSingleSetter::setShortQuarter(syms
, index
, value
, valueLength
, *status
);
809 case UDAT_STANDALONE_QUARTERS
:
810 DateFormatSymbolsSingleSetter::setStandaloneQuarter(syms
, index
, value
, valueLength
, *status
);
813 case UDAT_STANDALONE_SHORT_QUARTERS
:
814 DateFormatSymbolsSingleSetter::setStandaloneShortQuarter(syms
, index
, value
, valueLength
, *status
);
818 DateFormatSymbolsSingleSetter::setAmPm(syms
, index
, value
, valueLength
, *status
);
821 case UDAT_LOCALIZED_CHARS
:
822 DateFormatSymbolsSingleSetter::setLocalPatternChars(syms
, value
, valueLength
, *status
);
826 *status
= U_UNSUPPORTED_ERROR
;
832 U_CAPI
const char* U_EXPORT2
833 udat_getLocaleByType(const UDateFormat
*fmt
,
834 ULocDataLocaleType type
,
838 if (U_SUCCESS(*status
)) {
839 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
843 return ((Format
*)fmt
)->getLocaleID(type
, *status
);
847 * Verify that fmt is a RelativeDateFormat. Invalid error if not.
848 * @param fmt the UDateFormat, definitely a DateFormat, maybe something else
849 * @param status error code, will be set to failure if there is a familure or the fmt is NULL.
851 static void verifyIsRelativeDateFormat(const UDateFormat
* fmt
, UErrorCode
*status
) {
852 if(!U_FAILURE(*status
) &&
853 ((DateFormat
*)fmt
)->getDynamicClassID()!=RelativeDateFormat::getStaticClassID()) {
854 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
859 U_CAPI
int32_t U_EXPORT2
860 udat_toPatternRelativeDate(const UDateFormat
*fmt
,
862 int32_t resultLength
,
865 verifyIsRelativeDateFormat(fmt
, status
);
866 if(U_FAILURE(*status
)) return -1;
868 UnicodeString datePattern
;
869 if(!(result
==NULL
&& resultLength
==0)) {
870 // NULL destination for pure preflighting: empty dummy string
871 // otherwise, alias the destination buffer
872 datePattern
.setTo(result
, 0, resultLength
);
874 ((RelativeDateFormat
*)fmt
)->toPatternDate(datePattern
, *status
);
875 return datePattern
.extract(result
, resultLength
, *status
);
878 U_CAPI
int32_t U_EXPORT2
879 udat_toPatternRelativeTime(const UDateFormat
*fmt
,
881 int32_t resultLength
,
884 verifyIsRelativeDateFormat(fmt
, status
);
885 if(U_FAILURE(*status
)) return -1;
887 UnicodeString timePattern
;
888 if(!(result
==NULL
&& resultLength
==0)) {
889 // NULL destination for pure preflighting: empty dummy string
890 // otherwise, alias the destination buffer
891 timePattern
.setTo(result
, 0, resultLength
);
893 ((RelativeDateFormat
*)fmt
)->toPatternTime(timePattern
, *status
);
894 return timePattern
.extract(result
, resultLength
, *status
);
897 U_CAPI
void U_EXPORT2
898 udat_applyPatternRelative(UDateFormat
*format
,
899 const UChar
*datePattern
,
900 int32_t datePatternLength
,
901 const UChar
*timePattern
,
902 int32_t timePatternLength
,
905 verifyIsRelativeDateFormat(format
, status
);
906 if(U_FAILURE(*status
)) return;
907 const UnicodeString
datePat((UBool
)(datePatternLength
== -1), datePattern
, datePatternLength
);
908 const UnicodeString
timePat((UBool
)(timePatternLength
== -1), timePattern
, timePatternLength
);
909 ((RelativeDateFormat
*)format
)->applyPatterns(datePat
, timePat
, *status
);
912 #endif /* #if !UCONFIG_NO_FORMATTING */