16
16
package io .avaje .validation .core ;
17
17
18
18
import java .lang .reflect .Array ;
19
+ import java .time .Instant ;
19
20
import java .time .LocalDate ;
20
21
import java .time .LocalTime ;
21
22
import java .time .temporal .TemporalAccessor ;
22
23
import java .util .Collection ;
24
+ import java .util .Date ;
23
25
import java .util .List ;
24
26
import java .util .Map ;
25
27
import java .util .function .Predicate ;
@@ -157,7 +159,7 @@ public boolean validate(Object value, ValidationRequest req, String propertyName
157
159
}
158
160
}
159
161
160
- private static final class PastAdapter implements AnnotationValidationAdapter <TemporalAccessor > {
162
+ private static final class PastAdapter implements AnnotationValidationAdapter <Object > {
161
163
162
164
private String message ;
163
165
private final MessageInterpolator interpolator ;
@@ -167,29 +169,37 @@ public PastAdapter(MessageInterpolator interpolator) {
167
169
}
168
170
169
171
@ Override
170
- public AnnotationValidationAdapter <TemporalAccessor > init (
171
- Map <String , Object > annotationValueMap ) {
172
+ public AnnotationValidationAdapter <Object > init (Map <String , Object > annotationValueMap ) {
172
173
message = interpolator .interpolate ((String ) annotationValueMap .get ("message" ));
173
174
return this ;
174
175
}
175
176
176
177
@ 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 ) {
180
181
req .addViolation (message , propertyName );
181
182
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 () ))) {
185
186
req .addViolation (message , propertyName );
186
187
return false ;
187
188
}
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
+ }
193
203
}
194
204
return true ;
195
205
}
0 commit comments