From eab8c2dccc73922e319306208af27ca33ddf7e73 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 5 Oct 2016 03:04:02 +0800 Subject: [PATCH] Fix illegal date issues (e.g. year out of bounds) --- .../net/filebot/similarity/DateMatcher.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/source/net/filebot/similarity/DateMatcher.java b/source/net/filebot/similarity/DateMatcher.java index 6338f3ac..678dff34 100644 --- a/source/net/filebot/similarity/DateMatcher.java +++ b/source/net/filebot/similarity/DateMatcher.java @@ -9,6 +9,7 @@ import java.time.chrono.ChronoLocalDate; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.time.format.TextStyle; +import java.time.temporal.ChronoField; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -197,25 +198,30 @@ public class DateMatcher { public static class DateFilter implements Predicate { - public final ChronoLocalDate lowerBound; - public final ChronoLocalDate upperBound; + public final ChronoLocalDate min; + public final ChronoLocalDate max; - public DateFilter(ChronoLocalDate lowerBound, ChronoLocalDate upperBound) { - this.lowerBound = lowerBound; - this.upperBound = upperBound; + private final int minYear; + private final int maxYear; + + public DateFilter(ChronoLocalDate min, ChronoLocalDate max) { + this.min = min; + this.max = max; + this.minYear = min.get(ChronoField.YEAR); + this.maxYear = max.get(ChronoField.YEAR); } @Override public boolean test(ChronoLocalDate date) { - return date.isAfter(lowerBound) && date.isBefore(upperBound); - } - - public boolean acceptDate(int year, int month, int day) { - return test(LocalDate.of(year, month, day)); + return date.isAfter(min) && date.isBefore(max); } public boolean acceptYear(int year) { - return test(LocalDate.of(year, 1, 1)); + return minYear < year && year < maxYear; + } + + public boolean acceptDate(int year, int month, int day) { + return acceptYear(year) && test(LocalDate.of(year, month, day)); } }