null values in date range conditions

This commit is contained in:
Michele Artini 2023-02-13 16:05:58 +01:00 committed by Claudio Atzori
parent d05ca53a14
commit 554df257ab
2 changed files with 27 additions and 3 deletions

View File

@ -37,12 +37,24 @@ public class SubscriptionUtils {
}
public static boolean verifyDateRange(final long date, final String min, final String max) {
long from = 0;
long to = Long.MAX_VALUE;
try {
return date >= DateUtils.parseDate(min, "yyyy-MM-dd").getTime()
&& date < DateUtils.parseDate(max, "yyyy-MM-dd").getTime() + ONE_DAY;
from = min != null ? DateUtils.parseDate(min, "yyyy-MM-dd").getTime() : 0;
} catch (final ParseException e) {
return false;
from = 0;
}
try {
to = max != null ? DateUtils.parseDate(max, "yyyy-MM-dd").getTime() + ONE_DAY : Long.MAX_VALUE;
} catch (final ParseException e) {
to = Long.MAX_VALUE;
}
return date >= from && date < to;
}
public static boolean verifyExact(final String s1, final String s2) {

View File

@ -41,6 +41,18 @@ public class SubscriptionUtilsTest {
assertTrue(SubscriptionUtils.verifyDateRange(date, "2010-01-01", "2011-01-01"));
assertFalse(SubscriptionUtils.verifyDateRange(date, "2020-01-01", "2021-01-01"));
assertTrue(SubscriptionUtils.verifyDateRange(date, "2010-01-01", "NULL"));
assertTrue(SubscriptionUtils.verifyDateRange(date, "2010-01-01", null));
assertTrue(SubscriptionUtils.verifyDateRange(date, "NULL", "2011-01-01"));
assertTrue(SubscriptionUtils.verifyDateRange(date, null, "2011-01-01"));
assertTrue(SubscriptionUtils.verifyDateRange(date, "NULL", "NULL"));
assertTrue(SubscriptionUtils.verifyDateRange(date, null, null));
assertFalse(SubscriptionUtils.verifyDateRange(date, "2020-01-01", null));
assertFalse(SubscriptionUtils.verifyDateRange(date, "2020-01-01", "NULL"));
assertFalse(SubscriptionUtils.verifyDateRange(date, null, "2005-01-01"));
assertFalse(SubscriptionUtils.verifyDateRange(date, "NULL", "2005-01-01"));
}
@Test