In Joda Time, one can easily use the DateTimeZone.isLocalDateTimeGap
method to tell if a local date and time is invalid because it falls into the gap created by a spring-forward daylight saving time transition.
DateTimeZone zone = DateTimeZone.forID("America/New_York");
LocalDateTime ldt = new LocalDateTime(2013, 3, 10, 2, 0);
boolean inGap = zone.isLocalDateTimeGap(ldt); // true
But how do you detect the fall-back transition? In other words, if a local date and time could be ambiguous because there is an overlap, how do you detect that? I would expect something like zone.isLocalDateTimeOverlap
, but it doesn't exist. If it did, I would use it like so:
DateTimeZone zone = DateTimeZone.forID("America/New_York");
LocalDateTime ldt = new LocalDateTime(2013, 11, 3, 1, 0);
boolean overlaps = zone.isLocalDateTimeOverlap(ldt); // true
The Joda-Time documentation is clear that if there is an overlap during conversions, it will take the earlier possibility unless told otherwise. But it doesn't say how to detect that behavior.