Пример #1
0
  @Test
  public void testInstant() {
    // millisec since epoch
    long timestamp = System.currentTimeMillis();

    // point in time - now!
    Instant instant = Instant.now();
    long secEpoch = instant.getEpochSecond();

    // missing milli so divide by 1000
    Assert.assertEquals(timestamp / 1000, secEpoch);
    Assert.assertEquals(instant.getLong(ChronoField.INSTANT_SECONDS), secEpoch);

    Instant timestampInstant = Instant.ofEpochMilli(timestamp);
    Assert.assertEquals(timestamp, timestampInstant.truncatedTo(ChronoUnit.MILLIS).toEpochMilli());

    // different ways to go into the future
    Instant future1 = instant.plusMillis(1000);
    Instant future2 = instant.plus(1000, ChronoUnit.MILLIS);
    // add Duration instead of Period as this example is dealing with time
    Instant future3 = instant.plus(Duration.ofMillis(1000));
    Instant future4 = instant.plus(Duration.of(1000, ChronoUnit.MILLIS));

    // all futures are the same!
    Assert.assertEquals(future1, future2);
    Assert.assertEquals(future2, future3);
    Assert.assertEquals(future3, future4);
  }
Пример #2
0
  @Override
  public boolean test(final Object ignore) {
    if (_start == Instant.MIN) {
      _start = _clock.instant();
    }

    return _start.plus(_duration).isAfter(_clock.instant());
  }
Пример #3
0
 /**
  * @param newUid the newly scanned UID
  * @param oldUid the previously scanned code
  * @param lastScan the time of the last successful scan
  * @return Return true if the card is different OR if the previous card was scanned over 1 second
  *     before
  */
 private boolean isNewCard(String newUid, String oldUid, Instant lastScan) {
   return !newUid.equals(oldUid)
       || lastScan == null
       || (lastScan != null && lastScan.plus(1250, ChronoUnit.MILLIS).isBefore(Instant.now()));
 }