fix(magic-shelf): remove timestamp from magic shelf date checks (#2097)
This commit is contained in:
@@ -534,7 +534,7 @@ public class BookRuleEvaluatorService {
|
|||||||
if (value instanceof Boolean) {
|
if (value instanceof Boolean) {
|
||||||
return cb.equal(field, value);
|
return cb.equal(field, value);
|
||||||
} else if (value instanceof LocalDate) {
|
} else if (value instanceof LocalDate) {
|
||||||
return cb.equal(field, value);
|
return cb.equal(field.cast(LocalDate.class), value);
|
||||||
} else if (value instanceof LocalDateTime) {
|
} else if (value instanceof LocalDateTime) {
|
||||||
return cb.equal(field, value);
|
return cb.equal(field, value);
|
||||||
} else if (rule.getField() == RuleField.READ_STATUS) {
|
} else if (rule.getField() == RuleField.READ_STATUS) {
|
||||||
@@ -600,28 +600,28 @@ public class BookRuleEvaluatorService {
|
|||||||
private Predicate buildGreaterThan(Rule rule, CriteriaBuilder cb, Root<BookEntity> root, Join<BookEntity, UserBookProgressEntity> progressJoin) {
|
private Predicate buildGreaterThan(Rule rule, CriteriaBuilder cb, Root<BookEntity> root, Join<BookEntity, UserBookProgressEntity> progressJoin) {
|
||||||
return buildComparisonPredicate(rule, cb, root, progressJoin,
|
return buildComparisonPredicate(rule, cb, root, progressJoin,
|
||||||
(field, dateValue) -> cb.greaterThan(field.as(LocalDateTime.class), dateValue),
|
(field, dateValue) -> cb.greaterThan(field.as(LocalDateTime.class), dateValue),
|
||||||
(field, localDateValue) -> cb.greaterThan(field.as(LocalDate.class), localDateValue),
|
(field, localDateValue) -> cb.greaterThan(field.cast(LocalDate.class), localDateValue),
|
||||||
(field, numValue) -> cb.gt(toNumericExpression(field), numValue));
|
(field, numValue) -> cb.gt(toNumericExpression(field), numValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Predicate buildGreaterThanEqual(Rule rule, CriteriaBuilder cb, Root<BookEntity> root, Join<BookEntity, UserBookProgressEntity> progressJoin) {
|
private Predicate buildGreaterThanEqual(Rule rule, CriteriaBuilder cb, Root<BookEntity> root, Join<BookEntity, UserBookProgressEntity> progressJoin) {
|
||||||
return buildComparisonPredicate(rule, cb, root, progressJoin,
|
return buildComparisonPredicate(rule, cb, root, progressJoin,
|
||||||
(field, dateValue) -> cb.greaterThanOrEqualTo(field.as(LocalDateTime.class), dateValue),
|
(field, dateValue) -> cb.greaterThanOrEqualTo(field.as(LocalDateTime.class), dateValue),
|
||||||
(field, localDateValue) -> cb.greaterThanOrEqualTo(field.as(LocalDate.class), localDateValue),
|
(field, localDateValue) -> cb.greaterThanOrEqualTo(field.cast(LocalDate.class), localDateValue),
|
||||||
(field, numValue) -> cb.ge(toNumericExpression(field), numValue));
|
(field, numValue) -> cb.ge(toNumericExpression(field), numValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Predicate buildLessThan(Rule rule, CriteriaBuilder cb, Root<BookEntity> root, Join<BookEntity, UserBookProgressEntity> progressJoin) {
|
private Predicate buildLessThan(Rule rule, CriteriaBuilder cb, Root<BookEntity> root, Join<BookEntity, UserBookProgressEntity> progressJoin) {
|
||||||
return buildComparisonPredicate(rule, cb, root, progressJoin,
|
return buildComparisonPredicate(rule, cb, root, progressJoin,
|
||||||
(field, dateValue) -> cb.lessThan(field.as(LocalDateTime.class), dateValue),
|
(field, dateValue) -> cb.lessThan(field.as(LocalDateTime.class), dateValue),
|
||||||
(field, localDateValue) -> cb.lessThan(field.as(LocalDate.class), localDateValue),
|
(field, localDateValue) -> cb.lessThan(field.cast(LocalDate.class), localDateValue),
|
||||||
(field, numValue) -> cb.lt(toNumericExpression(field), numValue));
|
(field, numValue) -> cb.lt(toNumericExpression(field), numValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Predicate buildLessThanEqual(Rule rule, CriteriaBuilder cb, Root<BookEntity> root, Join<BookEntity, UserBookProgressEntity> progressJoin) {
|
private Predicate buildLessThanEqual(Rule rule, CriteriaBuilder cb, Root<BookEntity> root, Join<BookEntity, UserBookProgressEntity> progressJoin) {
|
||||||
return buildComparisonPredicate(rule, cb, root, progressJoin,
|
return buildComparisonPredicate(rule, cb, root, progressJoin,
|
||||||
(field, dateValue) -> cb.lessThanOrEqualTo(field.as(LocalDateTime.class), dateValue),
|
(field, dateValue) -> cb.lessThanOrEqualTo(field.as(LocalDateTime.class), dateValue),
|
||||||
(field, localDateValue) -> cb.lessThanOrEqualTo(field.as(LocalDate.class), localDateValue),
|
(field, localDateValue) -> cb.lessThanOrEqualTo(field.cast(LocalDate.class), localDateValue),
|
||||||
(field, numValue) -> cb.le(toNumericExpression(field), numValue));
|
(field, numValue) -> cb.le(toNumericExpression(field), numValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -655,7 +655,7 @@ public class BookRuleEvaluatorService {
|
|||||||
if (start == null || end == null) return cb.conjunction();
|
if (start == null || end == null) return cb.conjunction();
|
||||||
|
|
||||||
if (start instanceof LocalDate && end instanceof LocalDate) {
|
if (start instanceof LocalDate && end instanceof LocalDate) {
|
||||||
return cb.between(field.as(LocalDate.class), (LocalDate) start, (LocalDate) end);
|
return cb.between(field.cast(LocalDate.class), (LocalDate) start, (LocalDate) end);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start instanceof LocalDateTime && end instanceof LocalDateTime) {
|
if (start instanceof LocalDateTime && end instanceof LocalDateTime) {
|
||||||
@@ -892,19 +892,12 @@ public class BookRuleEvaluatorService {
|
|||||||
private Object normalizeValue(Object value, RuleField field) {
|
private Object normalizeValue(Object value, RuleField field) {
|
||||||
if (value == null) return null;
|
if (value == null) return null;
|
||||||
|
|
||||||
if (field == RuleField.PUBLISHED_DATE) {
|
if (field == RuleField.PUBLISHED_DATE || field == RuleField.DATE_FINISHED ||
|
||||||
|
field == RuleField.LAST_READ_TIME || field == RuleField.ADDED_ON) {
|
||||||
LocalDateTime parsed = parseDate(value);
|
LocalDateTime parsed = parseDate(value);
|
||||||
return parsed != null ? parsed.toLocalDate() : null;
|
return parsed != null ? parsed.toLocalDate() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field == RuleField.DATE_FINISHED || field == RuleField.LAST_READ_TIME || field == RuleField.ADDED_ON) {
|
|
||||||
LocalDateTime parsed = parseDate(value);
|
|
||||||
if (parsed != null) {
|
|
||||||
return parsed.atZone(ZoneId.systemDefault()).toInstant();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (field == RuleField.READ_STATUS) {
|
if (field == RuleField.READ_STATUS) {
|
||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,14 +27,18 @@ export class BookRuleEvaluatorService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const rawValue = this.extractBookValue(book, rule.field);
|
const rawValue = this.extractBookValue(book, rule.field);
|
||||||
|
const isDateField = rule.field === 'publishedDate' || rule.field === 'dateFinished' ||
|
||||||
|
rule.field === 'lastReadTime' || rule.field === 'addedOn';
|
||||||
|
const withoutTime = (date: Date): Date =>
|
||||||
|
new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
||||||
|
|
||||||
const normalize = (val: unknown): unknown => {
|
const normalize = (val: unknown): unknown => {
|
||||||
if (val === null || val === undefined) return val;
|
if (val === null || val === undefined) return val;
|
||||||
if (val instanceof Date) return val;
|
if (val instanceof Date) return isDateField ? withoutTime(val) : val;
|
||||||
if (typeof val === 'boolean') return String(val);
|
if (typeof val === 'boolean') return String(val);
|
||||||
if (typeof val === 'string') {
|
if (typeof val === 'string') {
|
||||||
const date = parseValue(val, 'date');
|
const date = parseValue(val, 'date');
|
||||||
if (date != null) return date;
|
if (date instanceof Date) return isDateField ? withoutTime(date) : date;
|
||||||
return val.toLowerCase();
|
return val.toLowerCase();
|
||||||
}
|
}
|
||||||
return val;
|
return val;
|
||||||
|
|||||||
Reference in New Issue
Block a user