/** * Get the time in millis of this temporal object (either numeric interpreted as millisecond time * in GMT, Date, or Calendar) * * @param timeObj The temporal object * @return The time in milliseconds since the epoch in GMT */ public static long getTimeMillis(final Object timeObj) { // handle dates, calendars, and Numbers only if (timeObj != null) { if (timeObj instanceof Calendar) { return calendarToGMTMillis(((Calendar) timeObj)); } else if (timeObj instanceof Date) { return ((Date) timeObj).getTime(); } else if (timeObj instanceof Number) { return ((Number) timeObj).longValue(); } else { LOGGER.warn( "Time value '" + timeObj + "' of type '" + timeObj.getClass() + "' is not of expected temporal type"); } } return RESERVED_MILLIS_FOR_NULL; }
@Override public byte[] writeField(final Calendar cal) { if (cal == null) { return new byte[] {}; } long time = TimeUtils.calendarToGMTMillis(cal); final ByteBuffer buf = ByteBuffer.allocate(VarintUtils.timeByteLength(time)); VarintUtils.writeTime(time, buf); return buf.array(); } }