From 1487205b1a10a9d63ee9fc22a352769ee17d7467 Mon Sep 17 00:00:00 2001 From: Yoshito Umaoka Date: Tue, 16 Aug 2011 16:35:02 +0000 Subject: [PATCH] ICU-8766 Fixed a regression bug - wrong parse position with RFC822 time zone format. X-SVN-Rev: 30514 --- .../src/com/ibm/icu/text/TimeZoneFormat.java | 2 +- .../icu/dev/test/format/DateFormatTest.java | 47 ++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/TimeZoneFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/TimeZoneFormat.java index 4042aced1f1..da8bc924cf4 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/TimeZoneFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/TimeZoneFormat.java @@ -907,7 +907,7 @@ public class TimeZoneFormat extends UFormat implements Freezable return 0; } - pos.setIndex(1 + numDigits); + pos.setIndex(start + 1 + numDigits); return ((((hour * 60) + min) * 60) + sec) * 1000 * sign; } diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatTest.java index e525d4b8751..f6f0decac14 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatTest.java @@ -3771,10 +3771,9 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk { { errln((String)"FAIL: " + in + " -> " + out + " expected -> " + expected); } - } - } + public void TestFormalChineseDate() { String pattern = "y\u5e74M\u6708d\u65e5"; @@ -3803,6 +3802,50 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk { } } + public void TestParsePosition() { + class ParseTestData { + String pattern; // format pattern + String input; // input date string + int startPos; // start position + int resPos; // expected result parse position + + ParseTestData(String pattern, String dateStr) { + this.pattern = pattern; + this.input = dateStr; + this.startPos = 0; + this.resPos = dateStr.length(); + } + + ParseTestData(String pattern, String lead, String dateStr, String trail) { + this.pattern = pattern; + this.input = lead + dateStr + trail; + this.startPos = lead.length(); + this.resPos = lead.length() + dateStr.length(); + } + } + + ParseTestData[] TestData = { + new ParseTestData("yyyy-MM-dd HH:mm:ssZ", "2010-01-10 12:30:00+0500"), + new ParseTestData("yyyy-MM-dd HH:mm:ss ZZZZ", "2010-01-10 12:30:00 GMT+05:00"), + new ParseTestData("Z HH:mm:ss", "-0100 13:20:30"), + new ParseTestData("y-M-d Z", "", "2011-8-25 -0400", " Foo"), + new ParseTestData("y/M/d H:mm:ss z", "2011/7/1 12:34:00 PDT"), + new ParseTestData("y/M/d H:mm:ss z", "+123", "2011/7/1 12:34:00 PDT", " PST"), + new ParseTestData("vvvv a h:mm:ss", "Pacific Time AM 10:21:45"), + new ParseTestData("HH:mm v M/d", "111", "14:15 PT 8/10", " 12345"), + new ParseTestData("'time zone:' VVVV 'date:' yyyy-MM-dd", "xxxx", "time zone: United States Time (Los Angeles) date: 2010-02-25", "xxxx"), + }; + + for (ParseTestData data : TestData) { + SimpleDateFormat sdf = new SimpleDateFormat(data.pattern); + ParsePosition pos = new ParsePosition(data.startPos); + /* Date d = */sdf.parse(data.input, pos); + if (pos.getIndex() != data.resPos) { + errln("FAIL: Parsing [" + data.input + "] with pattern [" + data.pattern + "] returns position - " + + pos.getIndex() + ", expected - " + data.resPos); + } + } + } }