File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ test('parseSchedule rejects bad input', () => {
1717 assert . throws ( ( ) => parseSchedule ( JSON . stringify ( { mon : '9:00-17:00' } ) ) , / H H : M M / i) ;
1818 assert . throws ( ( ) => parseSchedule ( JSON . stringify ( { mon : '17:00-09:00' } ) ) , / b e f o r e c l o s e / i) ;
1919 assert . throws ( ( ) => parseSchedule ( JSON . stringify ( { mon : null , sun : null } ) ) , / n o o p e n d a y s / i) ;
20+ assert . throws ( ( ) => parseSchedule ( JSON . stringify ( { mon : '09:00-17:00-junk' } ) ) , / H H : M M / i) ;
2021} ) ;
2122
2223test ( 'parseSchedule yields minute windows and treats null/absent as closed' , ( ) => {
Original file line number Diff line number Diff line change @@ -37,9 +37,9 @@ export function parseSchedule(json: string): Schedule {
3737 if ( ! DAYS . includes ( day ) ) throw new Error ( `schedule: unknown day "${ key } "` ) ;
3838 if ( value === null ) continue ; // closed
3939 if ( typeof value !== 'string' ) throw new Error ( `schedule: ${ day } must be "HH:MM-HH:MM" or null` ) ;
40- const [ openS , closeS ] = value . split ( '-' ) ;
41- const openMin = openS !== undefined ? parseHHMM ( openS ) : null ;
42- const closeMin = closeS !== undefined ? parseHHMM ( closeS ) : null ;
40+ const m = / ^ ( \d { 2 } : \d { 2 } ) - ( \d { 2 } : \d { 2 } ) $ / . exec ( value ) ;
41+ const openMin = m ? parseHHMM ( m [ 1 ] ) : null ;
42+ const closeMin = m ? parseHHMM ( m [ 2 ] ) : null ;
4343 if ( openMin === null || closeMin === null ) {
4444 throw new Error ( `schedule: ${ day } window "${ value } " is not "HH:MM-HH:MM"` ) ;
4545 }
You can’t perform that action at this time.
0 commit comments