/** * get current unix time * * @return return current unix time */ public static int nowUnix() { return (int) Instant.now().getEpochSecond(); }
/** * get current unix time * * @return return current unix time */ public static int nowUnix() { return (int) Instant.now().getEpochSecond(); }
public static int toUnix(Date date) { return (int) date.toInstant().getEpochSecond(); }
public static int toUnix(Date date) { return (int) date.toInstant().getEpochSecond(); }
/** * format string time to unix time * * @param time string date * @param pattern date format pattern * @return return unix time */ public static int toUnix(String time, String pattern) { LocalDateTime formatted = LocalDateTime.parse(time, DateTimeFormatter.ofPattern(pattern)); return (int) formatted.atZone(ZoneId.systemDefault()).toInstant().getEpochSecond(); }
/** * format string time to unix time * * @param time string date * @param pattern date format pattern * @return return unix time */ public static int toUnix(String time, String pattern) { LocalDateTime formatted = LocalDateTime.parse(time, DateTimeFormatter.ofPattern(pattern)); return (int) formatted.atZone(ZoneId.systemDefault()).toInstant().getEpochSecond(); }
@Override public long getTime(Instant timestamp) { return timestamp.getEpochSecond() * 1000000L + timestamp.getNano()/1000; } },
@Override public long getTime(Instant timestamp) { return timestamp.getEpochSecond() * 1000000000L + timestamp.getNano(); } },
@Override public long getTime(Instant timestamp) { return timestamp.getEpochSecond() * 1000 + timestamp.getNano() / 1000000; } };
private boolean expires(Session session) { long now = Instant.now().getEpochSecond(); return session.expired() < now; }
private boolean expires(Session session) { long now = Instant.now().getEpochSecond(); return session.expired() < now; }
private static long rndSeconds(Random rnd) { return (long) (Instant.MIN.getEpochSecond() + rnd.nextDouble() * (Instant.MAX.getEpochSecond() - Instant.MIN.getEpochSecond())); }
@Override public void write(WriteBuffer buffer, Instant attribute) { secondsSerializer.write(buffer, attribute.getEpochSecond()); nanosSerializer.write(buffer,attribute.getNano()); } }
@Override public void serialize(Instant record, DataOutputView target) throws IOException { if (record == null) { target.writeLong(NULL_SECONDS); target.writeInt(NULL_NANOS); } else { target.writeLong(record.getEpochSecond()); target.writeInt(record.getNano()); } }
@Test public void getClaimAsInstantWhenIntegerTypeSecondsThenReturnInstant() { Instant expectedClaimValue = Instant.now(); String claimName = "integerSeconds"; this.claims.put(claimName, Long.valueOf(expectedClaimValue.getEpochSecond()).intValue()); assertThat(this.claimAccessor.getClaimAsInstant(claimName)).isBetween( expectedClaimValue.minusSeconds(1), expectedClaimValue.plusSeconds(1)); }
@Test public void getClaimAsInstantWhenDoubleTypeSecondsThenReturnInstant() { Instant expectedClaimValue = Instant.now(); String claimName = "doubleSeconds"; this.claims.put(claimName, Long.valueOf(expectedClaimValue.getEpochSecond()).doubleValue()); assertThat(this.claimAccessor.getClaimAsInstant(claimName)).isBetween( expectedClaimValue.minusSeconds(1), expectedClaimValue.plusSeconds(1)); }
@Test public void getClaimAsInstantWhenLongTypeSecondsThenReturnInstant() { Instant expectedClaimValue = Instant.now(); String claimName = "longSeconds"; this.claims.put(claimName, expectedClaimValue.getEpochSecond()); assertThat(this.claimAccessor.getClaimAsInstant(claimName)).isBetween( expectedClaimValue.minusSeconds(1), expectedClaimValue.plusSeconds(1)); }
@Test void shouldReportTooHighEpochSecondDateTimeRecordWithNamedTZ() { // given PropertyRecord property = inUse( new PropertyRecord( 42 ) ); final int keyId = 6; add( inUse( new PropertyKeyTokenRecord( keyId ) ) ); final long[] longs = TemporalType.encodeDateTime( keyId, Instant.MAX.getEpochSecond() + 1,1, "Europe/London" ); expectInvalidPropertyValue( property, longs ); }
@Test void shouldReportTooHighEpochSecondLocalDateTimeRecord() { // given PropertyRecord property = inUse( new PropertyRecord( 42 ) ); final int keyId = 6; add( inUse( new PropertyKeyTokenRecord( keyId ) ) ); final long[] longs = TemporalType.encodeLocalDateTime( keyId, Instant.MAX.getEpochSecond() + 1,1 ); expectInvalidPropertyValue( property, longs ); }
@Test void shouldReportTooHighEpochSecondDateTimeRecord() { // given PropertyRecord property = inUse( new PropertyRecord( 42 ) ); final int keyId = 6; add( inUse( new PropertyKeyTokenRecord( keyId ) ) ); final long[] longs = TemporalType.encodeDateTime( keyId, Instant.MAX.getEpochSecond() + 1,1, 0 ); expectInvalidPropertyValue( property, longs ); }