From 37896ced0ea040b8c9111e2b21458ac88e9a6e8a Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Mon, 8 Oct 2018 23:09:44 +0300 Subject: [PATCH] remove diff-dates module --- .../com/baeldung/date/DateDiffUnitTest.java | 13 ++++ java-difference-date/README.md | 5 -- java-difference-date/pom.xml | 36 ----------- .../java/com/baeldung/DateDiffUnitTest.java | 61 ------------------- pom.xml | 2 - 5 files changed, 13 insertions(+), 104 deletions(-) delete mode 100644 java-difference-date/README.md delete mode 100644 java-difference-date/pom.xml delete mode 100644 java-difference-date/src/test/java/com/baeldung/DateDiffUnitTest.java diff --git a/java-dates/src/test/java/com/baeldung/date/DateDiffUnitTest.java b/java-dates/src/test/java/com/baeldung/date/DateDiffUnitTest.java index 545009a2a9..58d192bfdb 100644 --- a/java-dates/src/test/java/com/baeldung/date/DateDiffUnitTest.java +++ b/java-dates/src/test/java/com/baeldung/date/DateDiffUnitTest.java @@ -5,7 +5,9 @@ import org.junit.Test; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.Duration; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.Period; import java.util.Date; import java.util.Locale; import java.util.TimeZone; @@ -26,6 +28,17 @@ public class DateDiffUnitTest { assertEquals(diff, 6); } + + @Test + public void givenTwoDatesInJava8_whenDifferentiating_thenWeGetSix() { + LocalDate now = LocalDate.now(); + LocalDate sixDaysBehind = now.minusDays(6); + + Period period = Period.between(now, sixDaysBehind); + int diff = period.getDays(); + + assertEquals(diff, 6); + } @Test public void givenTwoDateTimesInJava8_whenDifferentiating_thenWeGetSix() { diff --git a/java-difference-date/README.md b/java-difference-date/README.md deleted file mode 100644 index 2a024c27a2..0000000000 --- a/java-difference-date/README.md +++ /dev/null @@ -1,5 +0,0 @@ -## Relevant articles: - -- [Period and Duration in Java](http://www.baeldung.com/java-period-duration) -- [Introduction to the Java 8 Date/Time API](http://www.baeldung.com/java-8-date-time-intro) -- [Migrating to the New Java 8 Date Time API](http://www.baeldung.com/migrating-to-java-8-date-time-api) \ No newline at end of file diff --git a/java-difference-date/pom.xml b/java-difference-date/pom.xml deleted file mode 100644 index 8c87afc0a2..0000000000 --- a/java-difference-date/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - 4.0.0 - com.baeldung - java-difference-date - 0.0.1-SNAPSHOT - jar - java-difference-date - Difference between two dates in java - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - - joda-time - joda-time - ${joda-time.version} - - - com.darwinsys - hirondelle-date4j - ${hirondelle-date4j.version} - - - - - 2.9.9 - 1.5.1 - - - diff --git a/java-difference-date/src/test/java/com/baeldung/DateDiffUnitTest.java b/java-difference-date/src/test/java/com/baeldung/DateDiffUnitTest.java deleted file mode 100644 index 2c5323be6f..0000000000 --- a/java-difference-date/src/test/java/com/baeldung/DateDiffUnitTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.baeldung; - -import org.joda.time.DateTime; -import org.junit.Test; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.time.Duration; -import java.time.ZonedDateTime; -import java.util.Date; -import java.util.Locale; -import java.util.TimeZone; -import java.util.concurrent.TimeUnit; - -import static org.junit.Assert.assertEquals; - -public class DateDiffUnitTest { - @Test - public void givenTwoDatesBeforeJava8_whenDifferentiating_thenWeGetSix() throws ParseException { - SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH); - Date firstDate = sdf.parse("06/24/2017"); - Date secondDate = sdf.parse("06/30/2017"); - - long diffInMillies = Math.abs(secondDate.getTime() - firstDate.getTime()); - long diff = TimeUnit.DAYS.convert(diffInMillies, TimeUnit.MILLISECONDS); - - assertEquals(diff, 6); - } - - @Test - public void givenTwoDatesInJava8_whenDifferentiating_thenWeGetSix() { - ZonedDateTime now = ZonedDateTime.now(); - ZonedDateTime sixDaysBehind = now.minusDays(6); - - Duration duration = Duration.between(now, sixDaysBehind); - long diff = Math.abs(duration.toDays()); - - assertEquals(diff, 6); - } - - @Test - public void givenTwoDatesInJodaTime_whenDifferentiating_thenWeGetSix() { - DateTime now = DateTime.now(); - DateTime sixDaysBehind = now.minusDays(6); - - org.joda.time.Duration duration = new org.joda.time.Duration(now, sixDaysBehind); - long diff = Math.abs(duration.getStandardDays()); - - assertEquals(diff, 6); - } - - @Test - public void givenTwoDatesInDate4j_whenDifferentiating_thenWeGetSix() { - hirondelle.date4j.DateTime now = hirondelle.date4j.DateTime.now(TimeZone.getDefault()); - hirondelle.date4j.DateTime sixDaysBehind = now.minusDays(6); - - long diff = Math.abs(now.numDaysFrom(sixDaysBehind)); - - assertEquals(diff, 6); - } -} \ No newline at end of file diff --git a/pom.xml b/pom.xml index ef34881cef..569b6a62be 100644 --- a/pom.xml +++ b/pom.xml @@ -665,7 +665,6 @@ dubbo flyway - java-difference-date jni jooby @@ -1138,7 +1137,6 @@ dubbo flyway - java-difference-date jni jooby