Daylight Savings Time Gap/Overlap definitions? Whe

2019-01-19 08:38发布

问题:

  1. What is the definition of Daylight Savings Time 'Overlap' & 'Gap'? I have a hazy understanding of them, so I'd like to confirm... What does it mean to be "within" either of them?

  2. What does it mean to "correct" for DST Gap or DST Overlap? When does a time need correcting, and when does it not need correcting?

The above questions are language-agnostic, but an example of their application I have is:

  1. When to call org.joda.time.LocalDateTime#correctDstTransition?

    Correct date in case of DST overlap.The Date object created has exactly the same fields as this date-time, except when the time would be invalid due to a daylight savings gap. In that case, the time will be set to the earliest valid time after the gap. In the case of a daylight savings overlap, the earlier instant is selected.

回答1:

Much of this is already explained in the DST tag wiki, but I will answer your specific questions.

What is the definition of Daylight Savings Time 'Overlap' & 'Gap'?
...
What does it mean to be "within" either of them?

When daylight saving time begins, the local time is advanced - usually by one hour. This creates a "gap" in the values of local time in that time zone.

  • For example, when DST starts in the United States, the clocks tick from 1:59 AM to 3:00 AM. Any local time value from 2:00 AM through 2:59 AM would be considered to be "within the gap".

  • Note that values in the gap are non-existent. They do not occur in the real world, unless a clock was not correctly advanced. In practice, one typically gets to a value within the gap by adding or subtracting an elapsed time value from another local time.

When daylight saving time ends, the local time is retracted by the same amount that was added when it began (again, usually 1 hour). This creates an "overlap" in the local time values of that time zone.

  • For example, when DST ends in the United states, the clocks tick from 1:59 AM back to 1:00 AM. Any local time value from 1:00 AM through 1:59 AM is ambiguous if there is no additional qualifying information.

  • To be "within the overlap" means that you have a value that is potentially ambiguous because it falls into this range.

  • Such values may belong to the daylight time occurrence (which comes first sequentially), or may belong to the standard time occurrence (which comes second sequentially).

What does it mean to "correct" for DST Gap or DST Overlap?

Correcting for the gap means to ensure that the local time value is valid by possible moving it to a different value. There are various schemes in use for doing so, but the most common and most sensible is to advance the local time value by the amount of the gap.

  • For example, if you have a local time of 2:30 AM, and you determine it to occur on the day of the spring-forward transition in the United States, then it falls into the gap. Advance it to 3:30 AM.

  • This approach tends to work well because simulates the act of a human manually advancing an analog clock - or rather, correcting with the idea that it had not been properly advanced.

Correcting for the overlap means to ensure that all local times are well qualified. Usually this is accomplished by assigning a time zone offset to all values.

  • In the case of a value that is not ambiguous, the offset is deterministic.

  • In the case of a value that falls within the overlap on the day of a fall-back transition, it often makes sense to choose the first of the two possible values (which will have the daylight time offset). This is because time moves in a forward direction. However, there are sometimes cases where it makes sense to use a different rule, so YMMV.

When does a time need correcting, and when does it not need correcting?

If you are attempting to work with time as an instantaneous value, such as determining the elapsed duration between two values, adding an elapsed time to a specific value, or when converting to UTC, then you need to correct for gaps and overlaps as they occur.

If you are only working with user input and output, always displaying the exact value a user gave you (and never using it for math or time zone conversions) then you do not need to correct for gaps and overlaps.

Also, if you are working with date-only values, or time-only values, then you should not be applying time zone information at all, and thus do not need to correct for gaps and overlaps.

Lastly, if you are working strictly with Coordinated Universal Time (UTC), which has no daylight saving time, then you do not need to correct for gaps and overlaps.

When to call org.joda.time.LocalDateTime#correctDstTransition?

You don't. That method is private, and is called by other Joda-time functions as needed.