Skip to content

Commit

Permalink
remove joda time dependency for tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <ceki@qos.ch>
  • Loading branch information
ceki committed Dec 24, 2021
1 parent 8b618b8 commit 51e0ef4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
5 changes: 0 additions & 5 deletions logback-core/pom.xml
Expand Up @@ -65,11 +65,6 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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
Expand Down

0 comments on commit 51e0ef4

Please sign in to comment.