Merge pull request #5910 from alimate/BAEL-2428
BAEL 2428: Calculate Time Duration in Seconds
This commit is contained in:
commit
83acd92ba5
|
@ -8,6 +8,7 @@ import java.time.Duration;
|
|||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Period;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
@ -51,6 +52,16 @@ public class DateDiffUnitTest {
|
|||
assertEquals(diff, 6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoDateTimesInJava8_whenDifferentiatingInSeconds_thenWeGetTen() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime tenSecondsLater = now.plusSeconds(10);
|
||||
|
||||
long diff = ChronoUnit.SECONDS.between(now, tenSecondsLater);
|
||||
|
||||
assertEquals(diff, 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoZonedDateTimesInJava8_whenDifferentiating_thenWeGetSix() {
|
||||
LocalDateTime ldt = LocalDateTime.now();
|
||||
|
@ -60,6 +71,16 @@ public class DateDiffUnitTest {
|
|||
assertEquals(diff, 6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoDateTimesInJava8_whenDifferentiatingInSecondsUsingUntil_thenWeGetTen() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime tenSecondsLater = now.plusSeconds(10);
|
||||
|
||||
long diff = now.until(tenSecondsLater, ChronoUnit.SECONDS);
|
||||
|
||||
assertEquals(diff, 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoDatesInJodaTime_whenDifferentiating_thenWeGetSix() {
|
||||
org.joda.time.LocalDate now = org.joda.time.LocalDate.now();
|
||||
|
|
Loading…
Reference in New Issue