ICU-9569 add UDAT_PATTERN and update docs
X-SVN-Rev: 32406
This commit is contained in:
parent
2d27b8f67e
commit
d455b9984e
@ -138,7 +138,7 @@ udat_open(UDateFormatStyle timeStyle,
|
||||
return (UDateFormat*)fmt;
|
||||
} // else fall through.
|
||||
}
|
||||
if(timeStyle != UDAT_IGNORE) {
|
||||
if(timeStyle != UDAT_PATTERN) {
|
||||
if(locale == 0) {
|
||||
fmt = DateFormat::createDateTimeInstance((DateFormat::EStyle)dateStyle,
|
||||
(DateFormat::EStyle)timeStyle);
|
||||
|
@ -167,9 +167,16 @@ typedef enum UDateFormatStyle {
|
||||
|
||||
/** No style */
|
||||
UDAT_NONE = -1,
|
||||
/** for internal API use only */
|
||||
UDAT_IGNORE = -2
|
||||
|
||||
/**
|
||||
* Use the pattern given in the parameter to udat_open
|
||||
* @see udat_open
|
||||
* @draft ICU 50
|
||||
*/
|
||||
UDAT_PATTERN = -2,
|
||||
|
||||
/** @internal alias to UDAT_PATTERN */
|
||||
UDAT_IGNORE = UDAT_PATTERN
|
||||
} UDateFormatStyle;
|
||||
|
||||
/* Cannot use #ifndef U_HIDE_DRAFT_API for UDateFormatContextType and UDateFormatContextValue
|
||||
@ -581,9 +588,12 @@ udat_toCalendarDateField(UDateFormatField field);
|
||||
* @param timeStyle The style used to format times; one of UDAT_FULL, UDAT_LONG,
|
||||
* UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, or UDAT_NONE (relative time styles
|
||||
* are not currently supported).
|
||||
* When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle.
|
||||
* @param dateStyle The style used to format dates; one of UDAT_FULL, UDAT_LONG,
|
||||
* UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, UDAT_FULL_RELATIVE, UDAT_LONG_RELATIVE,
|
||||
* UDAT_MEDIUM_RELATIVE, UDAT_SHORT_RELATIVE, or UDAT_NONE. As currently implemented,
|
||||
* UDAT_MEDIUM_RELATIVE, UDAT_SHORT_RELATIVE, or UDAT_NONE.
|
||||
* When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle.
|
||||
* As currently implemented,
|
||||
* relative date formatting only affects a limited range of calendar days before or
|
||||
* after the current date, based on the CLDR <field type="day">/<relative> data: For
|
||||
* example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range,
|
||||
|
@ -436,7 +436,7 @@ print_month(UCalendar *c,
|
||||
/* ========== Generate the header containing the month and year */
|
||||
|
||||
/* Open a formatter with a month and year only pattern */
|
||||
dfmt = udat_open(UDAT_IGNORE,UDAT_IGNORE,NULL,NULL,0,pat, len,status);
|
||||
dfmt = udat_open(UDAT_PATTERN,UDAT_PATTERN,NULL,NULL,0,pat, len,status);
|
||||
|
||||
/* Format the date */
|
||||
udat_format(dfmt, ucal_getMillis(c, status), s, BUF_SIZE, 0, status);
|
||||
@ -559,7 +559,7 @@ print_year(UCalendar *c,
|
||||
/* ========== Generate the header containing the year (only) */
|
||||
|
||||
/* Open a formatter with a month and year only pattern */
|
||||
dfmt = udat_open(UDAT_IGNORE,UDAT_IGNORE,NULL,NULL,0,pat, len, status);
|
||||
dfmt = udat_open(UDAT_PATTERN,UDAT_PATTERN,NULL,NULL,0,pat, len, status);
|
||||
|
||||
/* Format the date */
|
||||
udat_format(dfmt, ucal_getMillis(left_cal, status), s, BUF_SIZE, 0, status);
|
||||
|
@ -250,7 +250,7 @@ static void TestDateFormat()
|
||||
status=U_ZERO_ERROR;
|
||||
log_verbose("\nTesting the udat_openPattern with a specified pattern\n");
|
||||
/*for french locale */
|
||||
fr_pat=udat_open(UDAT_IGNORE, UDAT_IGNORE,"fr_FR",NULL,0,temp, u_strlen(temp), &status);
|
||||
fr_pat=udat_open(UDAT_PATTERN, UDAT_PATTERN,"fr_FR",NULL,0,temp, u_strlen(temp), &status);
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_err("FAIL: Error in creating a date format using udat_openPattern \n %s\n",
|
||||
|
@ -1,6 +1,6 @@
|
||||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2010, International Business Machines Corporation and
|
||||
* Copyright (c) 1997-2012, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
/********************************************************************************
|
||||
@ -57,7 +57,7 @@ void TestTwoDigitYearDSTParse()
|
||||
|
||||
pattern=(UChar*)malloc(sizeof(UChar) * (strlen("EEE MMM dd HH:mm:ss.SSS zzz yyyy G")+1 ));
|
||||
u_uastrcpy(pattern, "EEE MMM dd HH:mm:ss.SSS zzz yyyy G");
|
||||
fullFmt= udat_open(UDAT_IGNORE, UDAT_IGNORE,"en_US",NULL,0,pattern, u_strlen(pattern),&status);
|
||||
fullFmt= udat_open(UDAT_PATTERN, UDAT_PATTERN,"en_US",NULL,0,pattern, u_strlen(pattern),&status);
|
||||
if(U_FAILURE(status)) {
|
||||
log_data_err("FAIL: Error in creating a date format using udat_openPattern %s - (Are you missing data?)\n",
|
||||
myErrorName(status) );
|
||||
@ -66,7 +66,7 @@ void TestTwoDigitYearDSTParse()
|
||||
log_verbose("PASS: creating dateformat using udat_openPattern() succesful\n");
|
||||
|
||||
u_uastrcpy(pattern, "dd-MMM-yy h:mm:ss 'o''clock' a z");
|
||||
fmt= udat_open(UDAT_IGNORE,UDAT_IGNORE,"en_US", NULL, 0,pattern, u_strlen(pattern), &status);
|
||||
fmt= udat_open(UDAT_PATTERN,UDAT_PATTERN,"en_US", NULL, 0,pattern, u_strlen(pattern), &status);
|
||||
|
||||
|
||||
s=(UChar*)malloc(sizeof(UChar) * (strlen("03-Apr-04 2:20:47 o'clock AM PST")+1) );
|
||||
@ -200,7 +200,7 @@ void TestRunTogetherPattern985()
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
pattern=(UChar*)malloc(sizeof(UChar) * (strlen("yyyyMMddHHmmssSSS")+1) );
|
||||
u_uastrcpy(pattern, "yyyyMMddHHmmssSSS");
|
||||
format = udat_open(UDAT_IGNORE, UDAT_IGNORE, NULL, NULL, 0,pattern, u_strlen(pattern), &status);
|
||||
format = udat_open(UDAT_PATTERN, UDAT_PATTERN, NULL, NULL, 0,pattern, u_strlen(pattern), &status);
|
||||
if(U_FAILURE(status)){
|
||||
log_data_err("FAIL: Error in date format construction with pattern: %s - (Are you missing data?)\n", myErrorName(status));
|
||||
return;
|
||||
@ -316,7 +316,7 @@ void TestQuotePattern161()
|
||||
/* this is supposed to open default date format, but later on it treats it like it is "en_US"
|
||||
- very bad if you try to run the tests on machine where default locale is NOT "en_US" */
|
||||
/* format= udat_openPattern(pattern, u_strlen(pattern), NULL, &status); */
|
||||
format= udat_open(UDAT_IGNORE, UDAT_IGNORE,"en_US", NULL, 0,pattern, u_strlen(pattern), &status);
|
||||
format= udat_open(UDAT_PATTERN, UDAT_PATTERN,"en_US", NULL, 0,pattern, u_strlen(pattern), &status);
|
||||
if(U_FAILURE(status)){
|
||||
log_data_err("error in udat_open: %s - (Are you missing data?)\n", myErrorName(status));
|
||||
return;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2011, International Business Machines Corporation and
|
||||
* Copyright (c) 1997-2012, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
/********************************************************************************
|
||||
@ -160,7 +160,7 @@ void Test4056591()
|
||||
|
||||
|
||||
u_uastrcpy(pat, "yyMMdd");
|
||||
def = udat_open(UDAT_IGNORE,UDAT_IGNORE,NULL, NULL, 0, pat, u_strlen(pat), &status);
|
||||
def = udat_open(UDAT_PATTERN,UDAT_PATTERN,NULL, NULL, 0, pat, u_strlen(pat), &status);
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_data_err("FAIL: error in creating the dateformat using u_openPattern(): %s - (Are you missing data?)\n", myErrorName(status));
|
||||
@ -211,7 +211,7 @@ void Test4059917()
|
||||
u_uastrcpy(tzID, "PST");
|
||||
u_uastrcpy(pattern, "yyyy/MM/dd");
|
||||
log_verbose("%s\n", austrdup(pattern) );
|
||||
def = udat_open(UDAT_IGNORE,UDAT_IGNORE,NULL,tzID,-1,pattern, u_strlen(pattern),&status);
|
||||
def = udat_open(UDAT_PATTERN,UDAT_PATTERN,NULL,tzID,-1,pattern, u_strlen(pattern),&status);
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_data_err("FAIL: error in creating the dateformat using openPattern: %s - (Are you missing data?)\n", myErrorName(status));
|
||||
@ -224,7 +224,7 @@ void Test4059917()
|
||||
udat_close(def);
|
||||
|
||||
u_uastrcpy(pattern, "yyyyMMdd");
|
||||
def = udat_open(UDAT_IGNORE,UDAT_IGNORE,NULL,tzID,-1,pattern, u_strlen(pattern),&status);
|
||||
def = udat_open(UDAT_PATTERN,UDAT_PATTERN,NULL,tzID,-1,pattern, u_strlen(pattern),&status);
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_err("FAIL: error in creating the dateformat using openPattern: %s\n", myErrorName(status));
|
||||
@ -285,7 +285,7 @@ void Test4060212()
|
||||
status = U_ZERO_ERROR;
|
||||
u_uastrcpy(tzID, "PST");
|
||||
|
||||
formatter = udat_open(UDAT_IGNORE,UDAT_IGNORE,"en_US",tzID,-1,pattern, u_strlen(pattern), &status);
|
||||
formatter = udat_open(UDAT_PATTERN,UDAT_PATTERN,"en_US",tzID,-1,pattern, u_strlen(pattern), &status);
|
||||
pos=0;
|
||||
myDate = udat_parse(formatter, dateString, u_strlen(dateString), &pos, &status);
|
||||
|
||||
@ -329,7 +329,7 @@ void Test4061287()
|
||||
u_uastrcpy(pattern, "dd/mm/yyyy");
|
||||
status = U_ZERO_ERROR;
|
||||
log_verbose("Testing parsing by changing the attribute lenient\n");
|
||||
df = udat_open(UDAT_IGNORE,UDAT_IGNORE,NULL,NULL,0,pattern, u_strlen(pattern),&status);
|
||||
df = udat_open(UDAT_PATTERN,UDAT_PATTERN,NULL,NULL,0,pattern, u_strlen(pattern),&status);
|
||||
if(U_FAILURE(status)){
|
||||
log_data_err("ERROR: failure in open pattern of test4061287: %s - (Are you missing data?)\n", myErrorName(status));
|
||||
return;
|
||||
@ -448,7 +448,7 @@ void Test4162071()
|
||||
u_uastrcpy(format, "EEE', 'dd-MMM-yyyy HH:mm:ss z"); /* RFC 822/1123 */
|
||||
status = U_ZERO_ERROR;
|
||||
/* Can't hardcode the result to assume the default locale is "en_US". */
|
||||
df = udat_open(UDAT_IGNORE,UDAT_IGNORE,"en_US",NULL,0,format, u_strlen(format),&status);
|
||||
df = udat_open(UDAT_PATTERN,UDAT_PATTERN,"en_US",NULL,0,format, u_strlen(format),&status);
|
||||
if(U_FAILURE(status)){
|
||||
log_data_err("ERROR: couldn't create date format: %s\n", myErrorName(status));
|
||||
return;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2007-2010, International Business Machines
|
||||
* Copyright (C) 2007-2012, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
@ -325,7 +325,7 @@ static void TestBuilder() {
|
||||
/* get a pattern for an abbreviated month and day */
|
||||
length = udatpg_getBestPattern(generator, skeleton, 4,
|
||||
pattern, patternCapacity, &status);
|
||||
formatter = udat_open(UDAT_IGNORE, UDAT_DEFAULT, locale, timeZoneGMT, -1,
|
||||
formatter = udat_open(UDAT_PATTERN, UDAT_PATTERN, locale, timeZoneGMT, -1,
|
||||
pattern, length, &status);
|
||||
if (formatter==NULL) {
|
||||
log_err("Failed to initialize the UDateFormat of the sample code in Userguide.\n");
|
||||
|
@ -140,7 +140,7 @@ static const Field names_UDateFormatStyle[] =
|
||||
/*
|
||||
* negative enums.. leave out for now.
|
||||
FIELD_NAME_STR( LEN_UDAT, UDAT_NONE ),
|
||||
FIELD_NAME_STR( LEN_UDAT, UDAT_IGNORE ),
|
||||
FIELD_NAME_STR( LEN_UDAT, UDAT_PATTERN ),
|
||||
*/
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user