Refine search
/** * Set a field from the current value in the scratch timestamp. * * This is a FAST version that assumes the caller has checked to make sure the current value in * the scratch timestamp is valid and elementNum is correctly adjusted for isRepeating. And, * that the isNull entry has been set. Only the output entry fields will be set by this method. * * @param elementNum */ public void setFromScratchTimestamp(int elementNum) { this.time[elementNum] = scratchTimestamp.getTime(); this.nanos[elementNum] = scratchTimestamp.getNanos(); }
/** * Tests to see if this timestamp is equal to a supplied timestamp. * * @param theTimestamp * the timestamp to compare with this {@code Timestamp} object, * passed as an {@code Object}. * @return {@code true} if this {@code Timestamp} object is equal to the * supplied {@code Timestamp} object, {@code false} otherwise. */ public boolean equals(Timestamp theTimestamp) { if (theTimestamp == null) { return false; } return (this.getTime() == theTimestamp.getTime()) && (this.getNanos() == theTimestamp.getNanos()); }
private static Timestamp dateadd(String part, int count, Timestamp d) { int field = getDatePart(part); Calendar calendar = Calendar.getInstance(); int nanos = d.getNanos() % 1000000; calendar.setTime(d); calendar.add(field, count); long t = calendar.getTime().getTime(); Timestamp ts = new Timestamp(t); ts.setNanos(ts.getNanos() + nanos); return ts; }
@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())); } }
/** * Set a field from a Timestamp. * * This is a FAST version that assumes the caller has checked to make sure elementNum * is correctly adjusted for isRepeating. And, that the isNull entry * has been set. Only the output entry fields will be set by this method. * * For backward compatibility, this method does check if the timestamp is null and set the * isNull entry appropriately. * * @param elementNum * @param timestamp */ public void set(int elementNum, Timestamp timestamp) { if (timestamp == null) { isNull[elementNum] = true; noNulls = false; return; } this.time[elementNum] = timestamp.getTime(); this.nanos[elementNum] = timestamp.getNanos(); }
@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())); } }
Timestamp ts = new Timestamp(millisDeserialized); int nanosDeserialized = decodeUnsignedInt(b, Bytes.SIZEOF_LONG); ts.setNanos(nanosDeserialized < 1000000 ? ts.getNanos() + nanosDeserialized : nanosDeserialized); v = ts; } else if (phType == PhType.UNSIGNED_TIME || phType == PhType.UNSIGNED_DATE) { Timestamp ts = new Timestamp(millisDeserialized); int nanosDeserialized = decodeUnsignedInt(b, Bytes.SIZEOF_LONG); ts.setNanos(nanosDeserialized < 1000000 ? ts.getNanos() + nanosDeserialized : nanosDeserialized); v = ts; } else if (phType == PhType.VARBINARY) {
/** * Return a double representation of a Timestamp. * @param timestamp * @return */ public static double getDouble(Timestamp timestamp) { // Same algorithm as TimestampWritable (not currently import-able here). double seconds, nanos; seconds = millisToSeconds(timestamp.getTime()); nanos = timestamp.getNanos(); return seconds + nanos / 1000000000; }