Add FileUtils.isFileNewer(File, ChronoLocalDate, OffsetTime).
Add FileUtils.isFileNewer(File, OffsetDateTime).
Add FileUtils.isFileOlder(File, ChronoLocalDate, OffsetTime).
Add FileUtils.isFileOlder(File, OffsetDateTime).
MODIFY
src/changes/changes.xml
src/changes/changes.xml
@@ -372,7 +372,13 @@ The <action> type attribute can be add,update,fix,remove.
Add PathUtils.touch(Path).
</action>
<action dev="ggregory" type="add" due-to="Gary Gregory">
- Add Add FileSystem.getIllegalFileNameCodePoints().
+ Add FileSystem.getIllegalFileNameCodePoints().
+ </action>
+ <action dev="ggregory" type="add" due-to="Isira Seneviratne, Gary Gregory">
+ Add FileUtils.isFileNewer(File, ChronoLocalDate, OffsetTime).
+ Add FileUtils.isFileNewer(File, OffsetDateTime).
+ Add FileUtils.isFileOlder(File, ChronoLocalDate, OffsetTime).
+ Add FileUtils.isFileOlder(File, OffsetDateTime).
</action>
<!-- UPDATE -->
<action dev="kinow" type="update" due-to="Dependabot, Gary Gregory">

