const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/ ; const DAYS = [ 0 , 31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ] ; const TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d:\d\d)?$/i ; export interface DateTimeRecognizer { isDate ( s ) : boolean ; isTime ( s ) : boolean ; isDateTime ( s ) : boolean ; } const DATE_TIME_SEPARATOR = /t|\s/i ; export class DefaultDateTimeRecognizer implements DateTimeRecognizer { isDate ( str ) { const matches = str . match ( DATE ) ; if ( matches === null ) return false ; const month = + matches [ 2 ] ; const day = + matches [ 3 ] ; return month >= 1 && month <= 12 && day >= 1 && day <= DAYS [ month ] ; } isTime ( str ) { const matches = str . match ( TIME ) ; if ( matches === null ) return false ; const hour = + matches [ 1 ] ; const minute = + matches [ 2 ] ; const second = + matches [ 3 ] ; return hour <= 23 && minute <= 59 && second <= 59 ; } isDateTime ( str ) { const dateTime = str . split ( DATE_TIME_SEPARATOR ) ; return dateTime . length === 2 && this . isDate ( dateTime [ 0 ] ) && this . isTime ( dateTime [ 1 ] ) ; } }