diff --git a/core-java-modules/core-java-8-datetime-2/src/main/java/com/baeldung/maxdate/DateComparison.java b/core-java-modules/core-java-8-datetime-2/src/main/java/com/baeldung/maxdate/DateComparison.java new file mode 100644 index 0000000000..d6450670a2 --- /dev/null +++ b/core-java-modules/core-java-8-datetime-2/src/main/java/com/baeldung/maxdate/DateComparison.java @@ -0,0 +1,18 @@ +package com.baeldung.maxdate; + +import java.util.Date; + +public class DateComparison { + public int compareTodayWithMaxDate() { + Date today = new Date(); + Date maxDate = new Date(Long.MAX_VALUE); + + int comparisonResult = today.compareTo(maxDate); + return comparisonResult; + } + + public static void main(String[] args) { + DateComparison comparator = new DateComparison(); + System.out.println(comparator.compareTodayWithMaxDate()); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-8-datetime-2/src/main/java/com/baeldung/maxdate/MaxDateDisplay.java b/core-java-modules/core-java-8-datetime-2/src/main/java/com/baeldung/maxdate/MaxDateDisplay.java new file mode 100644 index 0000000000..b79b5f4422 --- /dev/null +++ b/core-java-modules/core-java-8-datetime-2/src/main/java/com/baeldung/maxdate/MaxDateDisplay.java @@ -0,0 +1,18 @@ +package com.baeldung.maxdate; + +import java.util.Date; +import java.text.SimpleDateFormat; + +public class MaxDateDisplay { + public String getMaxDateValue() { + Date maxDate = new Date(Long.MAX_VALUE); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); + return "The maximum date value in Java is: " + sdf.format(maxDate); + } + + public static void main(String[] args) { + MaxDateDisplay display = new MaxDateDisplay(); + System.out.println(display.getMaxDateValue()); + } +} + diff --git a/core-java-modules/core-java-8-datetime-2/src/test/java/com/baeldung/maxdate/DateComparisonUnitTest.java b/core-java-modules/core-java-8-datetime-2/src/test/java/com/baeldung/maxdate/DateComparisonUnitTest.java new file mode 100644 index 0000000000..70aef126da --- /dev/null +++ b/core-java-modules/core-java-8-datetime-2/src/test/java/com/baeldung/maxdate/DateComparisonUnitTest.java @@ -0,0 +1,16 @@ +package com.baeldung.maxdate; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +class DateComparisonUnitTest { + + @Test + void whenCompareTodayWithMaxDate_thenCorrectResult() { + DateComparison comparator = new DateComparison(); + int result = comparator.compareTodayWithMaxDate(); + + assertTrue(result < 0); + } +} diff --git a/core-java-modules/core-java-8-datetime-2/src/test/java/com/baeldung/maxdate/MaxDateDisplayUnitTest.java b/core-java-modules/core-java-8-datetime-2/src/test/java/com/baeldung/maxdate/MaxDateDisplayUnitTest.java new file mode 100644 index 0000000000..dd7000bd29 --- /dev/null +++ b/core-java-modules/core-java-8-datetime-2/src/test/java/com/baeldung/maxdate/MaxDateDisplayUnitTest.java @@ -0,0 +1,18 @@ +package com.baeldung.maxdate; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +class MaxDateDisplayUnitTest { + + @Test + void whenGetMaxDate_thenCorrectResult() { + MaxDateDisplay display = new MaxDateDisplay(); + String result = display.getMaxDateValue(); + assertEquals( + "The maximum date value in Java is: 292278994-08-17 07:12:55.807", + result + ); + } +}