@Override public LocalDateTime convert(OffsetDateTime source) { return source.toLocalDateTime(); } }
@Override public LocalDateTime convert(OffsetDateTime source) { return source.toLocalDateTime(); } }
public synchronized String toString(OffsetDateTime offsetDateTime) { if (offsetDateTime.isAfter(MAX_OFFSET_DATETIME)) { return "infinity"; } else if (OffsetDateTime.MIN.equals(offsetDateTime)) { return "-infinity"; } sbuf.setLength(0); int nano = offsetDateTime.getNano(); if (nanosExceed499(nano)) { // Technically speaking this is not a proper rounding, however // it relies on the fact that appendTime just truncates 000..999 nanosecond part offsetDateTime = offsetDateTime.plus(ONE_MICROSECOND); } LocalDateTime localDateTime = offsetDateTime.toLocalDateTime(); LocalDate localDate = localDateTime.toLocalDate(); appendDate(sbuf, localDate); sbuf.append(' '); appendTime(sbuf, localDateTime.toLocalTime()); appendTimeZone(sbuf, offsetDateTime.getOffset()); appendEra(sbuf, localDate); return sbuf.toString(); }
/** * Best effort parsing of the given value */ public static LocalDateTime parseBest(String value) { TemporalAccessor parsed = getDateTimeFormatter().parse(value); LocalDate datePart; LocalTime timePart; ZoneOffset zoneOffset; long epochDay = 0, nanoSeconds = 0; int offsetSeconds = 0; // get different parsed parts if (parsed.isSupported(ChronoField.EPOCH_DAY)) { epochDay = parsed.getLong(ChronoField.EPOCH_DAY); } if (parsed.isSupported(ChronoField.NANO_OF_DAY)) { nanoSeconds = parsed.getLong(ChronoField.NANO_OF_DAY); } if (parsed.isSupported(ChronoField.OFFSET_SECONDS)) { offsetSeconds = parsed.get(ChronoField.OFFSET_SECONDS); } zoneOffset = ZoneOffset.ofTotalSeconds(offsetSeconds); datePart = LocalDate.ofEpochDay(epochDay); timePart = LocalTime.ofNanoOfDay(nanoSeconds); return OffsetDateTime.of(datePart, timePart, zoneOffset).toLocalDateTime(); }
@Override public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final O output, final OffsetDateTime offsetDateTime) { kryo.writeObject(output, offsetDateTime.toLocalDateTime()); kryo.writeObject(output, offsetDateTime.getOffset()); }
@Override protected ByteBuf writeValue(final OffsetDateTime value, final ByteBufAllocator allocator, final GraphBinaryWriter context) throws SerializationException { final CompositeByteBuf result = allocator.compositeBuffer(2); result.addComponent(true, context.writeValue(value.toLocalDateTime(), allocator, false)); result.addComponent(true, context.writeValue(value.getOffset(), allocator, false)); return result; } }
@Override public LocalDateTime convert(OffsetDateTime source) { return source.toLocalDateTime(); } }
static OffsetDateTime correctOffset(OffsetDateTime value, ZoneId zoneId) { Instant instant = value.toLocalDateTime().atZone(zoneId).toInstant(); return OffsetDateTime.ofInstant(instant, zoneId); } }
@Override protected Object[] toConvertedColumns(OffsetDateTime value) { return new Object[] { value.toLocalDateTime(), value.getOffset() }; }
@Override protected Object[] toConvertedColumns(OffsetDateTime value) { return new Object[] { value.toLocalDateTime(), value.getOffset() }; }
protected ZonedDateTime toZonedDateTime(OffsetDateTime date){ return ZonedDateTime.of(date.toLocalDateTime(), date.getOffset()); }
String dateTimestr = "2015-02-05T02:05:17.000+00:00"; OffsetDateTime dateTime = OffsetDateTime.parse(dateTimestr); if ((dateTime.getNano() == 0) && (dateTimestr.length() > 25 )) System.out.println(dateTime.toLocalDateTime() + ".000Z"); else System.out.println(dateTime.toString());
@Override public Timestamp convertToDatabaseColumn(OffsetDateTime odt) { if (odt == null) return null; return Timestamp.valueOf(odt.withOffsetSameInstant(TimeConversions.getZoneOffset()).toLocalDateTime()); }
@Override public LocalDateTime read(LocalDateTime reuse) { return EPOCH.plus(column.nextLong(), ChronoUnit.MICROS).toLocalDateTime(); } }
@Override public LocalDateTime read(LocalDateTime reuse) { return EPOCH.plus(column.nextLong() * 1000, ChronoUnit.MICROS).toLocalDateTime(); } }
@Override public LocalDateTime read(Decoder decoder, Object reuse) throws IOException { return EPOCH.plus(decoder.readLong(), ChronoUnit.MICROS).toLocalDateTime(); } }
static String humanTimestampWithoutZone(Long timestampMicros) { return ChronoUnit.MICROS.addTo(EPOCH, timestampMicros).toLocalDateTime().toString(); }
@Override public void serialize(OffsetDateTime instant, JsonGenerator generator, SerializerProvider provider) throws IOException { StringBuilder builder = new StringBuilder(); builder.append(instant.toLocalDateTime().toString()); if (instant.getSecond() == 0 && instant.getNano() == 0) { builder.append(":00"); } builder.append(instant.getOffset().toString()); generator.writeString(builder.toString()); } }
@Override public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final O output, final OffsetDateTime offsetDateTime) { kryo.writeObject(output, offsetDateTime.toLocalDateTime()); kryo.writeObject(output, offsetDateTime.getOffset()); }
@Override public ByteBuf writeValue(final OffsetDateTime value, final ByteBufAllocator allocator, final GraphBinaryWriter context) throws SerializationException { final CompositeByteBuf result = allocator.compositeBuffer(2); result.addComponent(true, context.writeValue(value.toLocalDateTime(), allocator, false)); result.addComponent(true, context.writeValue(value.getOffset(), allocator, false)); return result; } }