Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,7 @@ export default function(value, nominatim_object, optional_conf_parm) {
// Run real_test regularly to fix the problem before a user is confronted with it.
pos -= tokens_to_use[nrule][2];
console.warn('Last token for rule: ' + JSON.stringify(tokens_to_use[nrule]));
console.log(value.substring(0, pos) + ' <--- (' + message + ')');
console.log('\n');
} {
} else {
console.warn('tokens_to_use[nrule][2] is undefined. This is ok if nrule is the last rule.');
}
}
Expand Down Expand Up @@ -2076,6 +2074,12 @@ export default function(value, nominatim_object, optional_conf_parm) {
} else {
error = [ at+6, '. ' + t('missing', {'symbol': ')'}) + '.'];
}
} else if (matchTokens(tokens, at+3, 'number') && matchTokens(tokens, at+4, ')')) {
// User likely meant hours without minutes, e.g. (sunset-1) instead of (sunset-01:00)
const hours = ('0' + tokens[at+3][0]).slice(-2);
const suggestion = '(' + tokens[at+1][0] + tokens[at+2][0] + hours + ':00)';
throw formatWarnErrorMessage(nrule, at+3,
t('time offset hours only', { suggestion: suggestion }));
} else {
error = [ at+5, ' ' + t('(time)') + '.'];
}
Expand Down
1 change: 1 addition & 0 deletions src/locales/lang.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
'outside day': 'Time range starts outside of the current day'
'zero calculation': 'Adding zero in a variable time calculation does not change the variable time. Please omit the calculation (example: "sunrise-(sunset-00:00)").'
'calculation syntax': 'Calculation with variable time is not in the right syntax'
'time offset hours only': 'Time offset must be in format HH:MM, not just hours. Did you mean "{{suggestion}}"?'
'missing': 'Missing "{{symbol}}"'
'(time)': (time)
'bad range': 'Bad range: {{from}}-{{to}}'
Expand Down
1 change: 1 addition & 0 deletions src/locales/opening_hours_resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ de:
outside day: "Die Zeitspanne beginnt außerhalb des aktuellen Tages"
zero calculation: "Das Hinzufügen von 0 in einer variablen Zeitberechnung ändert die variable Zeit nicht. Bitte entferne die Zeitberechnung (Beispiel: \"sunrise-(sunset-00:00)\")."
calculation syntax: "Berechnung mit variabler Zeit hat nicht die korrekte Syntax"
time offset hours only: "Zeitversatz muss im Format HH:MM angegeben werden, nicht nur Stunden. Meintest du \"{{suggestion}}\"?"
missing: "Fehlendes \"{{symbol}}\""
'(time)': "(Zeit)"
bad range: "Ungültige Zeitspanne: {{from}}-{{to}}"
Expand Down
14 changes: 13 additions & 1 deletion test/test.de.log
Original file line number Diff line number Diff line change
Expand Up @@ -2243,6 +2243,18 @@ week 02-52/2 We, <--- (Eine weitere Regel an dieser Stelle ergibt keinen Sinn.
"Incorrect syntax which should throw an error" for "(sunrise)-sunset; 00:23-00:42 unknown "warning at correct position?"": PASSED
(sunrise) <--- (Berechnung mit variabler Zeit hat nicht die korrekte Syntax. "+" or "-" erwartet.)

"Incorrect syntax which should throw an error" for "(sunset-1); 00:23-00:42 unknown "warning at correct position?"": PASSED
(sunset-1 <--- (Zeitversatz muss im Format HH:MM angegeben werden, nicht nur Stunden. Meintest du "(sunset-01:00)"?)

"Incorrect syntax which should throw an error" for "(sunrise+2); 00:23-00:42 unknown "warning at correct position?"": PASSED
(sunrise+2 <--- (Zeitversatz muss im Format HH:MM angegeben werden, nicht nur Stunden. Meintest du "(sunrise+02:00)"?)

"Incorrect syntax which should throw an error" for "(dawn-1); 00:23-00:42 unknown "warning at correct position?"": PASSED
(dawn-1 <--- (Zeitversatz muss im Format HH:MM angegeben werden, nicht nur Stunden. Meintest du "(dawn-01:00)"?)

"Incorrect syntax which should throw an error" for "(dusk+3); 00:23-00:42 unknown "warning at correct position?"": PASSED
(dusk+3 <--- (Zeitversatz muss im Format HH:MM angegeben werden, nicht nur Stunden. Meintest du "(dusk+03:00)"?)

"Incorrect syntax which should throw an error" for "(; 00:23-00:42 unknown "warning at correct position?"": PASSED
( <--- (Unerwartetes Zeichen: "(" Das bedeutet, dass die Syntax an dieser Stelle nicht erkannt werden konnte.)

Expand Down Expand Up @@ -2709,7 +2721,7 @@ Der optional_conf_parm["tag_key"] fehlt, ist aber notwendig wegen optional_conf_
"Test isEqualTo function" for "Mo 10:00-20:00; We-Fr 10:00-20:01": PASSED
"Test isEqualTo function" for "Mo 10:00-20:00; We-Fr 10:00-19:59": PASSED
"Test isEqualTo function" for "closed; Sa unknown "comment"": PASSED
940/950 tests passed. 10 did not pass.
944/954 tests passed. 10 did not pass.
41 tests where (partly) ignored, sorted by commonness:
* 26: prettifyValue (most of the cases this is used to test if values with selectors in wrong order or wrong symbols (error tolerance) are evaluated correctly)
* 11: not implemented yet
Expand Down
14 changes: 13 additions & 1 deletion test/test.en.log
Original file line number Diff line number Diff line change
Expand Up @@ -2243,6 +2243,18 @@ week 02-52/2 We, <--- (An additional rule does not make sense here. Just use a
"Incorrect syntax which should throw an error" for "(sunrise)-sunset; 00:23-00:42 unknown "warning at correct position?"": PASSED
(sunrise) <--- (Calculation with variable time is not in the right syntax. "+" or "-" expected.)

"Incorrect syntax which should throw an error" for "(sunset-1); 00:23-00:42 unknown "warning at correct position?"": PASSED
(sunset-1 <--- (Time offset must be in format HH:MM, not just hours. Did you mean "(sunset-01:00)"?)

"Incorrect syntax which should throw an error" for "(sunrise+2); 00:23-00:42 unknown "warning at correct position?"": PASSED
(sunrise+2 <--- (Time offset must be in format HH:MM, not just hours. Did you mean "(sunrise+02:00)"?)

"Incorrect syntax which should throw an error" for "(dawn-1); 00:23-00:42 unknown "warning at correct position?"": PASSED
(dawn-1 <--- (Time offset must be in format HH:MM, not just hours. Did you mean "(dawn-01:00)"?)

"Incorrect syntax which should throw an error" for "(dusk+3); 00:23-00:42 unknown "warning at correct position?"": PASSED
(dusk+3 <--- (Time offset must be in format HH:MM, not just hours. Did you mean "(dusk+03:00)"?)

"Incorrect syntax which should throw an error" for "(; 00:23-00:42 unknown "warning at correct position?"": PASSED
( <--- (Unexpected token: "(" This means that the syntax is not valid at that point or it is currently not supported.)

Expand Down Expand Up @@ -2702,7 +2714,7 @@ The optional_conf_parm["tag_key"] is missing, required by optional_conf_parm["ma
"Test isEqualTo function" for "Mo 10:00-20:00; We-Fr 10:00-20:01": PASSED
"Test isEqualTo function" for "Mo 10:00-20:00; We-Fr 10:00-19:59": PASSED
"Test isEqualTo function" for "closed; Sa unknown "comment"": PASSED
933/943 tests passed. 10 did not pass.
937/947 tests passed. 10 did not pass.
41 tests where (partly) ignored, sorted by commonness:
* 26: prettifyValue (most of the cases this is used to test if values with selectors in wrong order or wrong symbols (error tolerance) are evaluated correctly)
* 11: not implemented yet
Expand Down
4 changes: 4 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4997,6 +4997,10 @@ test.addShouldFail('Incorrect syntax which should throw an error', [
'(sunrise+01:00-sunset' + value_suffix,
'(sunrise+01::)-sunset' + value_suffix,
'(sunrise)-sunset' + value_suffix,
'(sunset-1)' + value_suffix,
'(sunrise+2)' + value_suffix,
'(dawn-1)' + value_suffix,
'(dusk+3)' + value_suffix,
'(' + value_suffix,
'sunrise-(' + value_suffix,
'sunrise-sunset,(' + value_suffix,
Expand Down