From 51e0ef40b859933c3226feb832752d9c225373b3 Mon Sep 17 00:00:00 2001 From: Ceki Gulcu Date: Fri, 24 Dec 2021 11:35:47 +0100 Subject: [PATCH] remove joda time dependency for tests Signed-off-by: Ceki Gulcu --- logback-core/pom.xml | 5 --- ...meBasedRollingWithArchiveRemoval_Test.java | 31 +++++++++++++------ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/logback-core/pom.xml b/logback-core/pom.xml index e5551f7f09..baafc22fda 100755 --- a/logback-core/pom.xml +++ b/logback-core/pom.xml @@ -65,11 +65,6 @@ compile true - - joda-time - joda-time - test - diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_Test.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_Test.java index 81ad0c1119..a7a5cc54a5 100755 --- a/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_Test.java +++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_Test.java @@ -19,6 +19,12 @@ import java.io.File; import java.io.FileFilter; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; +import java.time.Period; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; @@ -30,9 +36,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.joda.time.DateTimeZone; -import org.joda.time.Days; -import org.joda.time.LocalDate; +//import org.joda.time.DateTimeZone; +//import org.joda.time.Days; +//import org.joda.time.LocalDate; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -141,7 +147,7 @@ public void checkCrossedPeriodsWithDSTBarrier() { long SAT_2016_03_26_T_230705_CET = WED_2016_03_23_T_230705_CET + 3 * CoreConstants.MILLIS_IN_ONE_DAY; long MON_2016_03_28_T_000705_CET = SAT_2016_03_26_T_230705_CET + CoreConstants.MILLIS_IN_ONE_DAY; - int result = computeCrossedDayBarriers(SAT_2016_03_26_T_230705_CET, MON_2016_03_28_T_000705_CET, "CET"); + long result = computeCrossedDayBarriers(SAT_2016_03_26_T_230705_CET, MON_2016_03_28_T_000705_CET, "CET"); assertEquals(2, result); } @@ -150,14 +156,19 @@ private int computeCrossedDayBarriers(long currentTime, long millisAtEnd) { } private int computeCrossedDayBarriers(long currentTime, long millisAtEnd, String timeZoneID) { - DateTimeZone dateTimeZone = DateTimeZone.getDefault(); + ZoneId dateTimeZone = ZoneId.systemDefault(); if (timeZoneID != null) { - dateTimeZone = DateTimeZone.forID(timeZoneID); + dateTimeZone = ZoneId.of(timeZoneID); } - LocalDate startInstant = new LocalDate(currentTime, dateTimeZone); - LocalDate endInstant = new LocalDate(millisAtEnd, dateTimeZone); - Days days = Days.daysBetween(startInstant, endInstant); - return days.getDays(); + + Instant startInstant = Instant.ofEpochMilli(currentTime); + ZonedDateTime startZDT = startInstant.atZone(dateTimeZone); + + Instant endInstant = Instant.ofEpochMilli(millisAtEnd); + ZonedDateTime endZDT = endInstant.atZone(dateTimeZone); + + Period period = Period.between(startZDT.toLocalDate(), endZDT.toLocalDate()); + return period.getDays(); } @Test