/** * 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); }
/** * 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); }
/** * 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 the offset date-time for the local date-time at the end of the window. * * @param savingsSecs the amount of savings in use in seconds * @return the created date-time epoch second in the wall offset, not null */ long createDateTimeEpochSecond(int savingsSecs) { ZoneOffset wallOffset = createWallOffset(savingsSecs); LocalDateTime ldt = timeDefinition.createDateTime(windowEnd, standardOffset, wallOffset); return ldt.toEpochSecond(wallOffset); } }
/** * Creates the offset date-time for the local date-time at the end of the window. * * @param savingsSecs the amount of savings in use in seconds * @return the created date-time epoch second in the wall offset, not null */ long createDateTimeEpochSecond(int savingsSecs) { ZoneOffset wallOffset = createWallOffset(savingsSecs); LocalDateTime ldt = timeDefinition.createDateTime(windowEnd, standardOffset, wallOffset); return ldt.toEpochSecond(wallOffset); } }