diff --git a/.gitignore b/.gitignore index 36037661..9f85a7f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ export.* node_modules/ +tags diff --git a/opening_hours.js b/opening_hours.js index d60f8025..a52af9f1 100644 --- a/opening_hours.js +++ b/opening_hours.js @@ -1838,7 +1838,7 @@ // }}} // put tokenized blocks into list {{{ - if (value.match(/^(\s*;?\s*)+$/)) + if (value.match(/^(?:\s*;?\s*)+$/)) throw 'Value contains nothing meaningful which can be parsed'; var parsing_warnings = []; @@ -3640,16 +3640,21 @@ } selectors.week.push(function(tokens, at, is_range, has_period) { return function(date) { + // console.log('called: ' + date); var ourweek = Math.floor((date - dateAtWeek(date, 0)) / msec_in_week); var week_from = tokens[at][0] - 1; - var week_to = is_range ? tokens[at+2][0] - 1 : week_from; + var week_to = is_range ? tokens[at+2][0] - 1 : week_from; var start_of_next_year = new Date(date.getFullYear() + 1, 0, 1); // before range - if (ourweek < week_from) + if (ourweek < week_from) { + // console.log('Start of date', start_of_next_year); + // console.log('dateAtWeek(date, week_from)', dateAtWeek(date, week_from)); + // console.log(getMinDate(dateAtWeek(date, week_from), start_of_next_year)); return [false, getMinDate(dateAtWeek(date, week_from), start_of_next_year)]; + } // we're after range, set check date to next year if (ourweek > week_to) @@ -4386,11 +4391,11 @@ return false; // console.log('\n' + 'previous check time:', prevstate[1] - // + ', current check time:', - // // (state[1].getHours() < 10 ? '0' : '') + state[1].getHours() + - // // ':'+(state[1].getMinutes() < 10 ? '0' : '')+ state[1].getMinutes(), state[1].getDate(), - // state[1], - // (state[0] ? 'open' : (state[2] ? 'unknown' : 'closed')) + ', comment:', state[3]); + // + ', current check time:', + // // (state[1].getHours() < 10 ? '0' : '') + state[1].getHours() + + // // ':'+(state[1].getMinutes() < 10 ? '0' : '')+ state[1].getMinutes(), state[1].getDate(), + // state[1], + // (state[0] ? 'open' : (state[2] ? 'unknown' : 'closed')) + ', comment:', state[3]); // We're going backwards or staying at place. // This always indicates coding error in a selector code. diff --git a/test.js b/test.js index a46cc991..44edc3f5 100755 --- a/test.js +++ b/test.js @@ -101,10 +101,10 @@ test.addTest('Input tolerance: dot as time separator', [ ], 1000 * 60 * 60 * 2 * 7, 0, true, {}, 'not last test'); test.addTest('Input tolerance: short time (test prettify)', [ - '10:00-12:00,13:00-20:00', // reference value for prettify - '10-12,13-20', // Do not use. Returns warning. - '10am-12am,1pm-8pm', // Do not use. Returns warning. - '10:00am-12:00am,1:00pm-8:00pm', // Do not use. Returns warning. + '10:00-12:00,13:00-20:00', // reference value for prettify + '10-12,13-20', // Do not use. Returns warning. + '10am-12am,1pm-8pm', // Do not use. Returns warning. + '10:00am-12:00am,1:00pm-8:00pm', // Do not use. Returns warning. ], '2012.10.01 0:00', '2012.10.03 0:00', [ [ '2012.10.01 10:00', '2012.10.01 12:00' ], [ '2012.10.01 13:00', '2012.10.01 20:00' ], @@ -914,9 +914,12 @@ test.addTest('Week range', [ ], 1000 * 60 * 60 * 24 * 724, 0, false); test.addTest('Week range', [ - 'week 4-16 We; week 38-42 Sa 0:00-24:00', - ], '2012.01.01 0:00', '2014.01.01 0:00', [ - ], 1000 * 60 * 60 * 24 * 724, 0, false); + 'week 4-16', + // 'week 4-16 We', + // 'week 38-42 Sa 0:00-24:00', + // 'week 4-16 We; week 38-42 Sa 0:00-24:00', + ], '2012.01.01 0:00', '2018.01.01 0:00', [ + ], 1000 * 60 * 60 * 24 * 724, 0, false, {}, 'not only test'); // }}} // full months/month ranges {{{ @@ -1874,7 +1877,17 @@ test.addShouldWarn('Value not ideal (probably wrong). Should throw a warning.', // }}} 'Jan Dec' + value_suffix, 'Jan 1-22/1' + value_suffix, // period - '"testing" "second comment"' + value_suffix, + // https://en.wikipedia.org/wiki/International_variation_in_quotation_marks + '"testing" "second comment"' + value_suffix, // ": valid in opening_hours syntax + // '\'testing\'' + value_suffix, + // '„testing“' + value_suffix, // valid German quote + // '“testing”' + value_suffix, // valid English (and others) quote + // '«testing»' + value_suffix, // https://en.wikipedia.org/wiki/Guillemet + // '「testing」' + value_suffix, // valid Japanese quote + // '『testing』' + value_suffix, // valid Japanese quote + // '‚testing‘' + value_suffix, + // '‘testing‘' + value_suffix, + // '’testing’' + value_suffix, 'Jan 12:00-13:00 Mo 15:00-16:00' + value_suffix, 'sunrise-(sunset-00:00)' + value_suffix, // 'easter + 353 days' + value_suffix, // Does throw an error, but at runtime when the problem occurs respectively with the call of getWarnings(). @@ -1883,6 +1896,8 @@ test.addShouldWarn('Value not ideal (probably wrong). Should throw a warning.', '2014/1' + value_suffix, // period is one 'Mo-Sa 11:00-21:00 Su off' + value_suffix, // http://www.openstreetmap.org/way/228339826 // 'Mo-Sa 11:00-21:00 Su,PH off' + value_suffix, // http://www.openstreetmap.org/way/228339826 + '25pm-26am' + value_suffix, + '10:00am-12:00am,1:00pm-8:00pm' + value_suffix, ], {}, 'not last test'); // }}} @@ -1959,6 +1974,9 @@ test.addShouldFail('Incorrect syntax which should throw an error', [ '26:00-27:00' + value_suffix, '23:00-55:00' + value_suffix, '23:59-48:01' + value_suffix, + '25am-26pm' + value_suffix, + '24am-26pm' + value_suffix, + '23am-49pm' + value_suffix, 'Tu 23:59-48:00+' + value_suffix, // Does not make much sense. Should be written in another way. '12:00' + value_suffix, ], nominatiomTestJSON, 'not last test'); diff --git a/test.log b/test.log index df8990ef..31c20ff1 100644 --- a/test.log +++ b/test.log @@ -233,7 +233,7 @@ With warnings: "Week range limit" for "week 2-54: 00:00-24:00": PASSED "Week range limit" for "week 2-57": PASSED "Week range" for "week 2-52/2 We; week 1-53/2 Sa 0:00-24:00": CRASHED, reason: Fatal: infinite loop in nextChange -"Week range" for "week 4-16 We; week 38-42 Sa 0:00-24:00": CRASHED, reason: Fatal: infinite loop in nextChange +"Week range" for "week 4-16": CRASHED, reason: Fatal: infinite loop in nextChange "Only in one month of the year" for "Apr 08:00-12:00": PASSED "Only in one month of the year" for "Apr: 08:00-12:00": PASSED "Month ranges" for "Nov-Feb 00:00-24:00": PASSED @@ -555,6 +555,20 @@ With warnings: "Value not ideal (probably wrong). Should throw a warning." for "Mo-Sa 11:00-21:00 Su off; 00:23-00:42 unknown "warning at correct position?"": PASSED With warnings: *Mo-Sa 11:00-21:00 Su <--- (You have used 2 not connected weekdays in one rule. This is probably an error. Equal selector types can (and should) always be written in conjunction separated by comma or something. Example for time ranges "12:00-13:00,15:00-18:00". Example for weekdays "Mo-We,Fr". Rules can be separated by ";".) +"Value not ideal (probably wrong). Should throw a warning." for "25pm-26am; 00:23-00:42 unknown "warning at correct position?"": FAILED +25pm <--- (Time range starts outside of the current day) + +With warnings: + *10:00am <--- (Please use time format in 24 hours notation ("am"). If PM is used you might have to convert the hours to the 24 hours notation.) + *10:00am-12:00am <--- (Please use time format in 24 hours notation ("am"). If PM is used you might have to convert the hours to the 24 hours notation.) + *10:00am-12:00am,1:00pm <--- (Please use time format in 24 hours notation ("pm"). If PM is used you might have to convert the hours to the 24 hours notation.) + *10:00am-12:00am,1:00pm-8:00pm <--- (Please use time format in 24 hours notation ("pm"). If PM is used you might have to convert the hours to the 24 hours notation.) +"Value not ideal (probably wrong). Should throw a warning." for "10:00am-12:00am,1:00pm-8:00pm; 00:23-00:42 unknown "warning at correct position?"": PASSED +With warnings: + *10:00am <--- (Please use time format in 24 hours notation ("am"). If PM is used you might have to convert the hours to the 24 hours notation.) + *10:00am-12:00am <--- (Please use time format in 24 hours notation ("am"). If PM is used you might have to convert the hours to the 24 hours notation.) + *10:00am-12:00am,1:00pm <--- (Please use time format in 24 hours notation ("pm"). If PM is used you might have to convert the hours to the 24 hours notation.) + *10:00am-12:00am,1:00pm-8:00pm <--- (Please use time format in 24 hours notation ("pm"). If PM is used you might have to convert the hours to the 24 hours notation.) "Incorrect syntax which should throw an error" for "sdasdlasdj a3reaw": PASSED sd <--- (Unexpected token: "s" This means that the syntax is not valid at that point or it is currently not supported.) sdasdlasdj a3reaw <--- (Assuming "We" for "w") @@ -753,6 +767,15 @@ Jun 2-20/0 <--- (You can not use day ranges with period equals zero.) "Incorrect syntax which should throw an error" for "23:59-48:01; 00:23-00:42 unknown "warning at correct position?"": PASSED 23:59-48:01 <--- (Time spanning more than two midnights not supported) +"Incorrect syntax which should throw an error" for "25am-26pm; 00:23-00:42 unknown "warning at correct position?"": PASSED +25am <--- (Time range starts outside of the current day) + +"Incorrect syntax which should throw an error" for "24am-26pm; 00:23-00:42 unknown "warning at correct position?"": PASSED +24am <--- (Time range starts outside of the current day) + +"Incorrect syntax which should throw an error" for "23am-49pm; 00:23-00:42 unknown "warning at correct position?"": PASSED +23am-49pm <--- (Time spanning more than two midnights not supported) + "Incorrect syntax which should throw an error" for "Tu 23:59-48:00+; 00:23-00:42 unknown "warning at correct position?"": PASSED Tu 23:59-48:00+ <--- (Time spanning more than two midnights not supported) @@ -882,4 +905,4 @@ Su 7:30,10i <--- (Missing time separator in time range after: "number") "Compare result from getMatchingRule()" for "Fr 08:00-12:00 || Fr 12:00-16:00 open "Notfallsprechstunde"": PASSED "Compare result from getMatchingRule()" for "Fr 08:00-12:00, Fr 12:00-16:00 open "Notfallsprechstunde"": PASSED "Compare result from getMatchingRule()" for "Fr 08:00-12:00 || Fr 12:00-16:00 open "Notfallsprechstunde"": PASSED -486/492 tests passed +490/497 tests passed