PreciseTimestamp implements Timestamp { @Override public long calcDifferenceInNanoseconds(final Timestamp other) { Instant otherInstant = other.toInstant(); long result = this.instant.getEpochSecond() - otherInstant.getEpochSecond(); result *= SECOND_IN_MILLIS * MILLISECOND_IN_NANOS; result -= otherInstant.getNano(); result += this.instant.getNano(); return result; } PreciseTimestamp();  PreciseTimestamp(final long milliseconds, final long nanoseconds); @Override Date toDate(); @Override Instant toInstant(); @Override java.sql.Timestamp toSqlTimestamp(); @Override long calcDifferenceInNanoseconds(final Timestamp other);  }
@Test public void calcDifferenceInNanoseconds() { PreciseTimestamp first = create(LocalDate.of(1985, 6, 3), LocalTime.of(12, 30, 50, 500_000_000)); PreciseTimestamp second = create(LocalDate.of(1985, 6, 3), LocalTime.of(14, 33, 54, 505_000_001)); long nanoseconds = second.calcDifferenceInNanoseconds(first); assertThat(nanoseconds).isEqualTo((((2L * 60L + 3) * 60L + 4L) * 1000L + 5L) * 1_000_000L + 1L); }