]> granicus.if.org Git - icu/commitdiff
ICU-9569 add UDAT_PATTERN and update docs
authorSteven R. Loomis <srl@icu-project.org>
Wed, 19 Sep 2012 21:26:41 +0000 (21:26 +0000)
committerSteven R. Loomis <srl@icu-project.org>
Wed, 19 Sep 2012 21:26:41 +0000 (21:26 +0000)
X-SVN-Rev: 32406

icu4c/source/i18n/udat.cpp
icu4c/source/i18n/unicode/udat.h
icu4c/source/samples/cal/cal.c
icu4c/source/test/cintltst/cdattst.c
icu4c/source/test/cintltst/cdtdptst.c
icu4c/source/test/cintltst/cdtrgtst.c
icu4c/source/test/cintltst/udatpg_test.c
icu4c/source/tools/toolutil/udbgutil.cpp

index 16d52e4d77f1589d631807e61ca35d81d017e0bf..6b811cd07b051f7bde7694c6afa92377037019d4 100644 (file)
@@ -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);
index c5bf9d68c20ffaf6a240f618f921a572912cd97d..9a023888319347e340a6a3dff27a64aef8698b4c 100644 (file)
@@ -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 &lt;field type="day"&gt;/&lt;relative&gt; data: For
  * example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range,
index ba47450e6918211641c531e44cd0b449c3009028..aa511d33bd7ca47dc5c247c12d2fda217507c5ce 100644 (file)
@@ -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);
index 175395d0b2a27e0b1a9499bd9957fdf7a4d9c31c..1df4c2654ff8beb9f1371d7d2c0af11215acda33 100644 (file)
@@ -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", 
index 48230f07ed72e3e68f6bd1e8f0ecbbb0400a10b0..e1b03dd9d4cda622cedb6baa81c617e3c7b36ed7 100644 (file)
@@ -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;
index 8c5f14fc379b232dc48da50fa6e65cfdbd24dbac..491df933131cc6be9ede87c27fcbb05ee316de8d 100644 (file)
@@ -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;
index 32c85d39ba1a4de2beb64fc42ac3e006074812b1..6bdcb1435ac833c11d4be39fb3e8b9e673a2c314 100644 (file)
@@ -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");
index f642f290b91d2fd0971ff6292b0d255f81fa285c..7ba5e8ad1082e0935638049bd80f6f0baada515e 100644 (file)
@@ -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 ),
      */
 };