1º Day Of Daylight Saving Time Java And JS Showing A Different Behavior
Solution 1:
Basically, that answer was incorrect as far as I can see. I'm not entirely happy with the Java version, even.
Fundamentally, you're trying to construct a local date/time which never happened. Translating from local time to UTC is always tricky, as there are three possibilities:
- Unambiguous mapping, which in most time zones is the case for all but two hours per year
- Ambiguous mapping, during a backward transition, where the same local time period occurs twice (e.g. local time goes 12:59am, 1am, ... 1:59am, 1am, 1:59am, 2am)
- "Gap" mapping, where a local time period simply doesn't exist (e.g. local time goes 12:59am, 2am, 2:01am)
Brazil moves its clocks forward at midnight, so local time actually goes:
October 20th 11:58pm
October 20th 11:59pm
October 21st 01:00am
October 21st 01:01am
The local time you've asked for simply never happened. It looks like Java is just assuming you want to roll it forward... whereas JavaScript is getting confused :( The JavaScript result would be more understandable (but still incorrect) if you were asking for midnight at the start of February 16th 2013, for example - where the clocks would have gone back to 11pm on the 15th. 12am on the 16th is unambiguous, as it can only happen after the "second" 11pm-11:59pm on the 15th.
A good date/time API (in my very biased view) would force you to say how you want to happen ambiguity and gaps when you do the conversion.
Post a Comment for "1º Day Of Daylight Saving Time Java And JS Showing A Different Behavior"