@@ -17,7 +17,8 @@ const isValidIPV6 =
1717const isValidHostname =
1818 / ^ (? = .{ 1 , 255 } $ ) [ 0 - 9 A - Z a - z ] (?: (?: [ 0 - 9 A - Z a - z ] | - ) { 0 , 61 } [ 0 - 9 A - Z a - z ] ) ? (?: \. [ 0 - 9 A - Z a - z ] (?: (?: [ 0 - 9 A - Z a - z ] | - ) { 0 , 61 } [ 0 - 9 A - Z a - z ] ) ? ) * \. ? $ / ;
1919const matchDate = / ^ ( \d \d \d \d ) - ( \d \d ) - ( \d \d ) $ / ;
20- const matchTime = / ^ ( \d \d ) : ( \d \d ) : ( \d \d ) ( \. \d + ) ? ( z | [ + - ] \d \d (?: : ? \d \d ) ? ) ? $ / i;
20+ // const matchTime = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i;
21+ const matchTime = / ^ (?: [ 0 - 2 ] \d : [ 0 - 5 ] \d : [ 0 - 5 ] \d | 2 3 : 5 9 : 6 0 ) (?: \. \d + ) ? (?: z | [ + - ] \d \d (?: : ? \d \d ) ? ) ? $ / i;
2122const DAYS = [ 0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ] ;
2223
2324const isValidJsonPointer = / ^ (?: \/ (?: [ ^ ~ / ] | ~ 0 | ~ 1 ) * ) * $ / ;
@@ -175,27 +176,31 @@ const formatValidators: Record<
175176 return errors . formatRegExError ( { value, pointer, schema } ) ;
176177 } ,
177178
179+ // hh:mm:ss.sTZD
180+ // https://opis.io/json-schema/2.x/formats.html
181+ // regex https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s07.html
178182 time : ( draft , schema , value , pointer ) => {
179183 if ( typeof value !== "string" || value === "" ) {
180184 return undefined ;
181185 }
182186 // https://github.com/cfworker/cfworker/blob/main/packages/json-schema/src/format.ts
183187 const matches = value . match ( matchTime ) ;
184- if ( ! matches ) {
185- return errors . formatDateTimeError ( { value, pointer, schema } ) ;
186- }
187- const hour = + matches [ 1 ] ;
188- const minute = + matches [ 2 ] ;
189- const second = + matches [ 3 ] ;
190- const timeZone = ! ! matches [ 5 ] ;
191- if (
192- ( ( hour <= 23 && minute <= 59 && second <= 59 ) ||
193- ( hour == 23 && minute == 59 && second == 60 ) ) &&
194- timeZone
195- ) {
196- return undefined ;
197- }
198- return errors . formatTimeError ( { value, pointer, schema } ) ;
188+ return matches ? undefined : errors . formatDateTimeError ( { value, pointer, schema } ) ;
189+ // if (!matches) {
190+ // return errors.formatDateTimeError({ value, pointer, schema });
191+ // }
192+ // const hour = +matches[1];
193+ // const minute = +matches[2];
194+ // const second = +matches[3];
195+ // const timeZone = !!matches[5];
196+ // if (
197+ // ((hour <= 23 && minute <= 59 && second <= 59) ||
198+ // (hour == 23 && minute == 59 && second == 60)) &&
199+ // timeZone
200+ // ) {
201+ // return undefined;
202+ // }
203+ // return errors.formatTimeError({ value, pointer, schema });
199204 } ,
200205
201206 uri : ( draft , schema , value , pointer ) => {
0 commit comments