ICU-646 wall time support in icu4c - use 'v' for generic time, revert tests

X-SVN-Rev: 17946
This commit is contained in:
Doug Felt 2005-06-17 20:41:10 +00:00
parent 2717c31b16
commit 25d082e19b
7 changed files with 66 additions and 53 deletions

View file

@ -46,10 +46,10 @@
* locales use the same these unlocalized pattern characters.
*/
static const UChar gPatternChars[] = {
// GyMdkHmsSEDFwWahKzYeugAZ
// GyMdkHmsSEDFwWahKzYeugAZv
0x47, 0x79, 0x4D, 0x64, 0x6B, 0x48, 0x6D, 0x73, 0x53, 0x45,
0x44, 0x46, 0x77, 0x57, 0x61, 0x68, 0x4B, 0x7A, 0x59, 0x65,
0x75, 0x67, 0x41, 0x5A, 0
0x75, 0x67, 0x41, 0x5A, 0x76, 0
};
//------------------------------------------------------

View file

@ -534,7 +534,8 @@ SimpleDateFormat::fgPatternIndexToCalendarField[] =
/*wWa*/ UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_AM_PM,
/*hKz*/ UCAL_HOUR, UCAL_HOUR, UCAL_ZONE_OFFSET,
/*Yeu*/ UCAL_YEAR_WOY, UCAL_DOW_LOCAL, UCAL_EXTENDED_YEAR,
/*gAZ*/ UCAL_JULIAN_DAY, UCAL_MILLISECONDS_IN_DAY, UCAL_ZONE_OFFSET
/*gAZ*/ UCAL_JULIAN_DAY, UCAL_MILLISECONDS_IN_DAY, UCAL_ZONE_OFFSET,
/*v*/ UCAL_ZONE_OFFSET
};
// Map index into pattern character string to DateFormat field number
@ -547,7 +548,8 @@ SimpleDateFormat::fgPatternIndexToDateFormatField[] = {
/*wWa*/ UDAT_WEEK_OF_YEAR_FIELD, UDAT_WEEK_OF_MONTH_FIELD, UDAT_AM_PM_FIELD,
/*hKz*/ UDAT_HOUR1_FIELD, UDAT_HOUR0_FIELD, UDAT_TIMEZONE_FIELD,
/*Yeu*/ UDAT_YEAR_WOY_FIELD, UDAT_DOW_LOCAL_FIELD, UDAT_EXTENDED_YEAR_FIELD,
/*gAZ*/ UDAT_JULIAN_DAY_FIELD, UDAT_MILLISECONDS_IN_DAY_FIELD, UDAT_TIMEZONE_RFC_FIELD
/*gAZ*/ UDAT_JULIAN_DAY_FIELD, UDAT_MILLISECONDS_IN_DAY_FIELD, UDAT_TIMEZONE_RFC_FIELD,
/*v*/ UDAT_TIMEZONE_GENERIC_FIELD
};
//----------------------------------------------------------------------
@ -689,7 +691,8 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo,
// If we don't have a localized time zone name,
// then the time zone shows up as "GMT+hh:mm" or "GMT-hh:mm" (where "hh:mm" is the
// offset from GMT) regardless of how many z's were in the pattern symbol
case UDAT_TIMEZONE_FIELD: {
case UDAT_TIMEZONE_FIELD:
case UDAT_TIMEZONE_GENERIC_FIELD: {
UnicodeString str;
int32_t zoneIndex = fSymbols->getZoneIndex(cal.getTimeZone().getID(str));
if (zoneIndex == -1) {
@ -710,15 +713,17 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo,
else {
int ix;
int zsrc = fSymbols->fZoneStringsColCount;
if (zsrc < 7 && count < 3) {
count += 2; // no generic time, default to full times
}
switch (count) {
case 1: ix = zsrc == 7 ? 6 : 7; break; // short generic time
case 2: ix = zsrc == 7 ? 5 : 6; break; // long generic time
case 3: ix = cal.get(UCAL_DST_OFFSET, status) != 0 ? 4 : 2; break; // short dst/std time
default: ix = cal.get(UCAL_DST_OFFSET, status) != 0 ? 3 : 1; break; // long dst/std time
}
if (patternCharIndex == UDAT_TIMEZONE_GENERIC_FIELD && zsrc >= 7) {
ix = count < 4 ? 6 : 5;
if (zsrc > 7) {
ix += 1;
}
} else {
ix = count < 4 ? 2 : 1;
if (cal.get(UCAL_DST_OFFSET, status) != 0) {
ix += 2;
}
}
appendTo += fSymbols->fZoneStrings[zoneIndex][ix];
}
}
@ -1328,6 +1333,7 @@ int32_t SimpleDateFormat::subParse(const UnicodeString& text, int32_t& start, UC
return pos.getIndex();
case UDAT_TIMEZONE_FIELD:
case UDAT_TIMEZONE_RFC_FIELD:
case UDAT_TIMEZONE_GENERIC_FIELD:
{
// First try to parse generic forms such as GMT-07:00. Do this first
// in case localized DateFormatZoneData contains the string "GMT"
@ -1495,6 +1501,9 @@ SimpleDateFormat::matchZoneString(const UnicodeString& text, int32_t start, int3
continue;
}
// Checking long and short zones [1 & 2],
// and long and short daylight [3 & 4],
// and long and short generic [6 & 7]
const UnicodeString& zs = fSymbols->fZoneStrings[zi][i];
if (zs.length() > 0 && 0 == text.caseCompare(start, zs.length(), zs, 0)) {
break;

View file

@ -80,6 +80,7 @@ class DateFormat;
* K hour in am/pm (0~11) (Number) 0
* z time zone (Time) Pacific Standard Time
* Z time zone (RFC 822) (Number) -0800
* v time zone (generic) (Text) Pacific Time
* g Julian day (Number) 2451334
* A milliseconds in day (Number) 69540000
* ' escape for text (Delimiter) 'Date='
@ -91,10 +92,6 @@ class DateFormat;
* (Text): 4 or more, use full form, &lt;4, use short or abbreviated form if it
* exists. (e.g., "EEEE" produces "Monday", "EEE" produces "Mon")
* <P>
* (Time): 4 or 3, display long/short time zone names with daylight/standard
* designation (e.g., Pacific Daylight Time, PDT), 2 or 1, display long/short
* time zone generic names (e.g., Pacific Time, PT).
* <P>
* (Number): the minimum number of digits. Shorter numbers are zero-padded to
* this amount (e.g. if "m" produces "6", "mm" produces "06"). Year is handled
* specially; that is, if the count of 'y' is 2, the Year will be truncated to 2 digits.
@ -117,11 +114,11 @@ class DateFormat;
* \code
* Format Pattern Result
* -------------- -------
* "yyyy.MM.dd G 'at' HH:mm:ss zz" ->> 1996.07.10 AD at 15:08:56 Pacific Time
* "yyyy.MM.dd G 'at' HH:mm:ss vvvv" ->> 1996.07.10 AD at 15:08:56 Pacific Time
* "EEE, MMM d, ''yy" ->> Wed, July 10, '96
* "h:mm a" ->> 12:08 PM
* "hh 'o''clock' a, zzzz" ->> 12 o'clock PM, Pacific Daylight Time
* "K:mm a, z" ->> 0:00 PM, PT
* "K:mm a, vvv" ->> 0:00 PM, PT
* "yyyyy.MMMMM.dd GGG hh:mm aaa" ->> 1996.July.10 AD 12:08 PM
* \endcode
* </pre>

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1996-2004, International Business Machines Corporation and others. All Rights Reserved.
* Copyright (C) 1996-2005, International Business Machines Corporation and others. All Rights Reserved.
*******************************************************************************
*/
@ -341,7 +341,14 @@ typedef enum UDateFormatField {
*/
UDAT_TIMEZONE_RFC_FIELD = 23,
/**
/**
* FieldPosition and UFieldPosition selector for 'v' field alignment,
* corresponding to the UCAL_ZONE_OFFSET field.
* @draft ICU 3.4
*/
UDAT_TIMEZONE_GENERIC_FIELD = 24,
/**
* Number of FieldPosition and UFieldPosition selectors for
* DateFormat and UDateFormat.
* Valid selectors range from 0 to UDAT_FIELD_COUNT-1.
@ -349,7 +356,7 @@ typedef enum UDateFormatField {
* in the future.
* @draft ICU 3.0
*/
UDAT_FIELD_COUNT = 24
UDAT_FIELD_COUNT = 25
} UDateFormatField;

View file

@ -229,7 +229,7 @@ DateFormatTest::escape(UnicodeString& s)
/**
* This MUST be kept in sync with DateFormatSymbols.gPatternChars.
*/
static const char* PATTERN_CHARS = "GyMdkHmsSEDFwWahKzYeugAZ";
static const char* PATTERN_CHARS = "GyMdkHmsSEDFwWahKzYeugAZv";
/**
* A list of the names of all the fields in DateFormat.
@ -307,16 +307,16 @@ void DateFormatTest::TestFieldPosition() {
// Fields are given in order of DateFormat field number
const char* EXPECTED[] = {
"", "1997", "August", "13", "", "", "34", "12", "",
"Wednesday", "", "", "", "", "PM", "2", "", "PT", "", "", "", "", "", "",
"Wednesday", "", "", "", "", "PM", "2", "", "PDT", "", "", "", "", "", "", "",
"", "1997", "ao\\u00FBt", "13", "", "14", "34", "", "",
"mercredi", "", "", "", "", "", "", "", "HP (\\u00C9UA)", "", "", "", "", "", "",
"mercredi", "", "", "", "", "", "", "", "HAP (\\u00C9UA)", "", "", "", "", "", "", "",
"AD", "1997", "8", "13", "14", "14", "34", "12", "5",
"Wed", "225", "2", "33", "3", "PM", "2", "2", "PT", "1997", "4", "1997", "2450674", "52452513", "-0700",
"Wed", "225", "2", "33", "3", "PM", "2", "2", "PDT", "1997", "4", "1997", "2450674", "52452513", "-0700", "PT",
"AD", "1997", "August", "0013", "0014", "0014", "0034", "0012", "5130",
"Wednesday", "0225", "0002", "0033", "0003", "PM", "0002", "0002", "Pacific Daylight Time", "1997", "0004", "1997", "2450674", "52452513", "-0700",
"Wednesday", "0225", "0002", "0033", "0003", "PM", "0002", "0002", "Pacific Daylight Time", "1997", "0004", "1997", "2450674", "52452513", "-0700", "Pacific Time"
};
const int32_t EXPECTED_LENGTH = sizeof(EXPECTED)/sizeof(EXPECTED[0]);
@ -959,10 +959,10 @@ DateFormatTest::TestLocaleDateFormat() // Bug 495
DateFormat::FULL, Locale::getFrench());
DateFormat *dfUS = DateFormat::createDateTimeInstance(DateFormat::FULL,
DateFormat::FULL, Locale::getUS());
UnicodeString expectedFRENCH ( "lundi 15 septembre 1997 00 h 00 HP (\\u00C9UA)" );
UnicodeString expectedFRENCH ( "lundi 15 septembre 1997 00 h 00 HAP (\\u00C9UA)" );
expectedFRENCH = expectedFRENCH.unescape();
//UnicodeString expectedUS ( "Monday, September 15, 1997 12:00:00 o'clock AM PDT" );
UnicodeString expectedUS ( "Monday, September 15, 1997 12:00:00 AM PT" );
UnicodeString expectedUS ( "Monday, September 15, 1997 12:00:00 AM PDT" );
logln((UnicodeString)"Date set to : " + dateToString(testDate));
UnicodeString out;
dfFrench->format(testDate, out);
@ -1339,34 +1339,34 @@ void DateFormatTest::TestGenericTime() {
// round trip
"y/M/d H:mm zzzz", "F", "2004 01 01 01:00 PST", "2004/1/1 1:00 Pacific Standard Time",
"y/M/d H:mm zzz", "F", "2004 01 01 01:00 PST", "2004/1/1 1:00 PST",
"y/M/d H:mm zz", "F", "2004 01 01 01:00 PST", "2004/1/1 1:00 Pacific Time",
"y/M/d H:mm z", "F", "2004 01 01 01:00 PST", "2004/1/1 1:00 PT",
"y/M/d H:mm vvvv", "F", "2004 01 01 01:00 PST", "2004/1/1 1:00 Pacific Time",
"y/M/d H:mm vvv", "F", "2004 01 01 01:00 PST", "2004/1/1 1:00 PT",
// non-generic timezone string influences dst offset even if wrong for date/time
"y/M/d H:mm zzz", "pf", "2004/1/1 1:00 PDT", "2004 01 01 01:00 PDT", "2004/1/1 0:00 PST",
"y/M/d H:mm zz", "pf", "2004/1/1 1:00 PDT", "2004 01 01 01:00 PDT", "2004/1/1 0:00 Pacific Time",
"y/M/d H:mm vvvv", "pf", "2004/1/1 1:00 PDT", "2004 01 01 01:00 PDT", "2004/1/1 0:00 Pacific Time",
"y/M/d H:mm zzz", "pf", "2004/7/1 1:00 PST", "2004 07 01 02:00 PDT", "2004/7/1 2:00 PDT",
"y/M/d H:mm zz", "pf", "2004/7/1 1:00 PST", "2004 07 01 02:00 PDT", "2004/7/1 2:00 Pacific Time",
"y/M/d H:mm vvvv", "pf", "2004/7/1 1:00 PST", "2004 07 01 02:00 PDT", "2004/7/1 2:00 Pacific Time",
// generic timezone generates dst offset appropriate for local time
"y/M/d H:mm zzz", "pf", "2004/1/1 1:00 PT", "2004 01 01 01:00 PST", "2004/1/1 1:00 PST",
"y/M/d H:mm zz", "pf", "2004/1/1 1:00 PT", "2004 01 01 01:00 PST", "2004/1/1 1:00 Pacific Time",
"y/M/d H:mm vvvv", "pf", "2004/1/1 1:00 PT", "2004 01 01 01:00 PST", "2004/1/1 1:00 Pacific Time",
"y/M/d H:mm zzz", "pf", "2004/7/1 1:00 PT", "2004 07 01 01:00 PDT", "2004/7/1 1:00 PDT",
"y/M/d H:mm zz", "pf", "2004/7/1 1:00 PT", "2004 07 01 01:00 PDT", "2004/7/1 1:00 Pacific Time",
"y/M/d H:mm vvvv", "pf", "2004/7/1 1:00 PT", "2004 07 01 01:00 PDT", "2004/7/1 1:00 Pacific Time",
// daylight savings time transition edge cases.
// time to parse does not really exist, PT interpreted as earlier time
"y/M/d H:mm zzz", "pf", "2005/4/3 2:30 PT", "2005 04 03 01:30 PST", "2005/4/3 1:30 PST", // adjust earlier
"y/M/d H:mm zzz", "pf", "2005/4/3 2:30 PST", "2005 04 03 03:30 PDT", "2005/4/3 3:30 PDT",
"y/M/d H:mm zzz", "pf", "2005/4/3 2:30 PDT", "2005 04 03 01:30 PST", "2005/4/3 1:30 PST",
"y/M/d H:mm z", "pf", "2005/4/3 2:30 PT", "2005 04 03 01:30 PST", "2005/4/3 1:30 PT", // adjust earlier
"y/M/d H:mm z", "pf", "2005/4/3 2:30 PST", "2005 04 03 03:30 PDT", "2005/4/3 3:30 PT",
"y/M/d H:mm z", "pf", "2005/4/3 2:30 PDT", "2005 04 03 01:30 PST", "2005/4/3 1:30 PT",
"y/M/d H:mm vvv", "pf", "2005/4/3 2:30 PT", "2005 04 03 01:30 PST", "2005/4/3 1:30 PT", // adjust earlier
"y/M/d H:mm vvv", "pf", "2005/4/3 2:30 PST", "2005 04 03 03:30 PDT", "2005/4/3 3:30 PT",
"y/M/d H:mm vvv", "pf", "2005/4/3 2:30 PDT", "2005 04 03 01:30 PST", "2005/4/3 1:30 PT",
"y/M/d H:mm", "pf", "2005/4/3 2:30", "2005 04 03 01:30 PST", "2005/4/3 1:30",
// time to parse is ambiguous, PT interpreted as earlier time (?)
"y/M/d H:mm zzz", "pf", "2004/10/31 1:30 PT", "2004 10 31 01:30 PDT", "2004/10/31 1:30 PDT", // fail
"y/M/d H:mm zzz", "pf", "2004/10/31 1:30 PST", "2004 10 31 01:30 PST", "2004/10/31 1:30 PST",
"y/M/d H:mm zzz", "pf", "2004/10/31 1:30 PDT", "2004 10 31 01:30 PDT", "2004/10/31 1:30 PDT",
"y/M/d H:mm z", "pf", "2004/10/31 1:30 PT", "2004 10 31 01:30 PDT", "2004/10/31 1:30 PT", // fail
"y/M/d H:mm z", "pf", "2004/10/31 1:30 PST", "2004 10 31 01:30 PST", "2004/10/31 1:30 PT",
"y/M/d H:mm z", "pf", "2004/10/31 1:30 PDT", "2004 10 31 01:30 PDT", "2004/10/31 1:30 PT",
"y/M/d H:mm vvv", "pf", "2004/10/31 1:30 PT", "2004 10 31 01:30 PDT", "2004/10/31 1:30 PT", // fail
"y/M/d H:mm vvv", "pf", "2004/10/31 1:30 PST", "2004 10 31 01:30 PST", "2004/10/31 1:30 PT",
"y/M/d H:mm vvv", "pf", "2004/10/31 1:30 PDT", "2004 10 31 01:30 PDT", "2004/10/31 1:30 PT",
"y/M/d H:mm", "pf", "2004/10/31 1:30", "2004 10 31 01:30 PDT", "2004/10/31 1:30", // fail
};
const int32_t ZDATA_length = sizeof(ZDATA)/ sizeof(ZDATA[0]);
@ -1377,8 +1377,8 @@ void DateFormatTest::TestGenericTime() {
logln("cross format/parse tests");
UnicodeString basepat("yy/MM/dd H:mm ");
SimpleDateFormat formats[] = {
SimpleDateFormat(basepat + "z", en, status),
SimpleDateFormat(basepat + "zz", en, status),
SimpleDateFormat(basepat + "vvv", en, status),
SimpleDateFormat(basepat + "vvvv", en, status),
SimpleDateFormat(basepat + "zzz", en, status),
SimpleDateFormat(basepat + "zzzz", en, status)
};
@ -1431,9 +1431,9 @@ void DateFormatTest::TestGenericTimeZoneOrder() {
"zzz y/M/d H:mm", "pf", "PT 2004/1/1 1:00", "2004 01 01 01:00 PST", "PST 2004/1/1 1:00",
// standard time, generic
"y/M/d H:mm zz", "pf", "2004/1/1 1:00 PT", "2004 01 01 01:00 PST", "2004/1/1 1:00 Pacific Time",
"y/M/d zz H:mm", "pf", "2004/1/1 PT 1:00", "2004 01 01 01:00 PST", "2004/1/1 Pacific Time 1:00",
"zz y/M/d H:mm", "pf", "PT 2004/1/1 1:00", "2004 01 01 01:00 PST", "Pacific Time 2004/1/1 1:00",
"y/M/d H:mm vvvv", "pf", "2004/1/1 1:00 PT", "2004 01 01 01:00 PST", "2004/1/1 1:00 Pacific Time",
"y/M/d vvvv H:mm", "pf", "2004/1/1 PT 1:00", "2004 01 01 01:00 PST", "2004/1/1 Pacific Time 1:00",
"vvvv y/M/d H:mm", "pf", "PT 2004/1/1 1:00", "2004 01 01 01:00 PST", "Pacific Time 2004/1/1 1:00",
// dahylight time, explicit daylight/standard
"y/M/d H:mm zzz", "pf", "2004/7/1 1:00 PT", "2004 07 01 01:00 PDT", "2004/7/1 1:00 PDT",
@ -1441,9 +1441,9 @@ void DateFormatTest::TestGenericTimeZoneOrder() {
"zzz y/M/d H:mm", "pf", "PT 2004/7/1 1:00", "2004 07 01 01:00 PDT", "PDT 2004/7/1 1:00",
// daylight time, generic
"y/M/d H:mm zz", "pf", "2004/7/1 1:00 PT", "2004 07 01 01:00 PDT", "2004/7/1 1:00 Pacific Time",
"y/M/d zz H:mm", "pf", "2004/7/1 PT 1:00", "2004 07 01 01:00 PDT", "2004/7/1 Pacific Time 1:00",
"zz y/M/d H:mm", "pf", "PT 2004/7/1 1:00", "2004 07 01 01:00 PDT", "Pacific Time 2004/7/1 1:00",
"y/M/d H:mm vvvv", "pf", "2004/7/1 1:00 PT", "2004 07 01 01:00 PDT", "2004/7/1 1:00 Pacific Time",
"y/M/d vvvv H:mm", "pf", "2004/7/1 PT 1:00", "2004 07 01 01:00 PDT", "2004/7/1 Pacific Time 1:00",
"vvvv y/M/d H:mm", "pf", "PT 2004/7/1 1:00", "2004 07 01 01:00 PDT", "Pacific Time 2004/7/1 1:00",
};
const int32_t XDATA_length = sizeof(XDATA)/sizeof(XDATA[0]);
Locale en("en");

View file

@ -1138,7 +1138,7 @@ void TestMessageFormat::TestUnlimitedArgsAndSubformats() {
UnicodeString expected =
"On Nov 20, 2286 (aka 11/20/86, aka November 20, 2286) "
"at 9:46:40 AM (aka 9:46 AM, aka 9:46:40 AM PT) "
"at 9:46:40 AM (aka 9:46 AM, aka 9:46:40 AM PST) "
"there were 1,303 werjes "
"(a 8% increase over 1,202) "
"despite the Glimmung's efforts "

View file

@ -887,8 +887,8 @@ TimeZoneTest::TestDisplayName()
TimeZone::EDisplayType style;
const char *expect;
} kData[] = {
{FALSE, TimeZone::SHORT, "PT"},
{TRUE, TimeZone::SHORT, "PT"},
{FALSE, TimeZone::SHORT, "PST"},
{TRUE, TimeZone::SHORT, "PDT"},
{FALSE, TimeZone::LONG, "Pacific Standard Time"},
{TRUE, TimeZone::LONG, "Pacific Daylight Time"},