File tree Expand file tree Collapse file tree 4 files changed +54
-0
lines changed
main/java/com/networknt/schema
java/com/networknt/schema Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 25
25
import java .util .Collections ;
26
26
import java .util .LinkedHashSet ;
27
27
import java .util .Set ;
28
+ import java .util .TimeZone ;
28
29
import java .util .regex .Matcher ;
29
30
import java .util .regex .Pattern ;
30
31
@@ -136,6 +137,7 @@ private boolean isLegalDateTime(String string) {
136
137
private boolean validateDateTime (String dateTime , String pattern ) {
137
138
SimpleDateFormat sdf = new SimpleDateFormat (pattern );
138
139
sdf .setLenient (false );
140
+ sdf .setTimeZone (TimeZone .getTimeZone ("UTC" ));
139
141
return sdf .parse (dateTime , new ParsePosition (0 )) != null ;
140
142
}
141
143
}
Original file line number Diff line number Diff line change
1
+ package com .networknt .schema ;
2
+
3
+ import com .fasterxml .jackson .databind .JsonNode ;
4
+ import com .fasterxml .jackson .databind .ObjectMapper ;
5
+ import org .junit .Assert ;
6
+ import org .junit .Test ;
7
+
8
+ import java .io .InputStream ;
9
+ import java .util .Set ;
10
+
11
+ public class DateTimeDSTTest {
12
+ protected JsonSchema getJsonSchemaFromStreamContentV7 (InputStream schemaContent ) {
13
+ JsonSchemaFactory factory = JsonSchemaFactory .getInstance (SpecVersion .VersionFlag .V7 );
14
+ return factory .getSchema (schemaContent );
15
+ }
16
+
17
+ protected JsonNode getJsonNodeFromStreamContent (InputStream content ) throws Exception {
18
+ ObjectMapper mapper = new ObjectMapper ();
19
+ JsonNode node = mapper .readTree (content );
20
+ return node ;
21
+ }
22
+
23
+ @ Test
24
+ public void shouldWorkV7 () throws Exception {
25
+ String schemaPath = "/schema/dateTimeArray.json" ;
26
+ String dataPath = "/data/dstTimes.json" ; // Contains 2020 DST changes for various countries
27
+ InputStream schemaInputStream = getClass ().getResourceAsStream (schemaPath );
28
+ JsonSchema schema = getJsonSchemaFromStreamContentV7 (schemaInputStream );
29
+ InputStream dataInputStream = getClass ().getResourceAsStream (dataPath );
30
+ JsonNode node = getJsonNodeFromStreamContent (dataInputStream );
31
+ Set <ValidationMessage > errors = schema .validate (node );
32
+ Assert .assertEquals (0 , errors .size ());
33
+ }
34
+ }
Original file line number Diff line number Diff line change
1
+ [
2
+ " 2020-03-29T02:00:00Z" ,
3
+ " 2020-09-27T02:00:00Z" ,
4
+ " 2020-03-15T02:00:00Z" ,
5
+ " 2020-03-08T02:00:00Z" ,
6
+ " 2020-03-27T02:00:00Z" ,
7
+ " 2020-08-04T02:00:00Z"
8
+ ]
Original file line number Diff line number Diff line change
1
+ {
2
+ "$id" : " https://example.com/dateTimeTest.schema.json" ,
3
+ "$schema" : " http://json-schema.org/draft-07/schema#" ,
4
+ "type" : " array" ,
5
+ "items" : {
6
+ "type" : " string" ,
7
+ "format" : " date-time"
8
+ }
9
+ }
10
+
You can’t perform that action at this time.
0 commit comments