MODIFY
src/main/java/org/apache/commons/io/FileUtils.java
src/main/java/org/apache/commons/io/FileUtils.java
import java.time.Duration;
import java.time.Instant;
import java.time.LocalTime;
+import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.ZoneId;
import java.time.chrono.ChronoLocalDate;
@@ -1497,7 +1498,7 @@ public static String getUserDirectoryPath() {
/**
* Tests whether the specified {@link File} is a directory or not. Implemented as a
- * null-safe delegate to {@code Files.isDirectory(Path path, LinkOption... options)}.
+ * null-safe delegate to {@link Files#isDirectory(Path path, LinkOption... options)}.
*
* @param file the path to the file.
* @param options options indicating how symbolic links are handled
@@ -1571,6 +1572,24 @@ public static boolean isFileNewer(final File file, final ChronoLocalDate chronoL
return isFileNewer(file, chronoLocalDate.atTime(localTime));
}
+ /**
+ * Tests if the specified {@link File} is newer than the specified {@link ChronoLocalDate} at the specified
+ * {@link OffsetTime}.
+ *
+ * @param file the {@link File} of which the modification date must be compared
+ * @param chronoLocalDate the date reference
+ * @param offsetTime the time reference
+ * @return true if the {@link File} exists and has been modified after the given {@link ChronoLocalDate} at the given
+ * {@link OffsetTime}.
+ * @throws NullPointerException if the file, local date or zone ID is {@code null}
+ * @since 2.12.0
+ */
+ public static boolean isFileNewer(final File file, final ChronoLocalDate chronoLocalDate, final OffsetTime offsetTime) {
+ Objects.requireNonNull(chronoLocalDate, "chronoLocalDate");
+ Objects.requireNonNull(offsetTime, "offsetTime");
+ return isFileNewer(file, chronoLocalDate.atTime(offsetTime.toLocalTime()));
+ }
+
/**
* Tests if the specified {@link File} is newer than the specified {@link ChronoLocalDateTime}
* at the system-default time zone.
@@ -1697,6 +1716,20 @@ public static boolean isFileNewer(final File file, final long timeMillis) {
return UncheckedIO.get(() -> PathUtils.isNewer(file.toPath(), timeMillis));
}
+ /**
+ * Tests if the specified {@link File} is newer than the specified {@link OffsetDateTime}.
+ *
+ * @param file the {@link File} of which the modification date must be compared
+ * @param offsetDateTime the date reference
+ * @return true if the {@link File} exists and has been modified before the given {@link OffsetDateTime}.
+ * @throws NullPointerException if the file or zoned date time is {@code null}
+ * @since 2.12.0
+ */
+ public static boolean isFileNewer(final File file, final OffsetDateTime offsetDateTime) {
+ Objects.requireNonNull(offsetDateTime, "offsetDateTime");
+ return isFileNewer(file, offsetDateTime.toInstant());
+ }
+
/**
* Tests if the specified {@link File} is older than the specified {@link ChronoLocalDate}
* at the current time.
@@ -1745,6 +1778,24 @@ public static boolean isFileOlder(final File file, final ChronoLocalDate chronoL
return isFileOlder(file, chronoLocalDate.atTime(localTime));
}
+ /**
+ * Tests if the specified {@link File} is older than the specified {@link ChronoLocalDate} at the specified
+ * {@link OffsetTime}.
+ *
+ * @param file the {@link File} of which the modification date must be compared
+ * @param chronoLocalDate the date reference
+ * @param offsetTime the time reference
+ * @return true if the {@link File} exists and has been modified after the given {@link ChronoLocalDate} at the given
+ * {@link OffsetTime}.
+ * @throws NullPointerException if the file, local date or zone ID is {@code null}
+ * @since 2.12.0
+ */
+ public static boolean isFileOlder(final File file, final ChronoLocalDate chronoLocalDate, final OffsetTime offsetTime) {
+ Objects.requireNonNull(chronoLocalDate, "chronoLocalDate");
+ Objects.requireNonNull(offsetTime, "offsetTime");
+ return isFileOlder(file, chronoLocalDate.atTime(offsetTime.toLocalTime()));
+ }
+
/**
* Tests if the specified {@link File} is older than the specified {@link ChronoLocalDateTime}
* at the system-default time zone.
@@ -1869,9 +1920,23 @@ public static boolean isFileOlder(final File file, final long timeMillis) {
return UncheckedIO.get(() -> PathUtils.isOlder(file.toPath(), timeMillis));
}
+ /**
+ * Tests if the specified {@link File} is older than the specified {@link OffsetDateTime}.
+ *
+ * @param file the {@link File} of which the modification date must be compared
+ * @param offsetDateTime the date reference
+ * @return true if the {@link File} exists and has been modified before the given {@link OffsetDateTime}.
+ * @throws NullPointerException if the file or zoned date time is {@code null}
+ * @since 2.12.0
+ */
+ public static boolean isFileOlder(final File file, final OffsetDateTime offsetDateTime) {
+ Objects.requireNonNull(offsetDateTime, "offsetDateTime");
+ return isFileOlder(file, offsetDateTime.toInstant());
+ }
+
/**
* Tests whether the specified {@link File} is a regular file or not. Implemented as a
- * null-safe delegate to {@code Files.isRegularFile(Path path, LinkOption... options)}.
+ * null-safe delegate to {@link Files#isRegularFile(Path path, LinkOption... options)}.
*
* @param file the path to the file.
* @param options options indicating how symbolic links are handled

MODIFY
src/test/java/org/apache/commons/io/FileUtilsTest.java
src/test/java/org/apache/commons/io/FileUtilsTest.java
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.OffsetDateTime;
+import java.time.OffsetTime;
import java.time.ZoneId;
+import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Arrays;
@@ -1684,10 +1687,12 @@ public void testIsFileNewerOlder() throws Exception {
final long now = date.getTime();
final Instant instant = date.toInstant();
final ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, ZoneId.systemDefault());
+ final OffsetDateTime offsetDateTime = zonedDateTime.toOffsetDateTime();
final LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
final LocalDate localDate = zonedDateTime.toLocalDate();
final LocalDate localDatePlusDay = localDate.plusDays(1);
final LocalTime localTime = LocalTime.ofSecondOfDay(0);
+ final OffsetTime offsetTime = OffsetTime.of(localTime, ZoneOffset.UTC);
do {
try {
@@ -1714,24 +1719,30 @@ public void testIsFileNewerOlder() throws Exception {
assertFalse(FileUtils.isFileNewer(oldFile, now), "Old File - Newer - Mili");
assertFalse(FileUtils.isFileNewer(oldFile, instant), "Old File - Newer - Instant");
assertFalse(FileUtils.isFileNewer(oldFile, zonedDateTime), "Old File - Newer - ZonedDateTime");
+ assertFalse(FileUtils.isFileNewer(oldFile, offsetDateTime), "Old File - Newer - OffsetDateTime");
assertFalse(FileUtils.isFileNewer(oldFile, localDateTime), "Old File - Newer - LocalDateTime");
assertFalse(FileUtils.isFileNewer(oldFile, localDateTime, ZoneId.systemDefault()), "Old File - Newer - LocalDateTime,ZoneId");
assertFalse(FileUtils.isFileNewer(oldFile, localDate), "Old File - Newer - LocalDate");
- assertTrue(FileUtils.isFileNewer(oldFile, localDate, localTime), "Old File - Newer - LocalDate,ZoneId");
+ assertTrue(FileUtils.isFileNewer(oldFile, localDate, localTime), "Old File - Newer - LocalDate,LocalTime");
+ assertTrue(FileUtils.isFileNewer(oldFile, localDate, offsetTime), "Old File - Newer - LocalDate,OffsetTime");
assertFalse(FileUtils.isFileNewer(oldFile, localDatePlusDay), "Old File - Newer - LocalDate plus one day");
- assertFalse(FileUtils.isFileNewer(oldFile, localDatePlusDay, localTime), "Old File - Newer - LocalDate plus one day,ZoneId");
+ assertFalse(FileUtils.isFileNewer(oldFile, localDatePlusDay, localTime), "Old File - Newer - LocalDate plus one day,LocalTime");
+ assertFalse(FileUtils.isFileNewer(oldFile, localDatePlusDay, offsetTime), "Old File - Newer - LocalDate plus one day,OffsetTime");
assertTrue(FileUtils.isFileNewer(newFile, reference), "New File - Newer - File");
assertTrue(FileUtils.isFileNewer(newFile, date), "New File - Newer - Date");
assertTrue(FileUtils.isFileNewer(newFile, now), "New File - Newer - Mili");
assertTrue(FileUtils.isFileNewer(newFile, instant), "New File - Newer - Instant");
assertTrue(FileUtils.isFileNewer(newFile, zonedDateTime), "New File - Newer - ZonedDateTime");
+ assertTrue(FileUtils.isFileNewer(newFile, offsetDateTime), "New File - Newer - OffsetDateTime");
assertTrue(FileUtils.isFileNewer(newFile, localDateTime), "New File - Newer - LocalDateTime");
assertTrue(FileUtils.isFileNewer(newFile, localDateTime, ZoneId.systemDefault()), "New File - Newer - LocalDateTime,ZoneId");
assertFalse(FileUtils.isFileNewer(newFile, localDate), "New File - Newer - LocalDate");
- assertTrue(FileUtils.isFileNewer(newFile, localDate, localTime), "New File - Newer - LocalDate,ZoneId");
+ assertTrue(FileUtils.isFileNewer(newFile, localDate, localTime), "New File - Newer - LocalDate,LocalTime");
+ assertTrue(FileUtils.isFileNewer(newFile, localDate, offsetTime), "New File - Newer - LocalDate,OffsetTime");
assertFalse(FileUtils.isFileNewer(newFile, localDatePlusDay), "New File - Newer - LocalDate plus one day");
- assertFalse(FileUtils.isFileNewer(newFile, localDatePlusDay, localTime), "New File - Newer - LocalDate plus one day,ZoneId");
+ assertFalse(FileUtils.isFileNewer(newFile, localDatePlusDay, localTime), "New File - Newer - LocalDate plus one day,LocalTime");
+ assertFalse(FileUtils.isFileNewer(newFile, localDatePlusDay, offsetTime), "New File - Newer - LocalDate plus one day,OffsetTime");
assertFalse(FileUtils.isFileNewer(invalidFile, reference), "Invalid - Newer - File");
final String invalidFileName = invalidFile.getName();
assertThrows(IllegalArgumentException.class, () -> FileUtils.isFileNewer(newFile, invalidFile));
@@ -1742,24 +1753,30 @@ public void testIsFileNewerOlder() throws Exception {
assertTrue(FileUtils.isFileOlder(oldFile, now), "Old File - Older - Mili");
assertTrue(FileUtils.isFileOlder(oldFile, instant), "Old File - Older - Instant");
assertTrue(FileUtils.isFileOlder(oldFile, zonedDateTime), "Old File - Older - ZonedDateTime");
+ assertTrue(FileUtils.isFileOlder(oldFile, offsetDateTime), "Old File - Older - OffsetDateTime");
assertTrue(FileUtils.isFileOlder(oldFile, localDateTime), "Old File - Older - LocalDateTime");
assertTrue(FileUtils.isFileOlder(oldFile, localDateTime, ZoneId.systemDefault()), "Old File - Older - LocalDateTime,LocalTime");
assertTrue(FileUtils.isFileOlder(oldFile, localDate), "Old File - Older - LocalDate");
- assertFalse(FileUtils.isFileOlder(oldFile, localDate, localTime), "Old File - Older - LocalDate,ZoneId");
+ assertFalse(FileUtils.isFileOlder(oldFile, localDate, localTime), "Old File - Older - LocalDate,LocalTime");
+ assertFalse(FileUtils.isFileOlder(oldFile, localDate, offsetTime), "Old File - Older - LocalDate,OffsetTime");
assertTrue(FileUtils.isFileOlder(oldFile, localDatePlusDay), "Old File - Older - LocalDate plus one day");
assertTrue(FileUtils.isFileOlder(oldFile, localDatePlusDay, localTime), "Old File - Older - LocalDate plus one day,LocalTime");
+ assertTrue(FileUtils.isFileOlder(oldFile, localDatePlusDay, offsetTime), "Old File - Older - LocalDate plus one day,OffsetTime");
assertFalse(FileUtils.isFileOlder(newFile, reference), "New File - Older - File");
assertFalse(FileUtils.isFileOlder(newFile, date), "New File - Older - Date");
assertFalse(FileUtils.isFileOlder(newFile, now), "New File - Older - Mili");
assertFalse(FileUtils.isFileOlder(newFile, instant), "New File - Older - Instant");
assertFalse(FileUtils.isFileOlder(newFile, zonedDateTime), "New File - Older - ZonedDateTime");
+ assertFalse(FileUtils.isFileOlder(newFile, offsetDateTime), "New File - Older - OffsetDateTime");
assertFalse(FileUtils.isFileOlder(newFile, localDateTime), "New File - Older - LocalDateTime");
assertFalse(FileUtils.isFileOlder(newFile, localDateTime, ZoneId.systemDefault()), "New File - Older - LocalDateTime,ZoneId");
assertTrue(FileUtils.isFileOlder(newFile, localDate), "New File - Older - LocalDate");
assertFalse(FileUtils.isFileOlder(newFile, localDate, localTime), "New File - Older - LocalDate,LocalTime");
+ assertFalse(FileUtils.isFileOlder(newFile, localDate, offsetTime), "New File - Older - LocalDate,OffsetTime");
assertTrue(FileUtils.isFileOlder(newFile, localDatePlusDay), "New File - Older - LocalDate plus one day");
assertTrue(FileUtils.isFileOlder(newFile, localDatePlusDay, localTime), "New File - Older - LocalDate plus one day,LocalTime");
+ assertTrue(FileUtils.isFileOlder(newFile, localDatePlusDay, offsetTime), "New File - Older - LocalDate plus one day,OffsetTime");
assertFalse(FileUtils.isFileOlder(invalidFile, reference), "Invalid - Older - File");
assertThrows(IllegalArgumentException.class, () -> FileUtils.isFileOlder(newFile, invalidFile));

Add FileUtils.isFileNewer(File, ChronoLocalDate, OffsetTime).

Add FileUtils.isFileNewer(File, OffsetDateTime).
Add FileUtils.isFileOlder(File, ChronoLocalDate, OffsetTime).
Add FileUtils.isFileOlder(File, OffsetDateTime).