@Test public void testIsAlmostSameInstant() { Instant now = Instant.now(); Instant twoSecondsLater = now.plusSeconds(2); assertThat(serviceHelper.isAlmostSameInstant(now, twoSecondsLater)).isFalse(); Instant oneSecondLater = now.plusSeconds(1); assertThat(serviceHelper.isAlmostSameInstant(now, oneSecondLater)).isFalse(); Instant haveSecondLater = now.plus(500000, ChronoUnit.MICROS); assertThat(serviceHelper.isAlmostSameInstant(now, haveSecondLater)).isTrue(); }
public boolean isAlmostSameInstant(Instant dt1, Instant dt2) { long diff = dt1.toEpochMilli() - dt2.toEpochMilli(); diff = Math.abs(diff); if (diff < TimeUnit.SECONDS.toMillis(1)) { return true; } return false; }
ServiceHelper { public boolean isAlmostSameInstant(Instant dt1, Instant dt2) { long diff = dt1.toEpochMilli() - dt2.toEpochMilli(); diff = Math.abs(diff); if (diff < TimeUnit.SECONDS.toMillis(1)) { return true; } return false; } }
ServiceHelper { public boolean isAlmostSameInstant(Instant dt1, Instant dt2) { long diff = dt1.toEpochMilli() - dt2.toEpochMilli(); diff = Math.abs(diff); if (diff < TimeUnit.SECONDS.toMillis(1)) { return true; } return false; }  }
ServiceHelper { public boolean isAlmostSameInstant(Instant dt1, Instant dt2) { long diff = dt1.toEpochMilli() - dt2.toEpochMilli(); diff = Math.abs(diff); if (diff < TimeUnit.SECONDS.toMillis(1)) { return true; } return false; }  @Async(AppConfig.ASYNC_EXECUTOR_NAME) void syncUserAsync(String userId); @Async(AppConfig.ASYNC_EXECUTOR_NAME) void trackEventAsync(String userId, String eventName); void sendSmsGreeting(String userId); boolean isAlmostSameInstant(Instant dt1, Instant dt2); void handleError(ILogger log, String errMsg); void handleException(ILogger log, Exception ex, String errMsg); }
ServiceHelper { public boolean isAlmostSameInstant(Instant dt1, Instant dt2) { long diff = dt1.toEpochMilli() - dt2.toEpochMilli(); diff = Math.abs(diff); if (diff < TimeUnit.SECONDS.toMillis(1)) { return true; } return false; }  @Async(AppConfig.ASYNC_EXECUTOR_NAME) void syncUserAsync(String userId); @Async(AppConfig.ASYNC_EXECUTOR_NAME) void trackEventAsync(String userId, String eventName); void sendSmsGreeting(String userId); boolean isAlmostSameInstant(Instant dt1, Instant dt2); void handleError(ILogger log, String errMsg); void handleException(ILogger log, Exception ex, String errMsg);  }