@Override public List<ZoneOffsetTransition> getTransitions() { List<ZoneOffsetTransition> list = new ArrayList<ZoneOffsetTransition>(); for (int i = 0; i < savingsInstantTransitions.length; i++) { list.add(new ZoneOffsetTransition(savingsInstantTransitions[i], wallOffsets[i], wallOffsets[i + 1])); } return Collections.unmodifiableList(list); }
@Override public List<ZoneOffsetTransition> getTransitions() { List<ZoneOffsetTransition> list = new ArrayList<ZoneOffsetTransition>(); for (int i = 0; i < savingsInstantTransitions.length; i++) { list.add(new ZoneOffsetTransition(savingsInstantTransitions[i], wallOffsets[i], wallOffsets[i + 1])); } return Collections.unmodifiableList(list); }
ZoneOffset before = wallOffsets[i]; ZoneOffset after = wallOffsets[i + 1]; ZoneOffsetTransition trans = new ZoneOffsetTransition(savingsInstantTransitions[i], before, after); if (trans.isGap()) { localTransitionList.add(trans.getDateTimeBefore());
ZoneOffset before = wallOffsets[i]; ZoneOffset after = wallOffsets[i + 1]; ZoneOffsetTransition trans = new ZoneOffsetTransition(savingsInstantTransitions[i], before, after); if (trans.isGap()) { localTransitionList.add(trans.getDateTimeBefore());
/** * Reads the state from the stream. * * @param in the input stream, not null * @return the created object, not null * @throws IOException if an error occurs */ static ZoneOffsetTransition readExternal(DataInput in) throws IOException { long epochSecond = Ser.readEpochSec(in); ZoneOffset before = Ser.readOffset(in); ZoneOffset after = Ser.readOffset(in); if (before.equals(after)) { throw new IllegalArgumentException("Offsets must not be equal"); } return new ZoneOffsetTransition(epochSecond, before, after); }
/** * Reads the state from the stream. * * @param in the input stream, not null * @return the created object, not null * @throws IOException if an error occurs */ static ZoneOffsetTransition readExternal(DataInput in) throws IOException { long epochSecond = Ser.readEpochSec(in); ZoneOffset before = Ser.readOffset(in); ZoneOffset after = Ser.readOffset(in); if (before.equals(after)) { throw new IllegalArgumentException("Offsets must not be equal"); } return new ZoneOffsetTransition(epochSecond, before, after); }
/** * Obtains an instance defining a transition between two offsets. * <p> * Applications should normally obtain an instance from {@link ZoneRules}. * This factory is only intended for use when creating {@link ZoneRules}. * * @param transition the transition date-time at the transition, which never * actually occurs, expressed local to the before offset, not null * @param offsetBefore the offset before the transition, not null * @param offsetAfter the offset at and after the transition, not null * @return the transition, not null * @throws IllegalArgumentException if {@code offsetBefore} and {@code offsetAfter} * are equal, or {@code transition.getNano()} returns non-zero value */ public static ZoneOffsetTransition of(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) { Jdk8Methods.requireNonNull(transition, "transition"); Jdk8Methods.requireNonNull(offsetBefore, "offsetBefore"); Jdk8Methods.requireNonNull(offsetAfter, "offsetAfter"); if (offsetBefore.equals(offsetAfter)) { throw new IllegalArgumentException("Offsets must not be equal"); } if (transition.getNano() != 0) { throw new IllegalArgumentException("Nano-of-second must be zero"); } return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter); }
/** * Obtains an instance defining a transition between two offsets. * <p> * Applications should normally obtain an instance from {@link ZoneRules}. * This factory is only intended for use when creating {@link ZoneRules}. * * @param transition the transition date-time at the transition, which never * actually occurs, expressed local to the before offset, not null * @param offsetBefore the offset before the transition, not null * @param offsetAfter the offset at and after the transition, not null * @return the transition, not null * @throws IllegalArgumentException if {@code offsetBefore} and {@code offsetAfter} * are equal, or {@code transition.getNano()} returns non-zero value */ public static ZoneOffsetTransition of(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) { Jdk8Methods.requireNonNull(transition, "transition"); Jdk8Methods.requireNonNull(offsetBefore, "offsetBefore"); Jdk8Methods.requireNonNull(offsetAfter, "offsetAfter"); if (offsetBefore.equals(offsetAfter)) { throw new IllegalArgumentException("Offsets must not be equal"); } if (transition.getNano() != 0) { throw new IllegalArgumentException("Nano-of-second must be zero"); } return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter); }
if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) { return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter); } else { return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);
if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) { return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter); } else { return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);
index += 1; // exact match, so need to add one to get the next return new ZoneOffsetTransition(savingsInstantTransitions[index], wallOffsets[index], wallOffsets[index + 1]);
index += 1; // exact match, so need to add one to get the next return new ZoneOffsetTransition(savingsInstantTransitions[index], wallOffsets[index], wallOffsets[index + 1]);
return null; return new ZoneOffsetTransition(savingsInstantTransitions[index - 1], wallOffsets[index - 1], wallOffsets[index]);
return null; return new ZoneOffsetTransition(savingsInstantTransitions[index - 1], wallOffsets[index - 1], wallOffsets[index]);
new ZoneOffsetTransition( LocalDateTime.ofEpochSecond(loopWindowStart.toEpochSecond(loopWindowOffset), 0, loopStandardOffset), loopStandardOffset, window.standardOffset))); if (loopWindowOffset.equals(effectiveWallOffset) == false) { ZoneOffsetTransition trans = deduplicate( new ZoneOffsetTransition(loopWindowStart, loopWindowOffset, effectiveWallOffset)); transitionList.add(trans);
new ZoneOffsetTransition( LocalDateTime.ofEpochSecond(loopWindowStart.toEpochSecond(loopWindowOffset), 0, loopStandardOffset), loopStandardOffset, window.standardOffset))); if (loopWindowOffset.equals(effectiveWallOffset) == false) { ZoneOffsetTransition trans = deduplicate( new ZoneOffsetTransition(loopWindowStart, loopWindowOffset, effectiveWallOffset)); transitionList.add(trans);
/** * Converts this to a transition. * * @param standardOffset the active standard offset, not null * @param savingsBeforeSecs the active savings in seconds * @return the transition, not null */ ZoneOffsetTransition toTransition(ZoneOffset standardOffset, int savingsBeforeSecs) { // copy of code in ZoneOffsetTransitionRule to avoid infinite loop LocalDate date = toLocalDate(); date = deduplicate(date); LocalDateTime ldt = deduplicate(LocalDateTime.of(date.plusDays(adjustDays), time)); ZoneOffset wallOffset = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingsBeforeSecs)); LocalDateTime dt = deduplicate(timeDefinition.createDateTime(ldt, standardOffset, wallOffset)); ZoneOffset offsetAfter = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingAmountSecs)); return new ZoneOffsetTransition(dt, wallOffset, offsetAfter); }
/** * Creates a transition instance for the specified year. * <p> * Calculations are performed using the ISO-8601 chronology. * * @param year the year to create a transition for, not null * @return the transition instance, not null */ public ZoneOffsetTransition createTransition(int year) { LocalDate date; if (dom < 0) { date = LocalDate.of(year, month, month.length(IsoChronology.INSTANCE.isLeapYear(year)) + 1 + dom); if (dow != null) { date = date.with(previousOrSame(dow)); } } else { date = LocalDate.of(year, month, dom); if (dow != null) { date = date.with(nextOrSame(dow)); } } LocalDateTime localDT = LocalDateTime.of(date.plusDays(adjustDays), time); LocalDateTime transition = timeDefinition.createDateTime(localDT, standardOffset, offsetBefore); return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter); }
/** * Converts this to a transition. * * @param standardOffset the active standard offset, not null * @param savingsBeforeSecs the active savings in seconds * @return the transition, not null */ ZoneOffsetTransition toTransition(ZoneOffset standardOffset, int savingsBeforeSecs) { // copy of code in ZoneOffsetTransitionRule to avoid infinite loop LocalDate date = toLocalDate(); date = deduplicate(date); LocalDateTime ldt = deduplicate(LocalDateTime.of(date.plusDays(adjustDays), time)); ZoneOffset wallOffset = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingsBeforeSecs)); LocalDateTime dt = deduplicate(timeDefinition.createDateTime(ldt, standardOffset, wallOffset)); ZoneOffset offsetAfter = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingAmountSecs)); return new ZoneOffsetTransition(dt, wallOffset, offsetAfter); }
/** * Creates a transition instance for the specified year. * <p> * Calculations are performed using the ISO-8601 chronology. * * @param year the year to create a transition for, not null * @return the transition instance, not null */ public ZoneOffsetTransition createTransition(int year) { LocalDate date; if (dom < 0) { date = LocalDate.of(year, month, month.length(IsoChronology.INSTANCE.isLeapYear(year)) + 1 + dom); if (dow != null) { date = date.with(previousOrSame(dow)); } } else { date = LocalDate.of(year, month, dom); if (dow != null) { date = date.with(nextOrSame(dow)); } } LocalDateTime localDT = LocalDateTime.of(date.plusDays(adjustDays), time); LocalDateTime transition = timeDefinition.createDateTime(localDT, standardOffset, offsetBefore); return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter); }