Skip to content

Commit 79285e3

Browse files
jeetkunecoderjzheaux
authored andcommitted
BAEL-2234 Dates difference with ZonedDateTimes (eugenp#5445)
1 parent c9f2162 commit 79285e3

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎java-dates/src/test/java/com/baeldung/date/DateDiffUnitTest.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ public void givenTwoDateTimesInJava8_whenDifferentiating_thenWeGetSix() {
5151
assertEquals(diff, 6);
5252
}
5353

54+
@Test
55+
public void givenTwoZonedDateTimesInJava8_whenDifferentiating_thenWeGetSix() {
56+
LocalDateTime ldt = LocalDateTime.now();
57+
ZonedDateTime now = ldt.atZone(ZoneId.of("America/Montreal"));
58+
ZonedDateTime sixDaysBehind = now.withZoneSameInstant(ZoneId.of("Asia/Singapore")).minusDays(6);
59+
long diff = ChronoUnit.DAYS.between(sixDaysBehind, now);
60+
assertEquals(diff, 6);
61+
}
62+
5463
@Test
5564
public void givenTwoDatesInJodaTime_whenDifferentiating_thenWeGetSix() {
5665
org.joda.time.LocalDate now = org.joda.time.LocalDate.now();

0 commit comments

Comments
 (0)