• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.networknt.schema.format;
2 
3 import java.time.LocalDate;
4 import java.time.format.DateTimeParseException;
5 
6 import com.networknt.schema.ExecutionContext;
7 import com.networknt.schema.Format;
8 
9 /**
10  * Format for date.
11  */
12 public class DateFormat implements Format {
13     @Override
matches(ExecutionContext executionContext, String value)14     public boolean matches(ExecutionContext executionContext, String value) {
15         try {
16             LocalDate date = LocalDate.parse(value);
17             int year = date.getYear();
18             return 0 <= year && year <= 9999;
19         } catch (DateTimeParseException e) {
20             return false;
21         }
22     }
23 
24     @Override
getName()25     public String getName() {
26         return "date";
27     }
28 
29     @Override
getMessageKey()30     public String getMessageKey() {
31         return "format.date";
32     }
33 }
34