Skip to content

Commit

Permalink
Merge pull request JodaOrg#332 from pandacalculus/master
Browse files Browse the repository at this point in the history
fixes bug in timezone resolution that prevents some timezones being resolved
  • Loading branch information
jodastephen committed Dec 7, 2015
2 parents 9ced54c + 635830e commit f5bd8f5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f5bd8f5

Please sign in to comment.