/** * Returns true if both OffsetDateTime are in the same nanosecond, false otherwise. * * @param actual the actual OffsetDateTime. expected not be null * @param other the other OffsetDateTime. expected not be null * @return true if both OffsetDateTime are in the same year, false otherwise */ private static boolean haveSameNano(OffsetDateTime actual, OffsetDateTime other) { return actual.getNano() == other.getNano(); }
/** * Returns true if both OffsetDateTime are in the same nanosecond, false otherwise. * * @param actual the actual OffsetDateTime. expected not be null * @param other the other OffsetDateTime. expected not be null * @return true if both OffsetDateTime are in the same year, false otherwise */ private static boolean haveSameNano(OffsetDateTime actual, OffsetDateTime other) { return actual.getNano() == other.getNano(); }
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(); }
@Override protected String toJsonNanos(OffsetDateTime value) { return toJsonNanos(value.toEpochSecond(), value.getNano()); }
assertThat(c4DateTime.getMinute()).isEqualTo(0); assertThat(c4DateTime.getSecond()).isEqualTo(0); assertThat(c4DateTime.getNano()).isEqualTo(0); } else if (record.topic().endsWith("dbz_123_bitvaluetest")) {
@Override public Timestamp toNonNullValue(OffsetDateTime value) { final Timestamp timestamp = new Timestamp((value.toEpochSecond() * MILLIS_IN_SECOND)); timestamp.setNanos(value.getNano()); return timestamp; }
@Override public Timestamp toNonNullValue(OffsetDateTime value) { final Timestamp timestamp = new Timestamp((value.toEpochSecond() * MILLIS_IN_SECOND)); timestamp.setNanos(value.getNano()); return timestamp; }
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());
/** * Converts the given OffsetDateTime to a Timestamp. * * @param offsetDateTime * the OffsetDateTime to convert * @return Timestamp object that is equivalent to the given OffsetDateTime. */ private static Timestamp toTimestamp(OffsetDateTime offsetDateTime) { long seconds = offsetDateTime.toEpochSecond(); int nanos = offsetDateTime.getNano(); long microseconds = TimeUnit.SECONDS.toMicros(seconds) + TimeUnit.NANOSECONDS.toMicros(nanos); return Timestamp.ofTimeMicroseconds(microseconds); }
@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 protected String toJsonNanos(OffsetDateTime value) { return toJsonNanos(value.toEpochSecond(), value.getNano()); }
@Override protected String toJsonNanos(OffsetDateTime value) { return toJsonNanos(value.toEpochSecond(), value.getNano()); }
@Override public ValueBuilder<?, ?, ?> toDatastore(Object input) { if (input == null) { return NullValue.newBuilder(); } OffsetDateTime offsetDateTime = (OffsetDateTime) input; long seconds = offsetDateTime.toEpochSecond(); int nanos = offsetDateTime.getNano(); long microseconds = TimeUnit.SECONDS.toMicros(seconds) + TimeUnit.NANOSECONDS.toMicros(nanos); return TimestampValue.newBuilder(Timestamp.ofTimeMicroseconds(microseconds)); }
@Override protected void encodeValue(Context context, Type type, Object value, Object sourceContext, ByteBuf buffer) throws IOException { Calendar calendar = sourceContext != null ? (Calendar) sourceContext : Calendar.getInstance(); OffsetDateTime dateTime = convertInput(context, type, value, calendar); long micros; if (dateTime.equals(OffsetDateTime.MAX)) { micros = Long.MAX_VALUE; } else if (dateTime.equals(OffsetDateTime.MIN)) { micros = Long.MIN_VALUE; } else { long seconds = javaEpochToPg(dateTime.toEpochSecond(), SECONDS); // Convert to micros rounding nanoseconds micros = SECONDS.toMicros(seconds) + NANOSECONDS.toMicros(dateTime.getNano() + 500); } buffer.writeLong(micros); }
public static LocalDateTime toLocalDateTimeInZone(OffsetDateTime dateTime, ZoneId zoneId) { return LocalDateTime.ofEpochSecond(dateTime.toEpochSecond(), dateTime.getNano(), zoneId.getRules().getOffset(dateTime.toInstant())); }
@Override public final void serialize(Writer writer, OffsetDateTime datetime) throws IOException { super.serialize(writer, datetime); OutputStream stream = writer.stream; if (!(datetime.getOffset().equals(ZoneOffset.UTC))) { stream.write(TagString); ValueWriter.write(stream, datetime.toString()); } else { int year = datetime.getYear(); if (year > 9999 || year < 1) { stream.write(TagString); ValueWriter.write(stream, datetime.toString()); } else { ValueWriter.writeDate(stream, year, datetime.getMonthValue(), datetime.getDayOfMonth()); ValueWriter.writeTime(stream, datetime.getHour(), datetime.getMinute(), datetime.getSecond(), 0, false, true); ValueWriter.writeNano(stream, datetime.getNano()); stream.write(TagUTC); } } } }
ChronoField f = (ChronoField) field; switch (f) { case INSTANT_SECONDS: return ofInstant(Instant.ofEpochSecond(newValue, getNano()), offset); case OFFSET_SECONDS: { return with(dateTime, ZoneOffset.ofTotalSeconds(f.checkValidIntValue(newValue)));
@Override public final void serialize(Writer writer, OffsetDateTime datetime) throws IOException { super.serialize(writer, datetime); OutputStream stream = writer.stream; if (!(datetime.getOffset().equals(ZoneOffset.UTC))) { stream.write(TagString); ValueWriter.write(stream, datetime.toString()); } else { int year = datetime.getYear(); if (year > 9999 || year < 1) { stream.write(TagString); ValueWriter.write(stream, datetime.toString()); } else { ValueWriter.writeDate(stream, year, datetime.getMonthValue(), datetime.getDayOfMonth()); ValueWriter.writeTime(stream, datetime.getHour(), datetime.getMinute(), datetime.getSecond(), 0, false, true); ValueWriter.writeNano(stream, datetime.getNano()); stream.write(TagUTC); } } } }
buf[pos + 17] = ':'; NumberConverter.write2(value.getSecond(), buf, pos + 18); final int nano = value.getNano(); if (nano != 0) { final int end = writeNano(buf, pos, nano);