@Override public Instant getTime(long sinceEpoch) { return Instant.ofEpochSecond(0, (sinceEpoch * 1000L)); }
@Override public Instant getTime(long sinceEpoch) { return Instant.ofEpochSecond(0, sinceEpoch); }
@Override protected Instant parse(@Nullable final String input) throws Exception { return Instant.ofEpochSecond(Long.parseLong(input)); } }
private static ZonedDateTime newZonedDateTime( long epochSecondLocal, long nano, ZoneId zoneId ) { Instant instant = Instant.ofEpochSecond( epochSecondLocal, nano ); LocalDateTime localDateTime = LocalDateTime.ofInstant( instant, UTC ); return ZonedDateTime.of( localDateTime, zoneId ); } }
@JsonCreator public AtopSplit( @JsonProperty("table") AtopTable table, @JsonProperty("host") HostAddress host, @JsonProperty("epochSeconds") long epochSeconds, @JsonProperty("timeZone") ZoneId timeZone) { this.table = requireNonNull(table, "table name is null"); this.host = requireNonNull(host, "host is null"); requireNonNull(timeZone, "timeZone is null"); this.date = ZonedDateTime.ofInstant(ofEpochSecond(epochSeconds), timeZone); }
/** * format unix time to string * * @param unixTime unix time * @param pattern date format pattern * @return return string date */ public static String toString(long unixTime, String pattern) { return Instant.ofEpochSecond(unixTime).atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern(pattern)); }
/** * format unix time to string * * @param unixTime unix time * @param pattern date format pattern * @return return string date */ public static String toString(long unixTime, String pattern) { return Instant.ofEpochSecond(unixTime).atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern(pattern)); }
@Nullable private ZonedDateTime convertToZonedDateTime(Timestamp timestamp) { if (timestamp == null) { return null; } final Optional<ZoneId> zoneId = calendar.flatMap(c -> Optional.of(c.getTimeZone().toZoneId())); return ZonedDateTime.ofInstant( Instant.ofEpochSecond(timestamp.getTime() / 1000, timestamp.getNanos()), zoneId.orElse(ZoneId.systemDefault())); } }
public static ZonedDateTime datetimeRaw( long epochSecondUTC, long nano, ZoneId zone ) { return assertValidArgument( () -> ofInstant( ofEpochSecond( epochSecondUTC, nano ), zone ) ); }
public static LocalDateTime localDateTimeRaw( long epochSecond, long nano ) { return assertValidArgument( () -> ofInstant( ofEpochSecond( epochSecond, nano ), UTC ) ); }
@Nullable private OffsetDateTime convertToOffsetDateTime(Timestamp timestamp) { if (timestamp == null) { return null; } final Optional<ZoneId> zoneId = calendar.flatMap(c -> Optional.of(c.getTimeZone().toZoneId())); return OffsetDateTime.ofInstant( Instant.ofEpochSecond(timestamp.getTime() / 1000, timestamp.getNanos()), zoneId.orElse(ZoneId.systemDefault())); } }
private static OffsetTime readRawTime( ByteBuffer bb, int offset ) { final long nanosOfDayUTC = bb.getLong( offset ); offset += Long.BYTES; final int offsetSeconds = bb.getInt( offset ); return OffsetTime.ofInstant( Instant.ofEpochSecond( 0, nanosOfDayUTC ), ZoneOffset.ofTotalSeconds( offsetSeconds ) ); }
@Override public Instant deserialize(DataInputView source) throws IOException { final long seconds = source.readLong(); final int nanos = source.readInt(); if (seconds == NULL_SECONDS && nanos == NULL_NANOS) { return null; } return Instant.ofEpochSecond(seconds, nanos); }
@Override public Instant read(ScanBuffer buffer) { long seconds = secondsSerializer.read(buffer); long nanos = nanosSerializer.read(buffer); return Instant.ofEpochSecond(seconds, nanos); }
public static OffsetTime timeRaw( long nanosOfDayUTC, ZoneOffset offset ) { return OffsetTime.ofInstant( assertValidArgument( () -> Instant.ofEpochSecond( 0, nanosOfDayUTC ) ), offset ); }
@Override protected Instant[] getTestData() { final Random rnd = new Random(874597969123412341L); return new Instant[] { Instant.EPOCH, Instant.MIN, Instant.MAX, Instant.ofEpochSecond(rndSeconds(rnd), rndNanos(rnd)), Instant.ofEpochSecond(1534135584,949495), Instant.ofEpochSecond(56090783) }; } }
@Override public Object read( ReadableClosableChannel from ) throws IOException { return OffsetTime.ofInstant( Instant.ofEpochSecond( 0, from.getLong() ), ZoneOffset.ofTotalSeconds( from.getInt() ) ); }
private Instant nextInstantRaw() { return Instant.ofEpochSecond( longBetween( LocalDateTime.MIN.toEpochSecond( UTC ), LocalDateTime.MAX.toEpochSecond( UTC ) ), nextLong( NANOS_PER_SECOND ) ); }
@Before public void before() { time = 1505892010L; date = new Date(1505892470110L); localDateTime = LocalDateTime.from(Instant.ofEpochSecond(time).atZone(ZoneId.systemDefault())); }
@Test public void testMicro() { testRoundTrip(TimestampProviders.MICRO); Assert.assertEquals(Instant.ofEpochSecond(1000), TimestampProviders.MICRO.getTime(1000000000)); }