diff --git a/src/main/java/org/joda/time/format/DateTimeFormatterBuilder.java b/src/main/java/org/joda/time/format/DateTimeFormatterBuilder.java index c5af255c3..51ae9f481 100644 --- a/src/main/java/org/joda/time/format/DateTimeFormatterBuilder.java +++ b/src/main/java/org/joda/time/format/DateTimeFormatterBuilder.java @@ -2618,14 +2618,16 @@ public int parseInto(DateTimeParserBucket bucket, CharSequence text, int positio } static int csCompare(CharSequence text, int position, String search) { - int compareLen = Math.min(text.length() - position, search.length()); + int matchLen = text.length() - position; + int searchLen = search.length(); + int compareLen = Math.min(matchLen, searchLen); for (int i = 0; i < compareLen; i++) { int result = search.charAt(i) - text.charAt(position + i); if (result != 0) { return result; } } - return 0; + return searchLen - matchLen; } static boolean csStartsWith(CharSequence text, int position, String search) { diff --git a/src/test/java/org/joda/time/format/TestDateTimeFormatterBuilder.java b/src/test/java/org/joda/time/format/TestDateTimeFormatterBuilder.java index 602bac959..6436a274f 100644 --- a/src/test/java/org/joda/time/format/TestDateTimeFormatterBuilder.java +++ b/src/test/java/org/joda/time/format/TestDateTimeFormatterBuilder.java @@ -435,6 +435,26 @@ public void test_printParseZoneDawsonCreek() { // clashes with shorter Dawson assertEquals(dt, f.parseDateTime("2007-03-04 12:30 America/Dawson_Creek")); } + public void test_printParseZoneEtcGMT() { + DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder() + .appendPattern("yyyy-MM-dd HH:mm ZZZ"); + DateTimeFormatter f = bld.toFormatter(); + + DateTime dt = new DateTime(2007, 3, 4, 12, 30, 0, DateTimeZone.forID("Etc/GMT")); + assertEquals("2007-03-04 12:30 Etc/GMT", f.print(dt)); + assertEquals(dt, f.parseDateTime("2007-03-04 12:30 Etc/GMT")); + } + + public void test_printParseZoneEtcGMT1() { + DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder() + .appendPattern("yyyy-MM-dd HH:mm ZZZ"); + DateTimeFormatter f = bld.toFormatter(); + + DateTime dt = new DateTime(2007, 3, 4, 12, 30, 0, DateTimeZone.forID("Etc/GMT+1")); + assertEquals("2007-03-04 12:30 Etc/GMT+1", f.print(dt)); + assertEquals(dt, f.parseDateTime("2007-03-04 12:30 Etc/GMT+1")); + } + public void test_printParseZoneBahiaBanderas() { DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder() .appendPattern("yyyy-MM-dd HH:mm ").appendTimeZoneId();