/** * Get NTP Timestamp at specified starting index. * * @param index index into data array * @return TimeStamp object for 64 bits starting at index */ private TimeStamp getTimestamp(int index) { return new TimeStamp(getLong(index)); }
/*** * Parses the string argument as a NTP hexidecimal timestamp representation string * (e.g. "c1a089bd.fc904f6d"). * * @param s - hexstring. * @return the Timestamp represented by the argument in hexidecimal. * @throws NumberFormatException - if the string does not contain a parsable timestamp. */ public static TimeStamp parseNtpString(String s) throws NumberFormatException { return new TimeStamp(decodeNtpHexString(s)); }
/*** * Helper method to convert Java time to NTP timestamp object. * Note that Java time (milliseconds) by definition has less precision * then NTP time (picoseconds) so converting Ntptime to Javatime and back * to Ntptime loses precision. For example, Tue, Dec 17 2002 09:07:24.810 * is represented by a single Java-based time value of f22cd1fc8a, but its * NTP equivalent are all values from c1a9ae1c.cf5c28f5 to c1a9ae1c.cf9db22c. * @param date the milliseconds since January 1, 1970, 00:00:00 GMT. * @return NTP timestamp object at the specified date. */ public static TimeStamp getNtpTime(long date) { return new TimeStamp(toNtpTime(date)); }
/** * Compares two NTP timestamps (non-numerically) * * @param time1 * @param time2 * @return 0 if equal, less than 0 if time1 < time2, more than 0 if time1 > time2 */ public static int compare(long time1, long time2) { TimeStamp t1 = new TimeStamp(time1); TimeStamp t2 = new TimeStamp(time2); return compare(t1, t2); }
/** * Compares two NTP timestamps (non-numerically) * * @param time1 * @param time2 * @return 0 if equal, less than 0 if time1 < time2, more than 0 if time1 > time2 */ public static int compare(long time1, long time2) { TimeStamp t1 = new TimeStamp(time1); TimeStamp t2 = new TimeStamp(time2); return compare(t1, t2); }
/*** * Get NTP Timestamp at specified starting index. * * @param index index into data array * @return TimeStamp object for 64 bits starting at index */ private TimeStamp getTimestamp(int index) { return new TimeStamp(getLong(index)); }
/*** * Get NTP Timestamp at specified starting index. * * @param index index into data array * @return TimeStamp object for 64 bits starting at index */ private TimeStamp getTimestamp(int index) { return new TimeStamp(getLong(index)); }
/*** * Parses the string argument as a NTP hexidecimal timestamp representation string * (e.g. "c1a089bd.fc904f6d"). * * @param s - hexstring. * @return the Timestamp represented by the argument in hexidecimal. * @throws NumberFormatException - if the string does not contain a parsable timestamp. */ public static TimeStamp parseNtpString(String s) throws NumberFormatException { return new TimeStamp(decodeNtpHexString(s)); }
/*** * Parses the string argument as a NTP hexidecimal timestamp representation string * (e.g. "c1a089bd.fc904f6d"). * * @param s - hexstring. * @return the Timestamp represented by the argument in hexidecimal. * @throws NumberFormatException - if the string does not contain a parsable timestamp. */ public static TimeStamp parseNtpString(String s) throws NumberFormatException { return new TimeStamp(decodeNtpHexString(s)); }
public HybridTimestamp(PhysicalTimeProvider physicalTimeProvider) { this(physicalTimeProvider, new TimeStamp(new Date(0)).ntpValue(), 0); }
public HybridTimestamp(PhysicalTimeProvider physicalTimeProvider) { this(physicalTimeProvider, new TimeStamp(new Date(0)).ntpValue(), 0); }
/*** * Helper method to convert Java time to NTP timestamp object. * Note that Java time (milliseconds) by definition has less precision * then NTP time (picoseconds) so converting Ntptime to Javatime and back * to Ntptime loses precision. For example, Tue, Dec 17 2002 09:07:24.810 * is represented by a single Java-based time value of f22cd1fc8a, but its * NTP equivalent are all values from c1a9ae1c.cf5c28f5 to c1a9ae1c.cf9db22c. * @param date the milliseconds since January 1, 1970, 00:00:00 GMT. * @return NTP timestamp object at the specified date. */ public static TimeStamp getNtpTime(long date) { return new TimeStamp(toNtpTime(date)); }
/*** * Helper method to convert Java time to NTP timestamp object. * Note that Java time (milliseconds) by definition has less precision * then NTP time (picoseconds) so converting Ntptime to Javatime and back * to Ntptime loses precision. For example, Tue, Dec 17 2002 09:07:24.810 * is represented by a single Java-based time value of f22cd1fc8a, but its * NTP equivalent are all values from c1a9ae1c.cf5c28f5 to c1a9ae1c.cf9db22c. * @param date the milliseconds since January 1, 1970, 00:00:00 GMT. * @return NTP timestamp object at the specified date. */ public static TimeStamp getNtpTime(long date) { return new TimeStamp(toNtpTime(date)); }
@Override public BigInteger getSerializableComparable() { TimeStamp t = new TimeStamp(logicalTime); return BigInteger.valueOf(t.getSeconds()) .shiftLeft(64) .add(BigInteger.valueOf(t.getFraction()).shiftLeft(32)) .add(BigInteger.valueOf(logicalCounter)); } }
@Test public void initialTimestamp() { HybridTimestamp timestamp = new HybridTimestamp(physicalTimeProvider); TimeStamp ntpTime = new TimeStamp(timestamp.getLogicalTime()); assertEquals(ntpTime.getDate(), new Date(0)); }
TimeStamp ntpTs = new TimeStamp(new Date(currentTime)); long ntpSec = ntpTs.getSeconds(); long ntpFrac = ntpTs.getFraction();
TimeStamp ntpTs = new TimeStamp(new Date(currentTime)); long ntpSec = ntpTs.getSeconds(); long ntpFrac = ntpTs.getFraction();