[PATCH] Support for UTC Zones with TimeZone.getTimeZone() (original) (raw)

Mohamed Naufal naufal11 at gmail.com
Sat Dec 16 10:27:45 UTC 2017


Hi,

I noticed that with the following data:

LocalDateTime ldt = LocalDateTime.parse("2017-01-01T00:00:00"); ZonedDateTime dt1 = ZonedDateTime.of(ldt, ZoneId.of("GMT+10")); ZonedDateTime dt2 = ZonedDateTime.of(ldt, ZoneId.of("UTC+10"));

dt1.equals(dt2) returns true as expected, but with:

GregorianCalendar gc1 = GregorianCalendar.from(dt1); GregorianCalendar gc2 = GregorianCalendar.from(dt2);

gc1.equals(gc2) returns false.

Looking at the code, I see when a GregorianCalendar is being constructed, TimeZone.getTimeZone() gets called, but it doesn't recognise UTC time-zones with offsets, and falls back to GMT(+0), whereas ZoneId treats GMT and UTC based zones equivalently.

PFA a patch to fix this.

Thank you, Naufal -------------- next part -------------- diff -r 65464a307408 src/java.base/share/classes/java/util/TimeZone.java --- a/src/java.base/share/classes/java/util/TimeZone.java Thu Aug 03 18:56:59 2017 +0000 +++ b/src/java.base/share/classes/java/util/TimeZone.java Sat Dec 16 10:10:14 2017 +0000 @@ -782,7 +782,8 @@ private static volatile TimeZone defaultTimeZone;

 static final String         GMT_ID        = "GMT";

@@ -799,9 +800,9 @@ int length;

     // Error if the length of id isn't long enough or id doesn't

@@ -815,7 +816,7 @@ return zi; }



More information about the core-libs-dev mailing list