1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2012-01-17 08:06:29 +00:00
|
|
|
* Copyright (C) 1996-2012, International Business Machines
|
1999-11-23 01:30:04 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/udat.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/uloc.h"
|
|
|
|
#include "unicode/datefmt.h"
|
|
|
|
#include "unicode/timezone.h"
|
|
|
|
#include "unicode/smpdtfmt.h"
|
|
|
|
#include "unicode/fieldpos.h"
|
|
|
|
#include "unicode/parsepos.h"
|
|
|
|
#include "unicode/calendar.h"
|
|
|
|
#include "unicode/numfmt.h"
|
|
|
|
#include "unicode/dtfmtsym.h"
|
|
|
|
#include "unicode/ustring.h"
|
2002-07-12 21:42:24 +00:00
|
|
|
#include "cpputils.h"
|
2009-04-18 08:11:19 +00:00
|
|
|
#include "reldtfmt.h"
|
2012-02-18 23:10:51 +00:00
|
|
|
#include "umutex.h"
|
2001-10-08 23:26:58 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_USE
|
|
|
|
|
2009-02-14 02:29:08 +00:00
|
|
|
/**
|
|
|
|
* Verify that fmt is a SimpleDateFormat. Invalid error if not.
|
|
|
|
* @param fmt the UDateFormat, definitely a DateFormat, maybe something else
|
|
|
|
* @param status error code, will be set to failure if there is a familure or the fmt is NULL.
|
|
|
|
*/
|
|
|
|
static void verifyIsSimpleDateFormat(const UDateFormat* fmt, UErrorCode *status) {
|
2010-05-19 17:29:33 +00:00
|
|
|
if(U_SUCCESS(*status) &&
|
|
|
|
dynamic_cast<const SimpleDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))==NULL) {
|
2009-02-14 02:29:08 +00:00
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-17 22:15:20 +00:00
|
|
|
// This mirrors the correspondence between the
|
|
|
|
// SimpleDateFormat::fgPatternIndexToDateFormatField and
|
|
|
|
// SimpleDateFormat::fgPatternIndexToCalendarField arrays.
|
|
|
|
static UCalendarDateFields gDateFieldMapping[] = {
|
|
|
|
UCAL_ERA, // UDAT_ERA_FIELD = 0
|
|
|
|
UCAL_YEAR, // UDAT_YEAR_FIELD = 1
|
|
|
|
UCAL_MONTH, // UDAT_MONTH_FIELD = 2
|
|
|
|
UCAL_DATE, // UDAT_DATE_FIELD = 3
|
|
|
|
UCAL_HOUR_OF_DAY, // UDAT_HOUR_OF_DAY1_FIELD = 4
|
|
|
|
UCAL_HOUR_OF_DAY, // UDAT_HOUR_OF_DAY0_FIELD = 5
|
|
|
|
UCAL_MINUTE, // UDAT_MINUTE_FIELD = 6
|
|
|
|
UCAL_SECOND, // UDAT_SECOND_FIELD = 7
|
|
|
|
UCAL_MILLISECOND, // UDAT_FRACTIONAL_SECOND_FIELD = 8
|
|
|
|
UCAL_DAY_OF_WEEK, // UDAT_DAY_OF_WEEK_FIELD = 9
|
|
|
|
UCAL_DAY_OF_YEAR, // UDAT_DAY_OF_YEAR_FIELD = 10
|
|
|
|
UCAL_DAY_OF_WEEK_IN_MONTH, // UDAT_DAY_OF_WEEK_IN_MONTH_FIELD = 11
|
|
|
|
UCAL_WEEK_OF_YEAR, // UDAT_WEEK_OF_YEAR_FIELD = 12
|
|
|
|
UCAL_WEEK_OF_MONTH, // UDAT_WEEK_OF_MONTH_FIELD = 13
|
|
|
|
UCAL_AM_PM, // UDAT_AM_PM_FIELD = 14
|
|
|
|
UCAL_HOUR, // UDAT_HOUR1_FIELD = 15
|
|
|
|
UCAL_HOUR, // UDAT_HOUR0_FIELD = 16
|
|
|
|
UCAL_ZONE_OFFSET, // UDAT_TIMEZONE_FIELD = 17
|
|
|
|
UCAL_YEAR_WOY, // UDAT_YEAR_WOY_FIELD = 18
|
|
|
|
UCAL_DOW_LOCAL, // UDAT_DOW_LOCAL_FIELD = 19
|
|
|
|
UCAL_EXTENDED_YEAR, // UDAT_EXTENDED_YEAR_FIELD = 20
|
|
|
|
UCAL_JULIAN_DAY, // UDAT_JULIAN_DAY_FIELD = 21
|
|
|
|
UCAL_MILLISECONDS_IN_DAY, // UDAT_MILLISECONDS_IN_DAY_FIELD = 22
|
|
|
|
UCAL_ZONE_OFFSET, // UDAT_TIMEZONE_RFC_FIELD = 23
|
|
|
|
// UCAL_DST_OFFSET also
|
|
|
|
UCAL_ZONE_OFFSET, // UDAT_TIMEZONE_GENERIC_FIELD = 24
|
|
|
|
UCAL_DOW_LOCAL, // UDAT_STANDALONE_DAY_FIELD = 25
|
|
|
|
UCAL_MONTH, // UDAT_STANDALONE_MONTH_FIELD = 26
|
|
|
|
UCAL_MONTH, // UDAT_QUARTER_FIELD = 27
|
|
|
|
UCAL_MONTH, // UDAT_STANDALONE_QUARTER_FIELD = 28
|
|
|
|
UCAL_ZONE_OFFSET, // UDAT_TIMEZONE_SPECIAL_FIELD = 29
|
2012-01-17 08:06:29 +00:00
|
|
|
UCAL_YEAR, // UDAT_YEAR_NAME_FIELD = 30
|
|
|
|
UCAL_FIELD_COUNT, // UDAT_FIELD_COUNT = 31
|
2009-12-17 22:15:20 +00:00
|
|
|
// UCAL_IS_LEAP_MONTH is not the target of a mapping
|
|
|
|
};
|
|
|
|
|
|
|
|
U_CAPI UCalendarDateFields U_EXPORT2
|
|
|
|
udat_toCalendarDateField(UDateFormatField field) {
|
|
|
|
return gDateFieldMapping[field];
|
|
|
|
}
|
|
|
|
|
2012-02-18 23:10:51 +00:00
|
|
|
/* For now- one opener. */
|
|
|
|
static UDateFormatOpener gOpener = NULL;
|
|
|
|
|
|
|
|
U_INTERNAL void U_EXPORT2
|
|
|
|
udat_registerOpener(UDateFormatOpener opener, UErrorCode *status)
|
|
|
|
{
|
|
|
|
if(U_FAILURE(*status)) return;
|
|
|
|
umtx_lock(NULL);
|
|
|
|
if(gOpener==NULL) {
|
|
|
|
gOpener = opener;
|
|
|
|
} else {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
}
|
|
|
|
umtx_unlock(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_INTERNAL UDateFormatOpener U_EXPORT2
|
|
|
|
udat_unregisterOpener(UDateFormatOpener opener, UErrorCode *status)
|
|
|
|
{
|
|
|
|
if(U_FAILURE(*status)) return NULL;
|
|
|
|
UDateFormatOpener oldOpener = NULL;
|
|
|
|
umtx_lock(NULL);
|
|
|
|
if(gOpener==NULL || gOpener!=opener) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
} else {
|
|
|
|
oldOpener=gOpener;
|
|
|
|
gOpener=NULL;
|
|
|
|
}
|
|
|
|
umtx_unlock(NULL);
|
|
|
|
return oldOpener;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UDateFormat* U_EXPORT2
|
2001-08-16 00:55:16 +00:00
|
|
|
udat_open(UDateFormatStyle timeStyle,
|
|
|
|
UDateFormatStyle dateStyle,
|
|
|
|
const char *locale,
|
2002-04-02 02:55:31 +00:00
|
|
|
const UChar *tzID,
|
|
|
|
int32_t tzIDLength,
|
2001-08-16 00:55:16 +00:00
|
|
|
const UChar *pattern,
|
|
|
|
int32_t patternLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2005-09-15 04:28:26 +00:00
|
|
|
DateFormat *fmt;
|
|
|
|
if(U_FAILURE(*status)) {
|
2001-08-16 00:55:16 +00:00
|
|
|
return 0;
|
2004-07-16 16:22:08 +00:00
|
|
|
}
|
2012-02-18 23:10:51 +00:00
|
|
|
if(gOpener!=NULL) { // if it's registered
|
|
|
|
fmt = (DateFormat*) (*gOpener)(timeStyle,dateStyle,locale,tzID,tzIDLength,pattern,patternLength,status);
|
|
|
|
if(fmt!=NULL) {
|
|
|
|
return (UDateFormat*)fmt;
|
|
|
|
} // else fall through.
|
|
|
|
}
|
2005-09-15 04:28:26 +00:00
|
|
|
if(timeStyle != UDAT_IGNORE) {
|
|
|
|
if(locale == 0) {
|
2004-07-16 16:22:08 +00:00
|
|
|
fmt = DateFormat::createDateTimeInstance((DateFormat::EStyle)dateStyle,
|
|
|
|
(DateFormat::EStyle)timeStyle);
|
2005-09-15 04:28:26 +00:00
|
|
|
}
|
|
|
|
else {
|
2004-07-16 16:22:08 +00:00
|
|
|
fmt = DateFormat::createDateTimeInstance((DateFormat::EStyle)dateStyle,
|
|
|
|
(DateFormat::EStyle)timeStyle,
|
|
|
|
Locale(locale));
|
2001-08-16 00:55:16 +00:00
|
|
|
}
|
2005-09-15 04:28:26 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
UnicodeString pat((UBool)(patternLength == -1), pattern, patternLength);
|
2004-07-16 16:22:08 +00:00
|
|
|
|
2005-09-15 04:28:26 +00:00
|
|
|
if(locale == 0) {
|
|
|
|
fmt = new SimpleDateFormat(pat, *status);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fmt = new SimpleDateFormat(pat, Locale(locale), *status);
|
2004-07-16 16:22:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-15 04:28:26 +00:00
|
|
|
if(fmt == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
2004-07-16 16:22:08 +00:00
|
|
|
|
2005-09-15 04:28:26 +00:00
|
|
|
if(tzID != 0) {
|
|
|
|
TimeZone *zone = TimeZone::createTimeZone(UnicodeString((UBool)(tzIDLength == -1), tzID, tzIDLength));
|
|
|
|
if(zone == 0) {
|
2004-07-16 16:22:08 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
2005-09-15 04:28:26 +00:00
|
|
|
delete fmt;
|
2004-07-16 16:22:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-09-15 04:28:26 +00:00
|
|
|
fmt->adoptTimeZone(zone);
|
2004-07-16 16:22:08 +00:00
|
|
|
}
|
2005-09-15 04:28:26 +00:00
|
|
|
|
|
|
|
return (UDateFormat*)fmt;
|
2001-08-16 00:55:16 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_close(UDateFormat* format)
|
|
|
|
{
|
2004-07-16 16:22:08 +00:00
|
|
|
delete (DateFormat*)format;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UDateFormat* U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_clone(const UDateFormat *fmt,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2004-07-16 16:22:08 +00:00
|
|
|
if(U_FAILURE(*status)) return 0;
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2009-02-14 02:29:08 +00:00
|
|
|
Format *res = ((DateFormat*)fmt)->clone();
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
if(res == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
return (UDateFormat*) res;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_format( const UDateFormat* format,
|
|
|
|
UDate dateToFormat,
|
|
|
|
UChar* result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UFieldPosition* position,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
2004-07-16 16:22:08 +00:00
|
|
|
if(U_FAILURE(*status)) return -1;
|
|
|
|
|
|
|
|
UnicodeString res;
|
|
|
|
if(!(result==NULL && resultLength==0)) {
|
|
|
|
// NULL destination for pure preflighting: empty dummy string
|
|
|
|
// otherwise, alias the destination buffer
|
|
|
|
res.setTo(result, 0, resultLength);
|
|
|
|
}
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
FieldPosition fp;
|
|
|
|
|
|
|
|
if(position != 0)
|
|
|
|
fp.setField(position->field);
|
|
|
|
|
|
|
|
((DateFormat*)format)->format(dateToFormat, res, fp);
|
|
|
|
|
|
|
|
if(position != 0) {
|
|
|
|
position->beginIndex = fp.getBeginIndex();
|
|
|
|
position->endIndex = fp.getEndIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.extract(result, resultLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UDate U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_parse( const UDateFormat* format,
|
|
|
|
const UChar* text,
|
|
|
|
int32_t textLength,
|
|
|
|
int32_t *parsePos,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2004-07-16 16:22:08 +00:00
|
|
|
if(U_FAILURE(*status)) return (UDate)0;
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
const UnicodeString src((UBool)(textLength == -1), text, textLength);
|
|
|
|
ParsePosition pp;
|
|
|
|
int32_t stackParsePos = 0;
|
|
|
|
UDate res;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
if(parsePos == NULL) {
|
|
|
|
parsePos = &stackParsePos;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
pp.setIndex(*parsePos);
|
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
res = ((DateFormat*)format)->parse(src, pp);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
if(pp.getErrorIndex() == -1)
|
2004-07-16 16:22:08 +00:00
|
|
|
*parsePos = pp.getIndex();
|
1999-08-16 21:50:52 +00:00
|
|
|
else {
|
2004-07-16 16:22:08 +00:00
|
|
|
*parsePos = pp.getErrorIndex();
|
|
|
|
*status = U_PARSE_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2004-07-16 16:22:08 +00:00
|
|
|
|
|
|
|
return res;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-03-06 20:41:57 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
udat_parseCalendar(const UDateFormat* format,
|
|
|
|
UCalendar* calendar,
|
|
|
|
const UChar* text,
|
|
|
|
int32_t textLength,
|
|
|
|
int32_t *parsePos,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2004-07-16 16:22:08 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
2002-03-06 20:41:57 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
const UnicodeString src((UBool)(textLength == -1), text, textLength);
|
|
|
|
ParsePosition pp;
|
2002-03-06 20:41:57 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
if(parsePos != 0)
|
|
|
|
pp.setIndex(*parsePos);
|
2002-03-06 20:41:57 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
((DateFormat*)format)->parse(src, *(Calendar*)calendar, pp);
|
2002-03-06 20:41:57 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
if(parsePos != 0) {
|
|
|
|
if(pp.getErrorIndex() == -1)
|
|
|
|
*parsePos = pp.getIndex();
|
|
|
|
else {
|
|
|
|
*parsePos = pp.getErrorIndex();
|
|
|
|
*status = U_PARSE_ERROR;
|
|
|
|
}
|
2002-03-06 20:41:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UBool U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_isLenient(const UDateFormat* fmt)
|
|
|
|
{
|
2004-07-16 16:22:08 +00:00
|
|
|
return ((DateFormat*)fmt)->isLenient();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_setLenient( UDateFormat* fmt,
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool isLenient)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2004-07-16 16:22:08 +00:00
|
|
|
((DateFormat*)fmt)->setLenient(isLenient);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI const UCalendar* U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_getCalendar(const UDateFormat* fmt)
|
|
|
|
{
|
2004-07-16 16:22:08 +00:00
|
|
|
return (const UCalendar*) ((DateFormat*)fmt)->getCalendar();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2004-07-16 16:22:08 +00:00
|
|
|
udat_setCalendar(UDateFormat* fmt,
|
|
|
|
const UCalendar* calendarToSet)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2004-07-16 16:22:08 +00:00
|
|
|
((DateFormat*)fmt)->setCalendar(*((Calendar*)calendarToSet));
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI const UNumberFormat* U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_getNumberFormat(const UDateFormat* fmt)
|
|
|
|
{
|
2004-07-16 16:22:08 +00:00
|
|
|
return (const UNumberFormat*) ((DateFormat*)fmt)->getNumberFormat();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2004-07-16 16:22:08 +00:00
|
|
|
udat_setNumberFormat(UDateFormat* fmt,
|
|
|
|
const UNumberFormat* numberFormatToSet)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2004-07-16 16:22:08 +00:00
|
|
|
((DateFormat*)fmt)->setNumberFormat(*((NumberFormat*)numberFormatToSet));
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_getAvailable(int32_t index)
|
|
|
|
{
|
2004-07-16 16:22:08 +00:00
|
|
|
return uloc_getAvailable(index);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_countAvailable()
|
|
|
|
{
|
2004-07-16 16:22:08 +00:00
|
|
|
return uloc_countAvailable();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI UDate U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_get2DigitYearStart( const UDateFormat *fmt,
|
2004-07-16 16:22:08 +00:00
|
|
|
UErrorCode *status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2009-02-14 02:29:08 +00:00
|
|
|
verifyIsSimpleDateFormat(fmt, status);
|
2004-07-16 16:22:08 +00:00
|
|
|
if(U_FAILURE(*status)) return (UDate)0;
|
|
|
|
return ((SimpleDateFormat*)fmt)->get2DigitYearStart(*status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_set2DigitYearStart( UDateFormat *fmt,
|
2004-07-16 16:22:08 +00:00
|
|
|
UDate d,
|
|
|
|
UErrorCode *status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2009-02-14 02:29:08 +00:00
|
|
|
verifyIsSimpleDateFormat(fmt, status);
|
2004-07-16 16:22:08 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
|
|
|
((SimpleDateFormat*)fmt)->set2DigitYearStart(d, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_toPattern( const UDateFormat *fmt,
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool localized,
|
1999-08-16 21:50:52 +00:00
|
|
|
UChar *result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2004-07-16 16:22:08 +00:00
|
|
|
if(U_FAILURE(*status)) return -1;
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
UnicodeString res;
|
|
|
|
if(!(result==NULL && resultLength==0)) {
|
|
|
|
// NULL destination for pure preflighting: empty dummy string
|
|
|
|
// otherwise, alias the destination buffer
|
|
|
|
res.setTo(result, 0, resultLength);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2010-05-19 17:29:33 +00:00
|
|
|
const DateFormat *df=reinterpret_cast<const DateFormat *>(fmt);
|
|
|
|
const SimpleDateFormat *sdtfmt=dynamic_cast<const SimpleDateFormat *>(df);
|
|
|
|
const RelativeDateFormat *reldtfmt;
|
|
|
|
if (sdtfmt!=NULL) {
|
2009-04-18 08:11:19 +00:00
|
|
|
if(localized)
|
2010-05-19 17:29:33 +00:00
|
|
|
sdtfmt->toLocalizedPattern(res, *status);
|
2009-04-18 08:11:19 +00:00
|
|
|
else
|
2010-05-19 17:29:33 +00:00
|
|
|
sdtfmt->toPattern(res);
|
|
|
|
} else if (!localized && (reldtfmt=dynamic_cast<const RelativeDateFormat *>(df))!=NULL) {
|
|
|
|
reldtfmt->toPattern(res, *status);
|
2009-04-18 08:11:19 +00:00
|
|
|
} else {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
return res.extract(result, resultLength, *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2009-02-14 02:29:08 +00:00
|
|
|
// TODO: should this take an UErrorCode?
|
|
|
|
// A: Yes. Of course.
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2004-07-16 16:22:08 +00:00
|
|
|
udat_applyPattern( UDateFormat *format,
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool localized,
|
1999-08-16 21:50:52 +00:00
|
|
|
const UChar *pattern,
|
|
|
|
int32_t patternLength)
|
|
|
|
{
|
2004-07-16 16:22:08 +00:00
|
|
|
const UnicodeString pat((UBool)(patternLength == -1), pattern, patternLength);
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2009-02-14 02:29:08 +00:00
|
|
|
verifyIsSimpleDateFormat(format, &status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
if(localized)
|
|
|
|
((SimpleDateFormat*)format)->applyLocalizedPattern(pat, status);
|
|
|
|
else
|
|
|
|
((SimpleDateFormat*)format)->applyPattern(pat);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2004-07-16 16:22:08 +00:00
|
|
|
udat_getSymbols(const UDateFormat *fmt,
|
|
|
|
UDateFormatSymbolType type,
|
|
|
|
int32_t index,
|
|
|
|
UChar *result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UErrorCode *status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2011-05-02 23:14:32 +00:00
|
|
|
const DateFormatSymbols *syms;
|
|
|
|
const SimpleDateFormat* sdtfmt;
|
|
|
|
const RelativeDateFormat* rdtfmt;
|
|
|
|
if ((sdtfmt = dynamic_cast<const SimpleDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))) != NULL) {
|
|
|
|
syms = sdtfmt->getDateFormatSymbols();
|
|
|
|
} else if ((rdtfmt = dynamic_cast<const RelativeDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))) != NULL) {
|
|
|
|
syms = rdtfmt->getDateFormatSymbols();
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
2004-07-16 16:22:08 +00:00
|
|
|
int32_t count;
|
2005-07-12 04:41:20 +00:00
|
|
|
const UnicodeString *res = NULL;
|
2004-07-16 16:22:08 +00:00
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case UDAT_ERAS:
|
|
|
|
res = syms->getEras(count);
|
|
|
|
break;
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2005-10-13 03:26:40 +00:00
|
|
|
case UDAT_ERA_NAMES:
|
|
|
|
res = syms->getEraNames(count);
|
|
|
|
break;
|
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
case UDAT_MONTHS:
|
|
|
|
res = syms->getMonths(count);
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
case UDAT_SHORT_MONTHS:
|
|
|
|
res = syms->getShortMonths(count);
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
case UDAT_WEEKDAYS:
|
|
|
|
res = syms->getWeekdays(count);
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
case UDAT_SHORT_WEEKDAYS:
|
|
|
|
res = syms->getShortWeekdays(count);
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
case UDAT_AM_PMS:
|
|
|
|
res = syms->getAmPmStrings(count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_LOCALIZED_CHARS:
|
|
|
|
{
|
|
|
|
UnicodeString res1;
|
|
|
|
if(!(result==NULL && resultLength==0)) {
|
|
|
|
// NULL destination for pure preflighting: empty dummy string
|
|
|
|
// otherwise, alias the destination buffer
|
|
|
|
res1.setTo(result, 0, resultLength);
|
|
|
|
}
|
|
|
|
syms->getLocalPatternChars(res1);
|
|
|
|
return res1.extract(result, resultLength, *status);
|
|
|
|
}
|
2005-07-12 04:41:20 +00:00
|
|
|
|
|
|
|
case UDAT_NARROW_MONTHS:
|
|
|
|
res = syms->getMonths(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_NARROW_WEEKDAYS:
|
|
|
|
res = syms->getWeekdays(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_MONTHS:
|
|
|
|
res = syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_SHORT_MONTHS:
|
|
|
|
res = syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_NARROW_MONTHS:
|
|
|
|
res = syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_WEEKDAYS:
|
|
|
|
res = syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_SHORT_WEEKDAYS:
|
|
|
|
res = syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_NARROW_WEEKDAYS:
|
|
|
|
res = syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
|
|
|
|
break;
|
|
|
|
|
2006-07-12 23:21:02 +00:00
|
|
|
case UDAT_QUARTERS:
|
|
|
|
res = syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_SHORT_QUARTERS:
|
|
|
|
res = syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_QUARTERS:
|
|
|
|
res = syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_SHORT_QUARTERS:
|
|
|
|
res = syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
|
|
|
|
break;
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2005-07-12 04:41:20 +00:00
|
|
|
if(index < count) {
|
|
|
|
return res[index].extract(result, resultLength, *status);
|
|
|
|
}
|
2004-07-16 16:22:08 +00:00
|
|
|
return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2009-02-14 02:29:08 +00:00
|
|
|
// TODO: also needs an errorCode.
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_countSymbols( const UDateFormat *fmt,
|
|
|
|
UDateFormatSymbolType type)
|
|
|
|
{
|
2011-05-02 23:14:32 +00:00
|
|
|
const DateFormatSymbols *syms;
|
|
|
|
const SimpleDateFormat* sdtfmt;
|
|
|
|
const RelativeDateFormat* rdtfmt;
|
|
|
|
if ((sdtfmt = dynamic_cast<const SimpleDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))) != NULL) {
|
|
|
|
syms = sdtfmt->getDateFormatSymbols();
|
|
|
|
} else if ((rdtfmt = dynamic_cast<const RelativeDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))) != NULL) {
|
|
|
|
syms = rdtfmt->getDateFormatSymbols();
|
|
|
|
} else {
|
2009-02-14 02:29:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-07-16 16:22:08 +00:00
|
|
|
int32_t count = 0;
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case UDAT_ERAS:
|
|
|
|
syms->getEras(count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_MONTHS:
|
|
|
|
syms->getMonths(count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_SHORT_MONTHS:
|
|
|
|
syms->getShortMonths(count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_WEEKDAYS:
|
|
|
|
syms->getWeekdays(count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_SHORT_WEEKDAYS:
|
|
|
|
syms->getShortWeekdays(count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_AM_PMS:
|
|
|
|
syms->getAmPmStrings(count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_LOCALIZED_CHARS:
|
|
|
|
count = 1;
|
|
|
|
break;
|
2005-10-13 03:26:40 +00:00
|
|
|
|
2005-07-12 04:41:20 +00:00
|
|
|
case UDAT_ERA_NAMES:
|
|
|
|
syms->getEraNames(count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_NARROW_MONTHS:
|
|
|
|
syms->getMonths(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_NARROW_WEEKDAYS:
|
|
|
|
syms->getWeekdays(count, DateFormatSymbols::FORMAT, DateFormatSymbols::NARROW);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_MONTHS:
|
|
|
|
syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_SHORT_MONTHS:
|
|
|
|
syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_NARROW_MONTHS:
|
|
|
|
syms->getMonths(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_WEEKDAYS:
|
|
|
|
syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_SHORT_WEEKDAYS:
|
|
|
|
syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_NARROW_WEEKDAYS:
|
|
|
|
syms->getWeekdays(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::NARROW);
|
|
|
|
break;
|
|
|
|
|
2006-07-12 23:21:02 +00:00
|
|
|
case UDAT_QUARTERS:
|
|
|
|
syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::WIDE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_SHORT_QUARTERS:
|
|
|
|
syms->getQuarters(count, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_QUARTERS:
|
|
|
|
syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_SHORT_QUARTERS:
|
|
|
|
syms->getQuarters(count, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED);
|
|
|
|
break;
|
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
}
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
return count;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-10-15 00:36:11 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This DateFormatSymbolsSingleSetter class is a friend of DateFormatSymbols
|
|
|
|
* solely for the purpose of avoiding to clone the array of strings
|
|
|
|
* just to modify one of them and then setting all of them back.
|
|
|
|
* For example, the old code looked like this:
|
|
|
|
* case UDAT_MONTHS:
|
|
|
|
* res = syms->getMonths(count);
|
|
|
|
* array = new UnicodeString[count];
|
|
|
|
* if(array == 0) {
|
|
|
|
* *status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
* return;
|
|
|
|
* }
|
|
|
|
* uprv_arrayCopy(res, array, count);
|
|
|
|
* if(index < count)
|
|
|
|
* array[index] = val;
|
|
|
|
* syms->setMonths(array, count);
|
|
|
|
* break;
|
|
|
|
*
|
|
|
|
* Even worse, the old code actually cloned the entire DateFormatSymbols object,
|
|
|
|
* cloned one value array, changed one value, and then made the SimpleDateFormat
|
|
|
|
* replace its DateFormatSymbols object with the new one.
|
|
|
|
*
|
|
|
|
* markus 2002-oct-14
|
|
|
|
*/
|
|
|
|
class DateFormatSymbolsSingleSetter /* not : public UObject because all methods are static */ {
|
|
|
|
public:
|
2004-07-16 16:22:08 +00:00
|
|
|
static void
|
|
|
|
setSymbol(UnicodeString *array, int32_t count, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
if(array!=NULL) {
|
|
|
|
if(index>=count) {
|
|
|
|
errorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
|
|
|
} else if(value==NULL) {
|
|
|
|
errorCode=U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
} else {
|
|
|
|
array[index].setTo(value, valueLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setEra(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fEras, syms->fErasCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
2005-10-13 03:26:40 +00:00
|
|
|
static void
|
|
|
|
setEraName(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fEraNames, syms->fEraNamesCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
static void
|
|
|
|
setMonth(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fMonths, syms->fMonthsCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setShortMonth(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fShortMonths, syms->fShortMonthsCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
2005-10-13 03:26:40 +00:00
|
|
|
static void
|
|
|
|
setNarrowMonth(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fNarrowMonths, syms->fNarrowMonthsCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setStandaloneMonth(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fStandaloneMonths, syms->fStandaloneMonthsCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setStandaloneShortMonth(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fStandaloneShortMonths, syms->fStandaloneShortMonthsCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setStandaloneNarrowMonth(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fStandaloneNarrowMonths, syms->fStandaloneNarrowMonthsCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
static void
|
|
|
|
setWeekday(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fWeekdays, syms->fWeekdaysCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setShortWeekday(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fShortWeekdays, syms->fShortWeekdaysCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
2005-10-13 03:26:40 +00:00
|
|
|
static void
|
|
|
|
setNarrowWeekday(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fNarrowWeekdays, syms->fNarrowWeekdaysCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setStandaloneWeekday(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fStandaloneWeekdays, syms->fStandaloneWeekdaysCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setStandaloneShortWeekday(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fStandaloneShortWeekdays, syms->fStandaloneShortWeekdaysCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setStandaloneNarrowWeekday(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fStandaloneNarrowWeekdays, syms->fStandaloneNarrowWeekdaysCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
2006-08-08 21:58:59 +00:00
|
|
|
static void
|
|
|
|
setQuarter(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fQuarters, syms->fQuartersCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setShortQuarter(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fShortQuarters, syms->fShortQuartersCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setStandaloneQuarter(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fStandaloneQuarters, syms->fStandaloneQuartersCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setStandaloneShortQuarter(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fStandaloneShortQuarters, syms->fStandaloneShortQuartersCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
static void
|
|
|
|
setAmPm(DateFormatSymbols *syms, int32_t index,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(syms->fAmPms, syms->fAmPmsCount, index, value, valueLength, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setLocalPatternChars(DateFormatSymbols *syms,
|
|
|
|
const UChar *value, int32_t valueLength, UErrorCode &errorCode)
|
|
|
|
{
|
|
|
|
setSymbol(&syms->fLocalPatternChars, 1, 0, value, valueLength, errorCode);
|
2002-10-15 00:36:11 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2002-10-19 00:39:17 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
1999-08-16 21:50:52 +00:00
|
|
|
udat_setSymbols( UDateFormat *format,
|
|
|
|
UDateFormatSymbolType type,
|
|
|
|
int32_t index,
|
|
|
|
UChar *value,
|
|
|
|
int32_t valueLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2010-05-13 03:35:54 +00:00
|
|
|
verifyIsSimpleDateFormat(format, status);
|
2004-07-16 16:22:08 +00:00
|
|
|
if(U_FAILURE(*status)) return;
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
DateFormatSymbols *syms = (DateFormatSymbols *)((SimpleDateFormat *)format)->getDateFormatSymbols();
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
switch(type) {
|
|
|
|
case UDAT_ERAS:
|
|
|
|
DateFormatSymbolsSingleSetter::setEra(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2005-10-13 03:26:40 +00:00
|
|
|
case UDAT_ERA_NAMES:
|
|
|
|
DateFormatSymbolsSingleSetter::setEraName(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
case UDAT_MONTHS:
|
|
|
|
DateFormatSymbolsSingleSetter::setMonth(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
case UDAT_SHORT_MONTHS:
|
|
|
|
DateFormatSymbolsSingleSetter::setShortMonth(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2005-10-13 03:26:40 +00:00
|
|
|
case UDAT_NARROW_MONTHS:
|
|
|
|
DateFormatSymbolsSingleSetter::setNarrowMonth(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_MONTHS:
|
|
|
|
DateFormatSymbolsSingleSetter::setStandaloneMonth(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_SHORT_MONTHS:
|
|
|
|
DateFormatSymbolsSingleSetter::setStandaloneShortMonth(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_NARROW_MONTHS:
|
|
|
|
DateFormatSymbolsSingleSetter::setStandaloneNarrowMonth(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
case UDAT_WEEKDAYS:
|
|
|
|
DateFormatSymbolsSingleSetter::setWeekday(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
case UDAT_SHORT_WEEKDAYS:
|
|
|
|
DateFormatSymbolsSingleSetter::setShortWeekday(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2005-10-13 03:26:40 +00:00
|
|
|
case UDAT_NARROW_WEEKDAYS:
|
|
|
|
DateFormatSymbolsSingleSetter::setNarrowWeekday(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_WEEKDAYS:
|
|
|
|
DateFormatSymbolsSingleSetter::setStandaloneWeekday(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_SHORT_WEEKDAYS:
|
|
|
|
DateFormatSymbolsSingleSetter::setStandaloneShortWeekday(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_NARROW_WEEKDAYS:
|
|
|
|
DateFormatSymbolsSingleSetter::setStandaloneNarrowWeekday(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
|
|
|
|
2006-08-08 21:58:59 +00:00
|
|
|
case UDAT_QUARTERS:
|
|
|
|
DateFormatSymbolsSingleSetter::setQuarter(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_SHORT_QUARTERS:
|
|
|
|
DateFormatSymbolsSingleSetter::setShortQuarter(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_QUARTERS:
|
|
|
|
DateFormatSymbolsSingleSetter::setStandaloneQuarter(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UDAT_STANDALONE_SHORT_QUARTERS:
|
|
|
|
DateFormatSymbolsSingleSetter::setStandaloneShortQuarter(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
case UDAT_AM_PMS:
|
|
|
|
DateFormatSymbolsSingleSetter::setAmPm(syms, index, value, valueLength, *status);
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
case UDAT_LOCALIZED_CHARS:
|
|
|
|
DateFormatSymbolsSingleSetter::setLocalPatternChars(syms, value, valueLength, *status);
|
|
|
|
break;
|
2005-10-13 03:26:40 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
|
|
|
break;
|
|
|
|
|
2004-07-16 16:22:08 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-08-16 00:55:16 +00:00
|
|
|
|
2003-11-14 21:58:52 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
|
|
|
udat_getLocaleByType(const UDateFormat *fmt,
|
|
|
|
ULocDataLocaleType type,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
2004-01-20 23:06:38 +00:00
|
|
|
if (fmt == NULL) {
|
|
|
|
if (U_SUCCESS(*status)) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return ((Format*)fmt)->getLocaleID(type, *status);
|
2003-11-14 21:58:52 +00:00
|
|
|
}
|
2009-04-18 08:11:19 +00:00
|
|
|
|
2012-02-21 01:29:50 +00:00
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
udat_setDefaultContext(UDateFormat* fmt,
|
|
|
|
UDateFormatContextType type, UDateFormatContextValue value,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
|
|
|
verifyIsSimpleDateFormat(fmt, status);
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
((SimpleDateFormat*)fmt)->setDefaultContext(type, value, *status);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
udat_getDefaultContext(UDateFormat* fmt,
|
|
|
|
UDateFormatContextType type,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
|
|
|
verifyIsSimpleDateFormat(fmt, status);
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ((SimpleDateFormat*)fmt)->getDefaultContext(type, *status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-18 08:11:19 +00:00
|
|
|
/**
|
|
|
|
* Verify that fmt is a RelativeDateFormat. Invalid error if not.
|
|
|
|
* @param fmt the UDateFormat, definitely a DateFormat, maybe something else
|
|
|
|
* @param status error code, will be set to failure if there is a familure or the fmt is NULL.
|
|
|
|
*/
|
|
|
|
static void verifyIsRelativeDateFormat(const UDateFormat* fmt, UErrorCode *status) {
|
2010-05-19 17:29:33 +00:00
|
|
|
if(U_SUCCESS(*status) &&
|
|
|
|
dynamic_cast<const RelativeDateFormat*>(reinterpret_cast<const DateFormat*>(fmt))==NULL) {
|
2009-04-18 08:11:19 +00:00
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
udat_toPatternRelativeDate(const UDateFormat *fmt,
|
|
|
|
UChar *result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
verifyIsRelativeDateFormat(fmt, status);
|
|
|
|
if(U_FAILURE(*status)) return -1;
|
|
|
|
|
|
|
|
UnicodeString datePattern;
|
|
|
|
if(!(result==NULL && resultLength==0)) {
|
|
|
|
// NULL destination for pure preflighting: empty dummy string
|
|
|
|
// otherwise, alias the destination buffer
|
|
|
|
datePattern.setTo(result, 0, resultLength);
|
|
|
|
}
|
|
|
|
((RelativeDateFormat*)fmt)->toPatternDate(datePattern, *status);
|
|
|
|
return datePattern.extract(result, resultLength, *status);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
udat_toPatternRelativeTime(const UDateFormat *fmt,
|
|
|
|
UChar *result,
|
|
|
|
int32_t resultLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
verifyIsRelativeDateFormat(fmt, status);
|
|
|
|
if(U_FAILURE(*status)) return -1;
|
|
|
|
|
|
|
|
UnicodeString timePattern;
|
|
|
|
if(!(result==NULL && resultLength==0)) {
|
|
|
|
// NULL destination for pure preflighting: empty dummy string
|
|
|
|
// otherwise, alias the destination buffer
|
|
|
|
timePattern.setTo(result, 0, resultLength);
|
|
|
|
}
|
|
|
|
((RelativeDateFormat*)fmt)->toPatternTime(timePattern, *status);
|
|
|
|
return timePattern.extract(result, resultLength, *status);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
udat_applyPatternRelative(UDateFormat *format,
|
|
|
|
const UChar *datePattern,
|
|
|
|
int32_t datePatternLength,
|
|
|
|
const UChar *timePattern,
|
|
|
|
int32_t timePatternLength,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
verifyIsRelativeDateFormat(format, status);
|
|
|
|
if(U_FAILURE(*status)) return;
|
|
|
|
const UnicodeString datePat((UBool)(datePatternLength == -1), datePattern, datePatternLength);
|
|
|
|
const UnicodeString timePat((UBool)(timePatternLength == -1), timePattern, timePatternLength);
|
|
|
|
((RelativeDateFormat*)format)->applyPatterns(datePat, timePat, *status);
|
|
|
|
}
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|