Below is the logic we are trying to code.
We have startdate(SD) and enddate(ED) in UTC, we first convert startdate to PST(SD_PST) and then add difference between startdate and enddate to the PST converted startdate (SD_PST+(ED minus SD)) to obtain ED_PST(end date in PST)
Below is our partial code.
Duration duration = Duration.between(sud.getStartTime().toInstant(),
sud.getEndTime().toInstant()); // Sun Mar 12 08:00:00 PDT 2017 - [sud.getStartTime()] & Sun Mar 12 09:00:00 PDT 2017 - [sud.getEndTime()]
ZonedDateTime ldt = ZonedDateTime.ofInstant(convertToPst(sud.getStartTime()).toInstant(),
ZoneId.systemDefault()); // ldt now is 2017-03-12T1:00-08:00[PST8PDT]
ldt = ldt.plusSeconds(duration.getSeconds()); // ldt now is 2017-03-12T3:00-07:00[PST8PDT] , duration.getSeconds() is 3600
Date f2 = Date.from(ldt.toInstant()); // output Sun Mar 12 03:00:00 PDT 2017
I get it that daylight saving is affecting the output, but I am unable to understand how 1 hour extra is added, my expected output is 2017-03-12T2:00-07:00[PST8PDT]
(I understand that in dst -7 hours gets added).
Please help me understand the output.