/** * Retrieves the time as long based on the byte[] representation of a UUID. * * @param uuid byte[] uuid representation * @return a long representing the time */ public static long getTimeFromUUID(byte[] uuid) { return getTimeFromUUID(TimeUUIDUtils.toUUID(uuid)); }
@Test public void testDateUUIDConversion() { long originalTime = System.currentTimeMillis(); Date originalDate = new Date(originalTime); UUID originalUUID = TimeUUIDUtils.getTimeUUID(originalTime); long currentTime = TimeUUIDUtils.getTimeFromUUID(originalUUID); assertEquals(originalTime, currentTime); assertEquals(originalDate, new Date(currentTime)); }
final long actual1 = TimeUUIDUtils.getTimeFromUUID(TimeUUIDUtils.asByteArray(u1)); log.info("Java UUID to bytes to time: " + actual1); log.info("Java UUID to bytes time to Date: " + new Date(actual1)); final long actual2 = TimeUUIDUtils.getTimeFromUUID(u1); log.info("Java UUID to time: " + actual2); log.info("Java UUID to time to Date: " + new Date(actual2));
@Test public void testTimeUUIDAsByteArray() { // Generate UUID, convert to array and back to UUID. Then assert. UUID uuid = TimeUUIDUtils.getUniqueTimeUUIDinMillis(); UUID uuidAfterConversion = TimeUUIDUtils.toUUID(TimeUUIDUtils.asByteArray(uuid)); assertEquals(uuid, uuidAfterConversion); // Used the previously generated UUID, convert to array and back to UUID. Then compare their times. long timeInUUID = TimeUUIDUtils.getTimeFromUUID(TimeUUIDUtils.asByteArray(uuid)); assertEquals((uuid.timestamp() - 0x01b21dd213814000L) / 10000, timeInUUID); }
/** * Retrieves the time as long based on the byte[] representation of a UUID. * * @param uuid byte[] uuid representation * @return a long representing the time */ public static long getTimeFromUUID(byte[] uuid) { return getTimeFromUUID(TimeUUIDUtils.toUUID(uuid)); }
/** * Retrieves the time as long based on the byte[] representation of a UUID. * * @param uuid byte[] uuid representation * @return a long representing the time */ public static long getTimeFromUUID(byte[] uuid) { return getTimeFromUUID(TimeUUIDUtils.toUUID(uuid)); }