Java Code Examples for java.time.ZoneOffset#ofTotalSeconds()
The following examples show how to use
java.time.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: ZoneOffsetTransitionRule.java From dragonwell8_jdk with GNU General Public License v2.0 | 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); LocalTime time = (timeByte == 31 ? LocalTime.ofSecondOfDay(in.readInt()) : LocalTime.of(timeByte % 24, 0)); 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)); return ZoneOffsetTransitionRule.of(month, dom, dow, time, timeByte == 24, defn, std, before, after); }
Example 2
Source File: ZoneOffsetTransitionRule.java From Bytecoder with Apache License 2.0 | 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); LocalTime time = (timeByte == 31 ? LocalTime.ofSecondOfDay(in.readInt()) : LocalTime.of(timeByte % 24, 0)); 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)); return ZoneOffsetTransitionRule.of(month, dom, dow, time, timeByte == 24, defn, std, before, after); }
Example 3
Source File: ZoneOffsetTransitionRule.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 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); LocalTime time = (timeByte == 31 ? LocalTime.ofSecondOfDay(in.readInt()) : LocalTime.of(timeByte % 24, 0)); 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)); return ZoneOffsetTransitionRule.of(month, dom, dow, time, timeByte == 24, defn, std, before, after); }
Example 4
Source File: ZoneOffsetTransitionRule.java From TencentKona-8 with GNU General Public License v2.0 | 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); LocalTime time = (timeByte == 31 ? LocalTime.ofSecondOfDay(in.readInt()) : LocalTime.of(timeByte % 24, 0)); 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)); return ZoneOffsetTransitionRule.of(month, dom, dow, time, timeByte == 24, defn, std, before, after); }
Example 5
Source File: ZoneOffsetTransitionRule.java From openjdk-8 with GNU General Public License v2.0 | 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); LocalTime time = (timeByte == 31 ? LocalTime.ofSecondOfDay(in.readInt()) : LocalTime.of(timeByte % 24, 0)); 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)); return ZoneOffsetTransitionRule.of(month, dom, dow, time, timeByte == 24, defn, std, before, after); }
Example 6
Source File: ZonedDateTimes.java From jpx with Apache License 2.0 | 5 votes |
private static ZoneOffset readZoneOffset(final DataInput in) throws IOException { int offsetByte = in.readByte(); return offsetByte == 127 ? ZoneOffset.ofTotalSeconds(IO.readInt(in)) : ZoneOffset.ofTotalSeconds(offsetByte*900); }
Example 7
Source File: ZoneInfoOld.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
private int transToString(long val, int off_old, int[] offsets, StringBuilder sb) { int dst = (int)((val >>> DST_NSHIFT) & 0xfL); int save = (dst == 0) ? 0 : offsets[dst] / 1000; int off = offsets[(int)(val & OFFSET_MASK)]/1000; long second = (val >> TRANSITION_NSHIFT)/1000; ZoneOffset offset_old = ZoneOffset.ofTotalSeconds(off_old); ZoneOffset offset = ZoneOffset.ofTotalSeconds(off); sb.append(" " + LocalDateTime.ofEpochSecond(second, 0, offset_old)); sb.append(" [utc=" + second + " raw=" + Long.toHexString(val >> TRANSITION_NSHIFT) + ", offset=" + off + "/" + offset + ", saving=" + save + "]"); return off; }
Example 8
Source File: TimeConverter.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private ZoneOffset zoneOfSet(int rawOffset) { try { return ZoneOffset.ofTotalSeconds(rawOffset / 1000); } catch (DateTimeException dte) { Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Could not create ZoneOffset from raw offset " + rawOffset); } return ZoneOffset.UTC; }
Example 9
Source File: DateTimeFormatterBuilder.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Parse an offset following a prefix and set the ZoneId if it is valid. * To matching the parsing of ZoneId.of the values are not normalized * to ZoneOffsets. * * @param context the parse context * @param text the input text * @param prefixPos start of the prefix * @param position start of text after the prefix * @param parser parser for the value after the prefix * @return the position after the parse */ private int parseOffsetBased(DateTimeParseContext context, CharSequence text, int prefixPos, int position, OffsetIdPrinterParser parser) { String prefix = text.toString().substring(prefixPos, position).toUpperCase(); if (position >= text.length()) { context.setParsed(ZoneId.of(prefix)); return position; } // '0' or 'Z' after prefix is not part of a valid ZoneId; use bare prefix if (text.charAt(position) == '0' || context.charEquals(text.charAt(position), 'Z')) { context.setParsed(ZoneId.of(prefix)); return position; } DateTimeParseContext newContext = context.copy(); int endPos = parser.parse(newContext, text, position); try { if (endPos < 0) { if (parser == OffsetIdPrinterParser.INSTANCE_ID_Z) { return ~prefixPos; } context.setParsed(ZoneId.of(prefix)); return position; } int offset = (int) newContext.getParsed(OFFSET_SECONDS).longValue(); ZoneOffset zoneOffset = ZoneOffset.ofTotalSeconds(offset); context.setParsed(ZoneId.ofOffset(prefix, zoneOffset)); return endPos; } catch (DateTimeException dte) { return ~prefixPos; } }
Example 10
Source File: DateTimeFormatterBuilder.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * Parse an offset following a prefix and set the ZoneId if it is valid. * To matching the parsing of ZoneId.of the values are not normalized * to ZoneOffsets. * * @param context the parse context * @param text the input text * @param prefixPos start of the prefix * @param position start of text after the prefix * @param parser parser for the value after the prefix * @return the position after the parse */ private int parseOffsetBased(DateTimeParseContext context, CharSequence text, int prefixPos, int position, OffsetIdPrinterParser parser) { String prefix = text.toString().substring(prefixPos, position).toUpperCase(); if (position >= text.length()) { context.setParsed(ZoneId.of(prefix)); return position; } // '0' or 'Z' after prefix is not part of a valid ZoneId; use bare prefix if (text.charAt(position) == '0' || context.charEquals(text.charAt(position), 'Z')) { context.setParsed(ZoneId.of(prefix)); return position; } DateTimeParseContext newContext = context.copy(); int endPos = parser.parse(newContext, text, position); try { if (endPos < 0) { if (parser == OffsetIdPrinterParser.INSTANCE_ID_Z) { return ~prefixPos; } context.setParsed(ZoneId.of(prefix)); return position; } int offset = (int) newContext.getParsed(OFFSET_SECONDS).longValue(); ZoneOffset zoneOffset = ZoneOffset.ofTotalSeconds(offset); context.setParsed(ZoneId.ofOffset(prefix, zoneOffset)); return endPos; } catch (DateTimeException dte) { return ~prefixPos; } }
Example 11
Source File: ChronoZonedDateTimeImpl.java From JDKSourceCode1.8 with MIT 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 ChronoZonedDateTimeImpl.ensureValid(getChronology(), field.adjustInto(this, newValue)); }
Example 12
Source File: Parsed.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private void resolveInstantFields() { // resolve parsed instant seconds to date and time if zone available if (fieldValues.containsKey(INSTANT_SECONDS)) { if (zone != null) { resolveInstantFields0(zone); } else { Long offsetSecs = fieldValues.get(OFFSET_SECONDS); if (offsetSecs != null) { ZoneOffset offset = ZoneOffset.ofTotalSeconds(offsetSecs.intValue()); resolveInstantFields0(offset); } } } }
Example 13
Source File: TCKZoneOffset.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void test_factory_ofTotalSeconds_minValue() { ZoneOffset.ofTotalSeconds(Integer.MIN_VALUE); }
Example 14
Source File: ZoneOffsetSchema.java From joyrpc with Apache License 2.0 | 4 votes |
@Override public ZoneOffset newMessage() { //不能使用0,0会缓存结果对象 return ZoneOffset.ofTotalSeconds(1); }
Example 15
Source File: OffsetTimeEncoding.java From ndbc with Apache License 2.0 | 4 votes |
@Override public final OffsetTime decodeBinary(final BufferReader b) { final LocalTime time = LocalTime.ofNanoOfDay(b.readLong() * 1000); final ZoneOffset zone = ZoneOffset.ofTotalSeconds(-b.readInt()); return time.atOffset(zone); }
Example 16
Source File: TCKZoneOffset.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void test_factory_ofTotalSeconds_minValue() { ZoneOffset.ofTotalSeconds(Integer.MIN_VALUE); }
Example 17
Source File: TCKZoneOffset.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void test_factory_ofTotalSeconds_tooSmall() { ZoneOffset.ofTotalSeconds(-18 * 60 * 60 - 1); }
Example 18
Source File: TCKZoneOffset.java From j2objc with Apache License 2.0 | 4 votes |
@Test(expected=DateTimeException.class) public void test_factory_ofTotalSeconds_tooSmall() { ZoneOffset.ofTotalSeconds(-18 * 60 * 60 - 1); }
Example 19
Source File: Ser.java From openjdk-8 with GNU General Public License v2.0 | 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 20
Source File: Ser.java From openjdk-8-source with GNU General Public License v2.0 | 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)); }