@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; } };
public int getNano() { return this.instant.getNano(); }
@Override public long getTime(Instant timestamp) { return timestamp.getEpochSecond() * 1000000000L + timestamp.getNano(); } },
@Override public long getTime(Instant timestamp) { return timestamp.getEpochSecond() * 1000000L + timestamp.getNano()/1000; } },
@Override public long getTime(Instant timestamp) { return timestamp.getEpochSecond() * 1000 + timestamp.getNano() / 1000000; } };
public int getNanos() { return zonedDateTime.toInstant().getNano(); }
@Override public void writeObject(ObjectOutput output, Instant instant) throws IOException { output.writeLong(instant.getEpochSecond()); output.writeInt(instant.getNano()); }
/** * Get the number of nanoseconds past epoch of the given {@link Instant}. * * @param instant the Java instant value * @return the epoch nanoseconds */ public static long toEpochNanos(Instant instant) { return TimeUnit.NANOSECONDS.convert(instant.getEpochSecond() * MICROSECONDS_PER_SECOND + instant.getNano() / NANOSECONDS_PER_MICROSECOND, TimeUnit.MICROSECONDS); } }
private Object putSecondWithFractionIfValid(final Map<String, Object> hash, final String key, final Instant value) { if (value != null) { if (value.getNano() == 0) { return hash.put(key, value.getEpochSecond()); } else { return hash.put(key, BigDecimal.valueOf(value.getEpochSecond()).add(BigDecimal.valueOf(value.getNano(), 9))); } } return null; }
private Object convertValue(Object value) throws BackendException { if (value instanceof Geoshape) { return GeoToWktConverter.convertToWktString((Geoshape) value); } if (value instanceof UUID) { return value.toString(); } if(value instanceof Instant) { if(Math.floorMod(((Instant) value).getNano(), 1000000) != 0) { throw new IllegalArgumentException("Solr indexes do not support nanoseconds"); } return new Date(((Instant) value).toEpochMilli()); } return value; }
private static long currentTimeMicros() { if (PlatformDependent.javaVersion() == 8) { return TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()); } else { // Java 9+ support higher precision wall time. final Instant now = Clock.systemUTC().instant(); return TimeUnit.SECONDS.toMicros(now.getEpochSecond()) + TimeUnit.NANOSECONDS.toMicros( now.getNano()); } } }
@Override public void write(WriteBuffer buffer, Instant attribute) { secondsSerializer.write(buffer, attribute.getEpochSecond()); nanosSerializer.write(buffer,attribute.getNano()); } }
@Override public void write(WriteBuffer buffer, Instant attribute) { secondsSerializer.write(buffer, attribute.getEpochSecond()); nanosSerializer.write(buffer,attribute.getNano()); } }
@Override public String toString() { final int nano = this.instant.getNano(); if (nano == 0) { return FORMATTER_SECONDS.format(this.instant) + " UTC"; } else if (nano % 1000000 == 0) { return FORMATTER_MILLISECONDS.format(this.instant) + " UTC"; } else { final StringBuilder builder = new StringBuilder(); FORMATTER_SECONDS.formatTo(this.instant, builder); builder.append("."); final String digits; final int zeroDigits; if (nano % 1000 == 0) { digits = Integer.toString(nano / 1000); zeroDigits = 6 - digits.length(); } else { digits = Integer.toString(nano); zeroDigits = 9 - digits.length(); } builder.append(digits); for (int i = 0; i < zeroDigits; i++) { builder.append('0'); } builder.append(" UTC"); return builder.toString(); } }
@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()); } }
@Override public void putNormalizedKey(Instant record, MemorySegment target, int offset, int numBytes) { final int secondsBytes = InstantSerializer.SECONDS_BYTES; final long normalizedSeconds = record.getEpochSecond() - SECONDS_MIN_VALUE; if (numBytes >= secondsBytes) { target.putLongBigEndian(offset, normalizedSeconds); offset += secondsBytes; numBytes -= secondsBytes; final int nanosBytes = InstantSerializer.NANOS_BYTES; if (numBytes >= nanosBytes) { target.putIntBigEndian(offset, record.getNano()); offset += nanosBytes; numBytes -= nanosBytes; for (int i = 0; i < numBytes; i++) { target.put(offset + i, (byte) 0); } } else { final int nanos = record.getNano(); for (int i = 0; i < numBytes; i++) { target.put(offset + i, (byte) (nanos >>> ((3 - i) << 3))); } } } else { for (int i = 0; i < numBytes; i++) { target.put(offset + i, (byte) (normalizedSeconds >>> ((7 - i) << 3))); } } }
/** * 将当前时区时间转成UTC时间. * * @param dateTime 时间 * @return LocalDateTime */ public static LocalDateTime toUTCDateTime(final LocalDateTime dateTime) { if (dateTime == null) { return null; } else { Instant instant = dateTime.toInstant(DEFAULT_ZONE.getRules().getOffset(dateTime)); return LocalDateTime.ofEpochSecond(instant.getEpochSecond(), instant.getNano(), ZoneOffset.UTC); } }
@Override public Mono<Boolean> expireAt(K key, Instant expireAt) { Assert.notNull(key, "Key must not be null!"); Assert.notNull(expireAt, "Expire at must not be null!"); if (expireAt.getNano() == 0) { return createMono(connection -> connection.keyCommands() // .expireAt(rawKey(key), expireAt)); } return createMono(connection -> connection.keyCommands().pExpireAt(rawKey(key), expireAt)); }