Java Code Examples for org.threeten.bp.ZoneOffset#ofTotalSeconds()
The following examples show how to use
org.threeten.bp.ZoneOffset#ofTotalSeconds() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateTimeFormatterBuilder.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
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; }
Example 2
Source File: ZoneOffsetTransitionRule.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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 ZoneOffsetTransitionRule readExternal(DataInput in) throws IOException { int data = in.readInt(); Month month = Month.of(data >>> 28); int dom = ((data & (63 << 22)) >>> 22) - 32; int dowByte = (data & (7 << 19)) >>> 19; DayOfWeek dow = dowByte == 0 ? null : DayOfWeek.of(dowByte); int timeByte = (data & (31 << 14)) >>> 14; TimeDefinition defn = TimeDefinition.values()[(data & (3 << 12)) >>> 12]; int stdByte = (data & (255 << 4)) >>> 4; int beforeByte = (data & (3 << 2)) >>> 2; int afterByte = (data & 3); int timeOfDaysSecs = (timeByte == 31 ? in.readInt() : timeByte * 3600); ZoneOffset std = (stdByte == 255 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds((stdByte - 128) * 900)); ZoneOffset before = (beforeByte == 3 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(std.getTotalSeconds() + beforeByte * 1800)); ZoneOffset after = (afterByte == 3 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(std.getTotalSeconds() + afterByte * 1800)); // only bit of validation that we need to copy from public of() method if (dom < -28 || dom > 31 || dom == 0) { throw new IllegalArgumentException("Day of month indicator must be between -28 and 31 inclusive excluding zero"); } LocalTime time = LocalTime.ofSecondOfDay(Jdk8Methods.floorMod(timeOfDaysSecs, SECS_PER_DAY)); int adjustDays = Jdk8Methods.floorDiv(timeOfDaysSecs, SECS_PER_DAY); return new ZoneOffsetTransitionRule(month, dom, dow, time, adjustDays, defn, std, before, after); }
Example 3
Source File: TemporalQueries.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public ZoneOffset queryFrom(TemporalAccessor temporal) { if (temporal.isSupported(OFFSET_SECONDS)) { return ZoneOffset.ofTotalSeconds(temporal.get(OFFSET_SECONDS)); } return null; }
Example 4
Source File: DateTimeBuilder.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
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); } } } }
Example 5
Source File: ChronoZonedDateTimeImpl.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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)); }
Example 6
Source File: TzdbZoneRulesCompiler.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 4 votes |
private ZoneOffset parseOffset(String str) { int secs = parseSecs(str); return ZoneOffset.ofTotalSeconds(secs); }
Example 7
Source File: Ser.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * 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)); }
Example 8
Source File: ZoneRulesBuilder.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * 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); }