datetime - java.time discovering I'm in the daylight savings "gap" -
i have delivery time window 01:40 2:10 every day. that's localtime in uk have daylight savings time , if use
zoneddatetime.of(localdate(2015, 3, 29), localtime.of(1, 40), zoneid.of("europe/london"))
i 02:40 on day in question because switch daylight savings causes gap. end negative delivery time window of 2:40 - 2:10 on day in question. guess can detect converting localtime see if hours have stayed same, there smarter way of spotting local zoned datetime conversion has fallen "in gap"?
and if have fallen in gap how find out gap - in case 1:00 - 2:00
you can query:
localdatetime ldt = localdate.of(2015, 3, 29).attime(localtime.of(1, 40)); zoneoffsettransition conflict = zoneid.of("europe/london").getrules().gettransition(ldt); boolean gap = (conflict != null) && conflict.isgap(); // true
attention: documentation not correct, code example works.
about second question:
you can ask conflict transition. offers methods getdatetimeafter()
, getdatetimebefore()
returning appropriate local timestamp of type localdatetime
.
Comments
Post a Comment