Skip to content

Commit 8cbaee5

Browse files
committed
util.Date
1 parent ed377f6 commit 8cbaee5

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

validator/src/main/java/io/avaje/validation/core/JakartaTypeAdapters.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
package io.avaje.validation.core;
1717

1818
import java.lang.reflect.Array;
19+
import java.time.Instant;
1920
import java.time.LocalDate;
2021
import java.time.LocalTime;
2122
import java.time.temporal.TemporalAccessor;
2223
import java.util.Collection;
24+
import java.util.Date;
2325
import java.util.List;
2426
import java.util.Map;
2527
import java.util.function.Predicate;
@@ -157,7 +159,7 @@ public boolean validate(Object value, ValidationRequest req, String propertyName
157159
}
158160
}
159161

160-
private static final class PastAdapter implements AnnotationValidationAdapter<TemporalAccessor> {
162+
private static final class PastAdapter implements AnnotationValidationAdapter<Object> {
161163

162164
private String message;
163165
private final MessageInterpolator interpolator;
@@ -167,29 +169,37 @@ public PastAdapter(MessageInterpolator interpolator) {
167169
}
168170

169171
@Override
170-
public AnnotationValidationAdapter<TemporalAccessor> init(
171-
Map<String, Object> annotationValueMap) {
172+
public AnnotationValidationAdapter<Object> init(Map<String, Object> annotationValueMap) {
172173
message = interpolator.interpolate((String) annotationValueMap.get("message"));
173174
return this;
174175
}
175176

176177
@Override
177-
public boolean validate(
178-
TemporalAccessor temporalAccessor, ValidationRequest req, String propertyName) {
179-
if (temporalAccessor == null) {
178+
public boolean validate(Object obj, ValidationRequest req, String propertyName) {
179+
180+
if (obj == null) {
180181
req.addViolation(message, propertyName);
181182
return false;
182-
}
183-
if (temporalAccessor instanceof LocalDate) {
184-
if (LocalDate.from(temporalAccessor).isAfter(LocalDate.now())) {
183+
} else if (obj instanceof Date) {
184+
final Date date = (Date) obj;
185+
if (date.after(Date.from(Instant.now()))) {
185186
req.addViolation(message, propertyName);
186187
return false;
187188
}
188-
} else if (temporalAccessor instanceof LocalTime) {
189-
final LocalTime localTime = (LocalTime) temporalAccessor;
190-
// handle LocalTime
191-
192-
// TODO do the rest of them
189+
} else if (obj instanceof TemporalAccessor) {
190+
191+
final TemporalAccessor temporalAccessor = (TemporalAccessor) obj;
192+
if (temporalAccessor instanceof LocalDate) {
193+
if (LocalDate.from(temporalAccessor).isAfter(LocalDate.now())) {
194+
req.addViolation(message, propertyName);
195+
return false;
196+
}
197+
} else if (temporalAccessor instanceof LocalTime) {
198+
final LocalTime localTime = (LocalTime) temporalAccessor;
199+
// handle LocalTime
200+
201+
// TODO do the rest of them
202+
}
193203
}
194204
return true;
195205
}

0 commit comments

Comments
 (0)