/** * 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 ZoneOffset readOffset(DataInput in) throws IOException { int offsetByte = in.readByte(); return (offsetByte == 127 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(offsetByte * 900)); }
/** * 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 ZoneOffset readOffset(DataInput in) throws IOException { int offsetByte = in.readByte(); return (offsetByte == 127 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(offsetByte * 900)); }
static ZoneOffset readExternal(DataInput in) throws IOException { int offsetByte = in.readByte(); return (offsetByte == 127 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(offsetByte * 900)); }
static ZoneOffset readExternal(DataInput in) throws IOException { int offsetByte = in.readByte(); return (offsetByte == 127 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(offsetByte * 900)); }
/** * Creates the wall offset 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 */ ZoneOffset createWallOffset(int savingsSecs) { return ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingsSecs); }
/** * Creates the wall offset 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 */ ZoneOffset createWallOffset(int savingsSecs) { return ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingsSecs); }
private ZoneOffset parseOffset(String str) { int secs = parseSecs(str); return ZoneOffset.ofTotalSeconds(secs); }
private ZoneOffset parseOffset(String str) { int secs = parseSecs(str); return ZoneOffset.ofTotalSeconds(secs); }
private void mergeInstantFields() { if (fieldValues.containsKey(INSTANT_SECONDS)) { if (zone != null) { mergeInstantFields0(zone); } else { Long offsetSecs = fieldValues.get(OFFSET_SECONDS); if (offsetSecs != null) { ZoneOffset offset = ZoneOffset.ofTotalSeconds(offsetSecs.intValue()); mergeInstantFields0(offset); } } } }
private void mergeInstantFields() { if (fieldValues.containsKey(INSTANT_SECONDS)) { if (zone != null) { mergeInstantFields0(zone); } else { Long offsetSecs = fieldValues.get(OFFSET_SECONDS); if (offsetSecs != null) { ZoneOffset offset = ZoneOffset.ofTotalSeconds(offsetSecs.intValue()); mergeInstantFields0(offset); } } } }
@Override public ZoneOffset queryFrom(TemporalAccessor temporal) { if (temporal.isSupported(OFFSET_SECONDS)) { return ZoneOffset.ofTotalSeconds(temporal.get(OFFSET_SECONDS)); } return null; } };
@Override public ZoneOffset queryFrom(TemporalAccessor temporal) { if (temporal.isSupported(OFFSET_SECONDS)) { return ZoneOffset.ofTotalSeconds(temporal.get(OFFSET_SECONDS)); } return null; } };
private void resolveInstant() { if (date != null && time != null) { Long offsetSecs = fieldValues.get(OFFSET_SECONDS); if (offsetSecs != null) { ZoneOffset offset = ZoneOffset.ofTotalSeconds(offsetSecs.intValue()); long instant = date.atTime(time).atZone(offset).getLong(ChronoField.INSTANT_SECONDS); fieldValues.put(INSTANT_SECONDS, instant); } else if (zone != null) { long instant = date.atTime(time).atZone(zone).getLong(ChronoField.INSTANT_SECONDS); fieldValues.put(INSTANT_SECONDS, instant); } } }
private void resolveInstant() { if (date != null && time != null) { Long offsetSecs = fieldValues.get(OFFSET_SECONDS); if (offsetSecs != null) { ZoneOffset offset = ZoneOffset.ofTotalSeconds(offsetSecs.intValue()); long instant = date.atTime(time).atZone(offset).getLong(ChronoField.INSTANT_SECONDS); fieldValues.put(INSTANT_SECONDS, instant); } else if (zone != null) { long instant = date.atTime(time).atZone(zone).getLong(ChronoField.INSTANT_SECONDS); fieldValues.put(INSTANT_SECONDS, instant); } } }
private int parsePrefixedOffset(DateTimeParseContext context, CharSequence text, int prefixPos, int position) { String prefix = text.subSequence(prefixPos, position).toString().toUpperCase(); DateTimeParseContext newContext = context.copy(); if (position < text.length() && context.charEquals(text.charAt(position), 'Z')) { context.setParsed(ZoneId.ofOffset(prefix, ZoneOffset.UTC)); return position; } int endPos = OffsetIdPrinterParser.INSTANCE_ID.parse(newContext, text, position); if (endPos < 0) { context.setParsed(ZoneId.ofOffset(prefix, ZoneOffset.UTC)); return position; } int offsetSecs = (int) newContext.getParsed(OFFSET_SECONDS).longValue(); ZoneOffset offset = ZoneOffset.ofTotalSeconds(offsetSecs); context.setParsed(ZoneId.ofOffset(prefix, offset)); return endPos; }
private int parsePrefixedOffset(DateTimeParseContext context, CharSequence text, int prefixPos, int position) { String prefix = text.subSequence(prefixPos, position).toString().toUpperCase(); DateTimeParseContext newContext = context.copy(); if (position < text.length() && context.charEquals(text.charAt(position), 'Z')) { context.setParsed(ZoneId.ofOffset(prefix, ZoneOffset.UTC)); return position; } int endPos = OffsetIdPrinterParser.INSTANCE_ID.parse(newContext, text, position); if (endPos < 0) { context.setParsed(ZoneId.ofOffset(prefix, ZoneOffset.UTC)); return position; } int offsetSecs = (int) newContext.getParsed(OFFSET_SECONDS).longValue(); ZoneOffset offset = ZoneOffset.ofTotalSeconds(offsetSecs); context.setParsed(ZoneId.ofOffset(prefix, offset)); return endPos; }
/** * 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); }
@Override public ChronoZonedDateTime<D> with(TemporalField field, long newValue) { if (field instanceof ChronoField) { ChronoField f = (ChronoField) field; switch (f) { case INSTANT_SECONDS: return plus(newValue - toEpochSecond(), SECONDS); case OFFSET_SECONDS: { ZoneOffset offset = ZoneOffset.ofTotalSeconds(f.checkValidIntValue(newValue)); return create(dateTime.toInstant(offset), zone); } } return ofBest(dateTime.with(field, newValue), zone, offset); } return toLocalDate().getChronology().ensureChronoZonedDateTime(field.adjustInto(this, newValue)); }
@Override public ChronoZonedDateTime<D> with(TemporalField field, long newValue) { if (field instanceof ChronoField) { ChronoField f = (ChronoField) field; switch (f) { case INSTANT_SECONDS: return plus(newValue - toEpochSecond(), SECONDS); case OFFSET_SECONDS: { ZoneOffset offset = ZoneOffset.ofTotalSeconds(f.checkValidIntValue(newValue)); return create(dateTime.toInstant(offset), zone); } } return ofBest(dateTime.with(field, newValue), zone, offset); } return toLocalDate().getChronology().ensureChronoZonedDateTime(field.adjustInto(this, newValue)); }