java - Brasilia Summer Time transition at 2037-10-18 -


timezone.setdefault(timezone.gettimezone("bet")); locale.setdefault(locale.english);  simpledateformat sdf1 = new simpledateformat("yyyy-mm-dd hh:mm:ss.sss"); simpledateformat sdf2 = new simpledateformat("yyyy-mm-dd hh:mm:ss.sss zzzz");  date d0 = sdf1.parse("2037-10-17 23:00:00.000"); date d1 = sdf1.parse("2037-10-17 23:00:00.001"); date d2 = sdf1.parse("2037-10-17 23:59:59.999"); date d3 = sdf1.parse("2037-10-18 00:00:00.000"); date d4 = sdf1.parse("2037-10-18 00:00:00.001"); date d5 = sdf1.parse("2037-10-18 00:59:59.999"); date d6 = sdf1.parse("2037-10-18 01:00:00.000"); date d7 = sdf1.parse("2037-10-18 01:00:00.001"); date d8 = sdf1.parse("2037-10-18 01:59:59.999"); date d9 = sdf1.parse("2037-10-18 02:00:00.000");  system.out.println(sdf2.format(d0) + "(" + d0.gettime() + "), dst: " + timezone.getdefault().indaylighttime(d0) + ", offset: " + timezone.getdefault().getoffset(d0.gettime())); system.out.println(sdf2.format(d1) + "(" + d1.gettime() + "), dst: " + timezone.getdefault().indaylighttime(d1) + ", offset: " + timezone.getdefault().getoffset(d1.gettime())); system.out.println(sdf2.format(d2) + "(" + d2.gettime() + "), dst: " + timezone.getdefault().indaylighttime(d2) + ", offset: " + timezone.getdefault().getoffset(d2.gettime())); system.out.println(sdf2.format(d3) + "(" + d3.gettime() + "), dst: " + timezone.getdefault().indaylighttime(d3) + ", offset: " + timezone.getdefault().getoffset(d3.gettime())); system.out.println(sdf2.format(d4) + "(" + d4.gettime() + "), dst: " + timezone.getdefault().indaylighttime(d4) + ", offset: " + timezone.getdefault().getoffset(d4.gettime())); system.out.println(sdf2.format(d5) + "(" + d5.gettime() + "), dst: " + timezone.getdefault().indaylighttime(d5) + ", offset: " + timezone.getdefault().getoffset(d5.gettime())); system.out.println(sdf2.format(d6) + "(" + d6.gettime() + "), dst: " + timezone.getdefault().indaylighttime(d6) + ", offset: " + timezone.getdefault().getoffset(d6.gettime())); system.out.println(sdf2.format(d7) + "(" + d7.gettime() + "), dst: " + timezone.getdefault().indaylighttime(d7) + ", offset: " + timezone.getdefault().getoffset(d7.gettime())); system.out.println(sdf2.format(d8) + "(" + d8.gettime() + "), dst: " + timezone.getdefault().indaylighttime(d8) + ", offset: " + timezone.getdefault().getoffset(d8.gettime())); system.out.println(sdf2.format(d9) + "(" + d9.gettime() + "), dst: " + timezone.getdefault().indaylighttime(d9) + ", offset: " + timezone.getdefault().getoffset(d9.gettime())); 

the out put

2037-10-17 23:00:00.000 brasilia time(2139444000000), dst: false, offset: -10800000 2037-10-17 23:00:00.001 brasilia time(2139444000001), dst: false, offset: -10800000 2037-10-17 23:59:59.999 brasilia time(2139447599999), dst: false, offset: -10800000 2037-10-18 01:00:00.000 brasilia summer time(2139447600000), dst: true, offset: -7200000 2037-10-18 00:00:00.001 brasilia time(2139447600001), dst: true, offset: -10800000 2037-10-18 00:59:59.999 brasilia time(2139451199999), dst: true, offset: -10800000 2037-10-18 01:00:00.000 brasilia summer time(2139447600000), dst: true, offset: -7200000 2037-10-18 00:00:00.001 brasilia time(2139447600001), dst: true, offset: -10800000 2037-10-18 00:59:59.999 brasilia time(2139451199999), dst: true, offset: -10800000 2037-10-18 02:00:00.000 brasilia summer time(2139451200000), dst: true, offset: -7200000 

this code print out the date times around "2037-10-18 00:00:000 brasilia time", result shows out "2037-10-18 00:00:000 brasilia time" should "2037-10-18 01:00:00.000 brasilia summer time" means brasilia entered summer time in moment.

my question why between "2037-10-18 00:00:00.001 brasilia time" , "2037-10-18 00:59:59.999 brasilia time" time zone offset still using standard time offset. bug of jdk time zone data or time zone works way.

my code using offset decide whether or not there dst transition between 2 dates. "2037-10-18 01:00:00.000 brasilia summer time" , "2037-10-18 00:59:59.999 brasilia time" 2 dates not work here.

i can change use "timezone.getdefault().indaylighttime(date date)" decide if there transition, still want know if it's bug of jdk.

i tried step through code debugger , seems problem timezone , switch itself: brt brst switches 00:00:00 01:00:00 @ midnight, meaning hour in between doesn't exist.

from debugging problem seems in gregoriancalendar#computetime() in following line:

millis -= zoneoffsets[0] + zoneoffsets[1]; 

before line millis time since epoch has been calculated parsed date , different 00:00:00 (213946800000) , 01:00:00 (2139440400000). in both cases zoneoffsets[0] -10800000 raw offset utc.

the difference in zoneoffsets[1]: 00:00:00 0 01:00:00 is 3600000, i.e. 1 hour. reason seems internal call indaylighttime( new date(millis) ) returns false 00:00:00 (pre-dst) true 01:00:00 (which first hour of dst). hence final time same since add 10800000 millis subtract 3600000 millis higher value higher 3600000 millis :)

in end date same milli time.

when formatting date again seems formatter check milli time against timezone , every time correspond 00:00:00,000 - 59:59:59,999, i.e. in both time zones assumed have dstoffset of 0 instead of 3600000 , hence different time zones printed.

edit: when comparing 01:00:00.000 , 01:00:00.001 seems if there might bug in zoneinfo.getoffsets(time, offsets, type) returns dst offset of 360000 former , 0 latter while when filling fields of calendar inside formatter both assume dst.

edit 2: when changing parser format accept timezone shortcuts can observe same behavior, i.e. 00:00:00.000 brt , 01:00:00.000 brst parsed 2139447600000 , formatted again 01:00:00.000 brst while 00:00:00.001 brt , 01:00:00.001 brst parsed 2139447600001 , formatted 00:00:00.001 brt - in correct.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -