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
/** * Returns a string describing this object. * * @return a string for debugging, not null */ @Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append("Transition[") .append(isGap() ? "Gap" : "Overlap") .append(" at ") .append(transition) .append(offsetBefore) .append(" to ") .append(offsetAfter) .append(']'); return buf.toString(); }
/** * Returns a string describing this object. * * @return a string for debugging, not null */ @Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append("Transition[") .append(isGap() ? "Gap" : "Overlap") .append(" at ") .append(transition) .append(offsetBefore) .append(" to ") .append(offsetAfter) .append(']'); return buf.toString(); }
/** * Gets the valid offsets during this transition. * <p> * A gap will return an empty list, while an overlap will return both offsets. * * @return the list of valid offsets */ List<ZoneOffset> getValidOffsets() { if (isGap()) { return Collections.emptyList(); } return Arrays.asList(getOffsetBefore(), getOffsetAfter()); }
/** * Gets the valid offsets during this transition. * <p> * A gap will return an empty list, while an overlap will return both offsets. * * @return the list of valid offsets */ List<ZoneOffset> getValidOffsets() { if (isGap()) { return Collections.emptyList(); } return Arrays.asList(getOffsetBefore(), getOffsetAfter()); }
LocalDateTime ldt = LocalDateTime.of(2015, 3, 29, 2, 30, 0, 0); ZoneRules rules = ZoneId.of("Europe/Berlin").getRules(); ZoneOffsetTransition conflict = rules.getTransition(ldt); if (conflict != null && conflict.isGap()) { ldt = conflict.getDateTimeAfter(); } System.out.println(ldt); // 2015-03-29T03:00
localTransitionOffsetList.add(baseWallOffset); for (ZoneOffsetTransition trans : transitionList) { if (trans.isGap()) { localTransitionList.add(trans.getDateTimeBefore()); localTransitionList.add(trans.getDateTimeAfter());
ZoneOffset after = wallOffsets[i + 1]; ZoneOffsetTransition trans = new ZoneOffsetTransition(savingsInstantTransitions[i], before, after); if (trans.isGap()) { localTransitionList.add(trans.getDateTimeBefore()); localTransitionList.add(trans.getDateTimeAfter());
localTransitionOffsetList.add(baseWallOffset); for (ZoneOffsetTransition trans : transitionList) { if (trans.isGap()) { localTransitionList.add(trans.getDateTimeBefore()); localTransitionList.add(trans.getDateTimeAfter());
ZoneOffset after = wallOffsets[i + 1]; ZoneOffsetTransition trans = new ZoneOffsetTransition(savingsInstantTransitions[i], before, after); if (trans.isGap()) { localTransitionList.add(trans.getDateTimeBefore()); localTransitionList.add(trans.getDateTimeAfter());
/** * Checks if the specified offset is valid during this transition. * <p> * This checks to see if the given offset will be valid at some point in the transition. * A gap will always return false. * An overlap will return true if the offset is either the before or after offset. * * @param offset the offset to check, null returns false * @return true if the offset is valid during the transition */ public boolean isValidOffset(ZoneOffset offset) { return isGap() ? false : (getOffsetBefore().equals(offset) || getOffsetAfter().equals(offset)); }
/** * Checks if the specified offset is valid during this transition. * <p> * This checks to see if the given offset will be valid at some point in the transition. * A gap will always return false. * An overlap will return true if the offset is either the before or after offset. * * @param offset the offset to check, null returns false * @return true if the offset is valid during the transition */ public boolean isValidOffset(ZoneOffset offset) { return isGap() ? false : (getOffsetBefore().equals(offset) || getOffsetAfter().equals(offset)); }
ZoneRules rules = zone.getRules(); ZoneOffsetTransition trans = rules.getTransition(ldt); if (trans != null && trans.isGap()) { ldt = trans.getDateTimeAfter();
ZoneRules rules = zone.getRules(); ZoneOffsetTransition trans = rules.getTransition(ldt); if (trans != null && trans.isGap()) { ldt = trans.getDateTimeAfter();
if (rules.isValidOffset(localDateTime, offset) == false) { ZoneOffsetTransition trans = rules.getTransition(localDateTime); if (trans != null && trans.isGap()) {
if (rules.isValidOffset(localDateTime, offset) == false) { ZoneOffsetTransition trans = rules.getTransition(localDateTime); if (trans != null && trans.isGap()) {
/** * Finds the offset info for a local date-time and transition. * * @param dt the date-time, not null * @param trans the transition, not null * @return the offset info, not null */ private Object findOffsetInfo(LocalDateTime dt, ZoneOffsetTransition trans) { LocalDateTime localTransition = trans.getDateTimeBefore(); if (trans.isGap()) { if (dt.isBefore(localTransition)) { return trans.getOffsetBefore(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans; } else { return trans.getOffsetAfter(); } } else { if (dt.isBefore(localTransition) == false) { return trans.getOffsetAfter(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans.getOffsetBefore(); } else { return trans; } } }
/** * Finds the offset info for a local date-time and transition. * * @param dt the date-time, not null * @param trans the transition, not null * @return the offset info, not null */ private Object findOffsetInfo(LocalDateTime dt, ZoneOffsetTransition trans) { LocalDateTime localTransition = trans.getDateTimeBefore(); if (trans.isGap()) { if (dt.isBefore(localTransition)) { return trans.getOffsetBefore(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans; } else { return trans.getOffsetAfter(); } } else { if (dt.isBefore(localTransition) == false) { return trans.getOffsetAfter(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans.getOffsetBefore(); } else { return trans; } } }