@Override public boolean isValidOffset(LocalDateTime dateTime, ZoneOffset offset) { return this.offset.equals(offset); }
@Override public boolean isValidOffset(LocalDateTime dateTime, ZoneOffset offset) { return this.offset.equals(offset); }
/** * Returns a new time based on this one, returning {@code this} where possible. * * @param time the time to create with, not null * @param offset the zone offset to create with, not null */ private OffsetTime with(LocalTime time, ZoneOffset offset) { if (this.time == time && this.offset.equals(offset)) { return this; } return new OffsetTime(time, offset); }
/** * Returns a new date-time based on this one, returning {@code this} where possible. * * @param dateTime the date-time to create with, not null * @param offset the zone offset to create with, not null */ private OffsetDateTime with(LocalDateTime dateTime, ZoneOffset offset) { if (this.dateTime == dateTime && this.offset.equals(offset)) { return this; } return new OffsetDateTime(dateTime, offset); }
/** * Returns a new date-time based on this one, returning {@code this} where possible. * * @param dateTime the date-time to create with, not null * @param offset the zone offset to create with, not null */ private OffsetDateTime with(LocalDateTime dateTime, ZoneOffset offset) { if (this.dateTime == dateTime && this.offset.equals(offset)) { return this; } return new OffsetDateTime(dateTime, offset); }
/** * Returns a new time based on this one, returning {@code this} where possible. * * @param time the time to create with, not null * @param offset the zone offset to create with, not null */ private OffsetTime with(LocalTime time, ZoneOffset offset) { if (this.time == time && this.offset.equals(offset)) { return this; } return new OffsetTime(time, offset); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof Fixed) { return offset.equals(((Fixed) obj).offset); } if (obj instanceof StandardZoneRules) { StandardZoneRules szr = (StandardZoneRules) obj; return szr.isFixedOffset() && offset.equals(szr.getOffset(Instant.EPOCH)); } return false; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof Fixed) { return offset.equals(((Fixed) obj).offset); } if (obj instanceof StandardZoneRules) { StandardZoneRules szr = (StandardZoneRules) obj; return szr.isFixedOffset() && offset.equals(szr.getOffset(Instant.EPOCH)); } return false; }
/** * 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)); }
@Override public boolean isDaylightSavings(Instant instant) { return (getStandardOffset(instant).equals(getOffset(instant)) == false); }
@Override public boolean isDaylightSavings(Instant instant) { return (getStandardOffset(instant).equals(getOffset(instant)) == false); }
/** * Resolves the offset into this zoned date-time. * <p> * This ignores the offset, unless it can be used in an overlap. * * @param offset the offset, not null * @return the zoned date-time, not null */ private ZonedDateTime resolveOffset(ZoneOffset offset) { if (offset.equals(this.offset) == false && zone.getRules().isValidOffset(dateTime, offset)) { return new ZonedDateTime(dateTime, offset, zone); } return this; }
/** * Resolves the offset into this zoned date-time. * <p> * This ignores the offset, unless it can be used in an overlap. * * @param offset the offset, not null * @return the zoned date-time, not null */ private ZonedDateTime resolveOffset(ZoneOffset offset) { if (offset.equals(this.offset) == false && zone.getRules().isValidOffset(dateTime, offset)) { return new ZonedDateTime(dateTime, offset, zone); } return this; }
/** * 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); }
@Override public ChronoZonedDateTime<D> withLaterOffsetAtOverlap() { ZoneOffsetTransition trans = getZone().getRules().getTransition(LocalDateTime.from(this)); if (trans != null) { ZoneOffset offset = trans.getOffsetAfter(); if (offset.equals(getOffset()) == false) { return new ChronoZonedDateTimeImpl<D>(dateTime, offset, zone); } } return this; }
@Override public ChronoZonedDateTime<D> withEarlierOffsetAtOverlap() { ZoneOffsetTransition trans = getZone().getRules().getTransition(LocalDateTime.from(this)); if (trans != null && trans.isOverlap()) { ZoneOffset earlierOffset = trans.getOffsetBefore(); if (earlierOffset.equals(offset) == false) { return new ChronoZonedDateTimeImpl<D>(dateTime, earlierOffset, zone); } } return this; }
@Override public ChronoZonedDateTime<D> withEarlierOffsetAtOverlap() { ZoneOffsetTransition trans = getZone().getRules().getTransition(LocalDateTime.from(this)); if (trans != null && trans.isOverlap()) { ZoneOffset earlierOffset = trans.getOffsetBefore(); if (earlierOffset.equals(offset) == false) { return new ChronoZonedDateTimeImpl<D>(dateTime, earlierOffset, zone); } } return this; }
@Override public ChronoZonedDateTime<D> withLaterOffsetAtOverlap() { ZoneOffsetTransition trans = getZone().getRules().getTransition(LocalDateTime.from(this)); if (trans != null) { ZoneOffset offset = trans.getOffsetAfter(); if (offset.equals(getOffset()) == false) { return new ChronoZonedDateTimeImpl<D>(dateTime, offset, zone); } } return this; }