Skip to content

Commit 53922f2

Browse files
committed
Convert non-ASCII TimeZone
Where the name of the time-zone has Arabic or other digits Fixes #381
1 parent 262448b commit 53922f2

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

RELEASE-NOTES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ This is the same license as all of Apache, plus other open source projects such
1313
** Please also check out our related projects **
1414
** http://www.joda.org/joda-time/related.html **
1515

16+
Changes in 2.9.6
17+
----------------
18+
- Support conversion of old TimeZone where name has digits other than ASCII [#381]
19+
20+
1621
Changes in 2.9.5
1722
----------------
1823
- Add Norwegian period translations [#378]

src/main/java/org/joda/time/DateTimeZone.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,12 @@ public static DateTimeZone forTimeZone(TimeZone zone) {
362362
convId = id;
363363
if (convId.startsWith("GMT+") || convId.startsWith("GMT-")) {
364364
convId = convId.substring(3);
365+
if (convId.length() > 2) {
366+
char firstDigit = convId.charAt(1);
367+
if (firstDigit > '9' && Character.isDigit(firstDigit)) {
368+
convId = convertToAsciiNumber(convId);
369+
}
370+
}
365371
int offset = parseOffset(convId);
366372
if (offset == 0L) {
367373
return DateTimeZone.UTC;
@@ -374,6 +380,18 @@ public static DateTimeZone forTimeZone(TimeZone zone) {
374380
throw new IllegalArgumentException("The datetime zone id '" + id + "' is not recognised");
375381
}
376382

383+
private static String convertToAsciiNumber(String convId) {
384+
StringBuilder buf = new StringBuilder(convId);
385+
for (int i = 0; i < buf.length(); i++) {
386+
char ch = buf.charAt(i);
387+
int digit = Character.digit(ch, 10);
388+
if (digit >= 0) {
389+
buf.setCharAt(i, (char) ('0' + digit));
390+
}
391+
}
392+
return buf.toString();
393+
}
394+
377395
//-----------------------------------------------------------------------
378396
/**
379397
* Gets the zone using a fixed offset amount.

src/test/java/org/joda/time/TestDateTimeZone.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ public void testForTimeZone_TimeZone() {
394394

395395
zone = DateTimeZone.forTimeZone(TimeZone.getTimeZone("EST"));
396396
assertEquals("America/New_York", zone.getID());
397+
398+
TimeZone tz = TimeZone.getTimeZone("GMT-08:00");
399+
tz.setID("GMT-\u0660\u0668:\u0660\u0660");
400+
zone = DateTimeZone.forTimeZone(tz);
401+
assertEquals("-08:00", zone.getID());
397402
}
398403

399404
public void testFromTimeZoneInvalid() throws Exception {

0 commit comments

Comments
 (0)