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

Mohamed Naufal naufal11 at gmail.com
Thu Dec 21 01:44:51 UTC 2017


Hi Naoto,

Thank you for the feedback, I'll send an updated patch shortly.

Best regards,
Naufal

On 21 December 2017 at 05:19, Naoto Sato <naoto.sato at oracle.com> wrote:

> Hi Naufal,
>
> Thank you for the patch. It does seem to be a bug. However, TimeZone class
> defines CustomID as "GMT+(offset)", so I'd rather fix it in
> GregorianCalendar.from() to recognize those "UTC+offset" zones.
>
> Naoto
>
>
> On 12/16/17 2:27 AM, Mohamed Naufal wrote:
>
>> 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
>>
>>


More information about the core-libs-dev mailing list