1
1
package org .everit .json .schema .internal ;
2
2
3
- import com . google . common . collect . ImmutableList ;
3
+ import static org . everit . json . schema . internal . TemporalFormatValidator . SECONDS_FRACTION_FORMATTER ;
4
4
5
5
import java .time .format .DateTimeFormatter ;
6
6
import java .time .format .DateTimeFormatterBuilder ;
7
7
import java .util .List ;
8
+ import java .util .Optional ;
9
+
10
+ import org .everit .json .schema .FormatValidator ;
11
+
12
+ import com .google .common .collect .ImmutableList ;
8
13
9
14
/**
10
15
* Implementation of the "date-time" format value.
11
16
*/
12
- public class DateTimeFormatValidator extends TemporalFormatValidator {
17
+ public class DateTimeFormatValidator implements FormatValidator {
18
+
19
+ private static class Delegate extends TemporalFormatValidator {
20
+
21
+ Delegate () {
22
+ super (FORMATTER , FORMATS_ACCEPTED );
23
+ }
24
+
25
+ @ Override public String formatName () {
26
+ return "date-time" ;
27
+ }
28
+ }
13
29
14
30
private static final List <String > FORMATS_ACCEPTED = ImmutableList .of (
15
31
"yyyy-MM-dd'T'HH:mm:ssZ" , "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,9}Z, yyyy-MM-dd'T'HH:mm:ss[+-]HH:mm" ,
@@ -24,13 +40,15 @@ public class DateTimeFormatValidator extends TemporalFormatValidator {
24
40
final DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder ()
25
41
.appendPattern (PARTIAL_DATETIME_PATTERN )
26
42
.appendOptional (SECONDS_FRACTION_FORMATTER )
27
- .appendPattern (ZONE_OFFSET_PATTERN );
43
+ .appendPattern (TemporalFormatValidator . ZONE_OFFSET_PATTERN );
28
44
29
45
FORMATTER = builder .toFormatter ();
30
46
}
31
47
32
- public DateTimeFormatValidator () {
33
- super (FORMATTER , FORMATS_ACCEPTED );
48
+ private Delegate delegate = new Delegate ();
49
+
50
+ @ Override public Optional <String > validate (String subject ) {
51
+ return delegate .validate (subject );
34
52
}
35
53
36
54
@ Override
0 commit comments