private static String currentTimeZoneOffsetString() { ZoneOffset offset = OffsetDateTime.now().getOffset(); return offset.equals( UTC ) ? "+0000" : offset.toString().replace( ":", "" ); } }
if ( !expected.equals( offset ) )
if (!defaultZoneOffset.equals(ZoneOffset.UTC)) {
@Override public DateFormatter withZone(ZoneId zoneId) { if (ZoneOffset.UTC.equals(zoneId) == false) { throw new IllegalArgumentException(pattern() + " date formatter can only be in zone offset UTC"); } return INSTANCE; }
@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); }
@Override public DateFormatter withZone(ZoneId zoneId) { if (ZoneOffset.UTC.equals(zoneId) == false) { throw new IllegalArgumentException(pattern() + " date formatter can only be in zone offset UTC"); } return INSTANCE; }
@Override public DateFormatter withZone(ZoneId zoneId) { if (ZoneOffset.UTC.equals(zoneId) == false) { throw new IllegalArgumentException(pattern() + " date formatter can only be in zone offset UTC"); } return INSTANCE; }
public static List<String> getRegionNamesForOffset(ZoneOffset offset) { LocalDateTime now = LocalDateTime.now(); return ZoneId.getAvailableZoneIds().stream() .map(ZoneId::of) .filter(zoneId -> now.atZone(zoneId).getOffset().equals(offset)) .map(ZoneId::toString) .sorted() .collect(Collectors.toList()); }
@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)); }
@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; }
/** * Returns a generally equivalent {@link java.util.TimeZone}. The offset will be truncated to minutes. * * @param self a ZoneOffset * @return a TimeZone * @since 2.5.0 */ public static TimeZone toTimeZone(final ZoneOffset self) { if (ZoneOffset.UTC.equals(self)) { return TimeZone.getTimeZone("GMT"); } else if (getSeconds(self) == 0) { return TimeZone.getTimeZone("GMT" + self.getId()); } else { // TimeZone is only hours and minutes--no seconds ZoneOffset noSeconds = ZoneOffset.ofHoursMinutes(getHours(self), getMinutes(self)); return TimeZone.getTimeZone("GMT" + noSeconds.getId()); } }
@Override public final void serialize(Writer writer, OffsetTime time) throws IOException { super.serialize(writer, time); OutputStream stream = writer.stream; if (!(time.getOffset().equals(ZoneOffset.UTC))) { stream.write(TagString); ValueWriter.write(stream, time.toString()); } else { ValueWriter.writeTime(stream, time.getHour(), time.getMinute(), time.getSecond(), 0, false, true); ValueWriter.writeNano(stream, time.getNano()); stream.write(TagUTC); } } }
@Override public final void serialize(Writer writer, OffsetTime time) throws IOException { super.serialize(writer, time); OutputStream stream = writer.stream; if (!(time.getOffset().equals(ZoneOffset.UTC))) { stream.write(TagString); ValueWriter.write(stream, time.toString()); } else { ValueWriter.writeTime(stream, time.getHour(), time.getMinute(), time.getSecond(), 0, false, true); ValueWriter.writeNano(stream, time.getNano()); stream.write(TagUTC); } } }
private boolean areSchedulersEqualForSyncStarting(SchedulerJobDTO notebookScheduler, SchedulerJobDTO clusterScheduler) { return !Objects.isNull(notebookScheduler) && !Objects.isNull(clusterScheduler) && notebookScheduler.getBeginDate().equals(clusterScheduler.getBeginDate()) && notebookScheduler.getStartTime().equals(clusterScheduler.getStartTime()) && areCollectionsEqual(notebookScheduler.getStartDaysRepeat(), clusterScheduler.getStartDaysRepeat()) && notebookScheduler.getTimeZoneOffset().equals(clusterScheduler.getTimeZoneOffset()) && notebookScheduler.isSyncStartRequired() && clusterScheduler.isSyncStartRequired(); }
@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; }