forked from opening-hours/opening_hours.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
executable file
·5857 lines (5370 loc) · 311 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env nodejs
// preamble {{{
/* Parameter handling {{{ */
var optimist = require('optimist')
.usage('Usage: $0 [optional parameters]')
.describe('h', 'Display the usage')
// .describe('v', 'Verbose output')
.describe('f', 'File path to the opening_hours.js libary file to run the tests against.')
.describe('l', 'Locale for error/warning messages and prettified values.')
.alias('h', 'help')
// .alias('v', 'verbose')
.alias('f', 'library-file')
.alias('l', 'locale')
.default('f', './opening_hours.js')
.default('l', 'en');
var argv = optimist.argv;
if (argv.help) {
optimist.showHelp();
process.exit(0);
}
/* }}} */
/* Required modules {{{ */
var opening_hours = require('./' + argv['library-file']);
var colors = require('colors');
var sprintf = require('sprintf-js').sprintf;
var timekeeper = require('timekeeper');
var moment = require('moment');
var glob = require('glob');
var yaml = require('js-yaml');
var fs = require('fs');
/* }}} */
colors.setTheme({
passed: [ 'green' , 'bold' ] , // printed with console.log
warn: [ 'blue' , 'bold' ] , // printed with console.info
failed: [ 'red' , 'bold' ] , // printed with console.warn
crashed: [ 'magenta', 'bold' ] , // printed with console.error
ignored: [ 'yellow' , 'bold' ] ,
});
// Because of DST and such things, the timezone needs to be set to
// Europe/Berlin for some tests to be reproducible.
process.env.TZ = 'Europe/Berlin';
/* Fake time to make "The year is in the past." test deterministic. */
var timekeeperTime = new Date('Sat May 23 2015 23:23:23 GMT+0200 (CEST)');
timekeeper.travel(timekeeperTime); // Travel to that date.
var test = new opening_hours_test();
// test.extensive_testing = true;
// FIXME: Do it.
/* }}} */
// Nominatim data {{{
var nominatim_by_loc = {};
for (var nominatim_file of glob.sync("holidays/nominatim_cache/*.yaml")) {
var country_state = nominatim_file.match(/^.*\/([^/]*)\.yaml$/)[1];
nominatim_by_loc[country_state] = yaml.safeLoad(fs.readFileSync(nominatim_file));
}
var nominatim_default = nominatim_by_loc.de_bw;
// https://nominatim.openstreetmap.org/reverse?format=json&lat=60.5487429714954&lon=9.81602098644987&zoom=18&addressdetails=1
var nominatim_sunrise_below = {
"place_id": "71977948",
"licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright",
"osm_type": "way",
"osm_id": "118145917",
"lat": "60.5467949",
"lon": "9.8269589",
"display_name": "243, Ringerike, Buskerud, Norway",
"address": {
"road": "243",
"county": "Ringerike",
"state": "Buskerud",
"country": "Norway",
"country_code": "no"
}
};
// https://nominatim.openstreetmap.org/reverse?format=json&lat=27.567&lon=-71.093&zoom=18&addressdetails=1
// Actual response: {"error":"Unable to geocode"}
var nominatim_no_valid_address = {
"place_id": "-966",
"licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright",
"osm_type": "way",
"osm_id": "-42",
"lat": "27.567",
"lon": "-71.093",
"display_name": "-23, None, None, None",
"address": {
"road": "-23",
"county": "None",
"state": "None",
"country": "None",
"country_code": "none"
}
};
/* }}} */
var sane_value_suffix = '; 00:01-00:02 closed "warning at correct position?"';
// Suffix to add to values to make the value more complex and to spot problems
// easier without changing there meaning (in most cases).
var value_suffix = '; 00:23-00:42 unknown "warning at correct position?"';
// This suffix value is there to test if the warning marks the correct position of the problem.
var value_suffix_to_disable_time_not_used = ' 12:00-15:00';
var value_perfectly_valid = [
'Mo-Fr 12:00-18:00; We off; Sa,PH 12:00-17:00; Th[3],Th[-1] off',
'open; Tu-Su 08:30-09:00 off; Tu-Su,PH 14:00-14:30 off; Mo 08:00-13:00 off',
/* Don‘t use 24/7 instead of "open". PH usage does not make much sense … */
];
/* Used in the README and other places.
* Those values must be perfectly valid and not return any warnings,
* regardless of the warnings_severity.
*/
/* Avoid the warning that no time selector was used in a rule. Use this if you
* are checking for values which should return another warning.
* warning.
*/
// time ranges {{{
test.addTest('Time intervals', [
'10:00-12:00',
'08:00-09:00; 10:00-12:00',
'10:00-12:00,',
'10:00-12:00;',
'10-12', // Do not use. Returns warning.
'10:00-11:00,11:00-12:00',
'10:00-12:00,10:30-11:30',
'10:00-14:00; 12:00-14:00 off',
], '2012-10-01 0:00', '2012-10-08 0:00', [
[ '2012-10-01 10:00', '2012-10-01 12:00' ],
[ '2012-10-02 10:00', '2012-10-02 12:00' ],
[ '2012-10-03 10:00', '2012-10-03 12:00' ],
[ '2012-10-04 10:00', '2012-10-04 12:00' ],
[ '2012-10-05 10:00', '2012-10-05 12:00' ],
[ '2012-10-06 10:00', '2012-10-06 12:00' ],
[ '2012-10-07 10:00', '2012-10-07 12:00' ],
], 1000 * 60 * 60 * 2 * 7, 0, true, {}, 'not last test');
test.addTest('Time intervals', [
'24/7; Mo 15:00-16:00 off', // throws a warning, use next value which is evaluated the same but is more logical.
'open; Mo 15:00-16:00 off',
'00:00-24:00; Mo 15:00-16:00 off',
], '2012-10-01 0:00', '2012-10-08 0:00', [
[ '2012-10-01 00:00', '2012-10-01 15:00' ],
[ '2012-10-01 16:00', '2012-10-08 00:00' ],
], 1000 * 60 * 60 * (24 * 6 + 23), 0, true, {}, 'not last test');
test.addTest('Time zero intervals (always closed)', [
'off',
'closed',
ignored('always closed', 'prettifyValue'),
'off; closed',
'24/7 closed "always closed"', // Used on the demo page.
'24/7: closed "always closed"',
'24/7 closed: "always closed"',
'24/7: closed: "always closed"',
'closed "always closed"',
'off "always closed"',
'00:00-24:00 closed',
'24/7 closed',
], '2012-10-01 0:00', '2018-10-08 0:00', [
], 0, 0, true, {}, 'not last test');
test.addTest('Time zero intervals (always closed), prettifyValue is OK …', [
ignored('yes', 'prettifyValue'),
], '2012-10-01 0:00', '2012-10-03 0:00', [
[ '2012-10-01 00:00', '2012-10-01 06:00', false, 'specified as yes: At night (unknown time schedule or daylight detection)' ], // 6
[ '2012-10-01 18:00', '2012-10-02 06:00', false, 'specified as yes: At night (unknown time schedule or daylight detection)' ], // 12
[ '2012-10-02 18:00', '2012-10-03 00:00', false, 'specified as yes: At night (unknown time schedule or daylight detection)' ], // 6
], 1000 * 60 * 60 * (6 + 12 + 6), 0, true, {}, 'not last test', { 'map_value': true, 'tag_key': 'lit' });
// error tolerance {{{
test.addTest('Error tolerance: dot as time separator', [
'10:00-12:00', // reference value for prettify
'10.00-12.00',
], '2012-10-01 0:00', '2012-10-08 0:00', [
[ '2012-10-01 10:00', '2012-10-01 12:00' ],
[ '2012-10-02 10:00', '2012-10-02 12:00' ],
[ '2012-10-03 10:00', '2012-10-03 12:00' ],
[ '2012-10-04 10:00', '2012-10-04 12:00' ],
[ '2012-10-05 10:00', '2012-10-05 12:00' ],
[ '2012-10-06 10:00', '2012-10-06 12:00' ],
[ '2012-10-07 10:00', '2012-10-07 12:00' ],
], 1000 * 60 * 60 * 2 * 7, 0, true, {}, 'not last test');
test.addTest('Error tolerance: dot as time separator', [
'10:00-14:00; 12:00-14:00 off', // reference value for prettify
'10-14; 12-14 off', // '22-2', // Do not use. Returns warning.
'10.00-14.00; 12.00-14.00 off',
// '10.00-12.00;10.30-11.30',
], '2012-10-01 0:00', '2012-10-08 0:00', [
[ '2012-10-01 10:00', '2012-10-01 12:00' ],
[ '2012-10-02 10:00', '2012-10-02 12:00' ],
[ '2012-10-03 10:00', '2012-10-03 12:00' ],
[ '2012-10-04 10:00', '2012-10-04 12:00' ],
[ '2012-10-05 10:00', '2012-10-05 12:00' ],
[ '2012-10-06 10:00', '2012-10-06 12:00' ],
[ '2012-10-07 10:00', '2012-10-07 12:00' ],
], 1000 * 60 * 60 * 2 * 7, 0, true, {}, 'not last test');
test.addTest('Error tolerance: Correctly handle pm time.', [
'10:00-12:00,13:00-20:00', // reference value for prettify
'10-12,13-20',
'10am-12pm,1pm-8pm',
'10:00am-12:00pm,1:00pm-8:00pm',
'10:00am-12:00pm,1.00pm-8.00pm',
], '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' ],
[ '2012-10-02 10:00', '2012-10-02 12:00' ],
[ '2012-10-02 13:00', '2012-10-02 20:00' ],
], 1000 * 60 * 60 * (2 + 7) * 2, 0, true, {}, 'not last test');
/* Legacy 12-hour clock am/pm format {{{ */
/*
* https://en.wikipedia.org/wiki/12-hour_clock
* '1pm-8pm/10am-12am', // Can not be corrected as / is a valid token
*/
test.addTest('Error tolerance: Correctly handle am/pm time.', [
'00:00-00:01', // reference value for prettify
'12:00am-12:01am',
'12:00 a.m. - 12:01am',
], '2012-10-01 0:00', '2012-10-03 0:00', [
[ '2012-10-01 00:00', '2012-10-01 00:01' ],
[ '2012-10-02 00:00', '2012-10-02 00:01' ],
], 1000 * 60 * 2, 0, true, {}, 'not only test');
test.addTest('Error tolerance: Correctly handle am/pm time.', [
'01:00-11:00', // reference value for prettify
'01:00am-11:00am',
'01am-11am',
], '2012-10-01 0:00', '2012-10-03 0:00', [
[ '2012-10-01 01:00', '2012-10-01 11:00' ],
[ '2012-10-02 01:00', '2012-10-02 11:00' ],
], 1000 * 60 * 60 * 10 * 2, 0, true, {}, 'not only test');
test.addTest('Error tolerance: Correctly handle am/pm time.', [
'11:59-12:00', // reference value for prettify
'11:59am-12:00pm',
'11:59a.m.-12:00 p.m.',
], '2012-10-01 0:00', '2012-10-03 0:00', [
[ '2012-10-01 11:59', '2012-10-01 12:00' ],
[ '2012-10-02 11:59', '2012-10-02 12:00' ],
], 1000 * 60 * 2, 0, true, {}, 'not only test');
test.addTest('Error tolerance: Correctly handle am/pm time.', [
'12:01-12:59', // reference value for prettify
'12:01pm-12:59pm',
'12:01p.m.-12:59 p.m.',
], '2012-10-01 0:00', '2012-10-03 0:00', [
[ '2012-10-01 12:01', '2012-10-01 12:59' ],
[ '2012-10-02 12:01', '2012-10-02 12:59' ],
], 1000 * 60 * 58 * 2, 0, true, {}, 'not only test');
test.addTest('Error tolerance: Correctly handle am/pm time.', [
'13:00-13:01', // reference value for prettify
'01:00pm-01:01pm',
], '2012-10-01 0:00', '2012-10-03 0:00', [
[ '2012-10-01 13:00', '2012-10-01 13:01' ],
[ '2012-10-02 13:00', '2012-10-02 13:01' ],
], 1000 * 60 * 2, 0, true, {}, 'not only test');
test.addTest('Error tolerance: Correctly handle am/pm time.', [
'23:00-23:59', // reference value for prettify
'11:00pm-11:59pm',
], '2012-10-01 0:00', '2012-10-03 0:00', [
[ '2012-10-01 23:00', '2012-10-01 23:59' ],
[ '2012-10-02 23:00', '2012-10-02 23:59' ],
], 1000 * 60 * 59 * 2, 0, true, {}, 'not only test');
/* }}} */
test.addTest('Error tolerance: Time intervals, short time', [
'Mo 07:00-18:00', //reference value for prettify
'Montags 07:00-18:00', //reference value for prettify
'Mo 7-18', // throws a warning, use previous value which is equal.
], '2012-10-01 0:00', '2012-10-08 0:00', [
[ '2012-10-01 07:00', '2012-10-01 18:00' ],
], 1000 * 60 * 60 * 11, 0, true, {}, 'not last test');
test.addTest('Error tolerance: Time range', [
'Mo 12:00-14:00', // reference value for prettify
'Mo12:00-14:00',
'Mo 12:00→14:00',
'Mo 12:00–14:00',
'Mo 12:00−14:00',
'Mo 12:00—14:00',
'Mo 12:00ー14:00',
'Mo 12:00=14:00',
'Mo 12:00 to 14:00',
'Mo 12:00 до 14:00',
'Mo 12:00 a 14:00',
'Mo 12:00 as 14:00',
'Mo 12:00 á 14:00',
'Mo 12:00 ás 14:00',
'Mo 12:00 à 14:00',
'Mo 12:00 às 14:00',
'Mo 12:00 ate 14:00',
'Mo 12:00 till 14:00',
'Mo 12:00 til 14:00',
'Mo 12:00 until 14:00',
'Mo 12:00 through 14:00',
'Mo 12:00~14:00',
'Mo 12:00~14:00',
'Mo 12:00-14:00',
'Mo 12°°-14:00',
], '2012-10-01 0:00', '2012-10-08 0:00', [
[ '2012-10-01 12:00', '2012-10-01 14:00' ],
], 1000 * 60 * 60 * 2, 0, true, {}, 'not only test');
test.addTest('Error tolerance: Time range', [
'Mo 00:30-14:09' + sane_value_suffix, // reference value for prettify
'Mo 00³°-14:09' + sane_value_suffix,
'Mo 00:³°-14:09' + sane_value_suffix,
'Mo °°³°-14:09' + sane_value_suffix,
'Mo ⁰⁰:³⁰-¹⁴:⁰⁹' + sane_value_suffix,
'Mo ₀₀₃₀-₁₄⁰⁹' + sane_value_suffix,
'Mo ₀₀:₃₀-₁₄:₀₉' + sane_value_suffix,
'Mo ₀:₃₀-₁₄:₀₉' + sane_value_suffix,
'Mo ₀:₃₀-₁₄:₉' + sane_value_suffix,
], '2012-10-01 0:00', '2012-10-08 0:00', [
[ '2012-10-01 00:30', '2012-10-01 14:09' ],
], 1000 * 60 * (60 * 13 + 39), 0, true, {}, 'not only test');
// }}}
// time range spanning midnight {{{
test.addTest('Time ranges spanning midnight', [
'22:00-02:00',
'22:00-26:00',
'22-2', // Do not use. Returns warning.
], '2012-10-01 0:00', '2012-10-08 0:00', [
[ '2012-10-01 00:00', '2012-10-01 02:00' ],
[ '2012-10-01 22:00', '2012-10-02 02:00' ],
[ '2012-10-02 22:00', '2012-10-03 02:00' ],
[ '2012-10-03 22:00', '2012-10-04 02:00' ],
[ '2012-10-04 22:00', '2012-10-05 02:00' ],
[ '2012-10-05 22:00', '2012-10-06 02:00' ],
[ '2012-10-06 22:00', '2012-10-07 02:00' ],
[ '2012-10-07 22:00', '2012-10-08 00:00' ],
], 1000 * 60 * 60 * 4 * 7, 0, true, nominatim_default);
test.addTest('Time ranges spanning midnight', [
'22:00-26:00', // reference value for prettify
'22-26', // Do not use. Returns warning.
], '2012-10-01 0:00', '2012-10-08 0:00', [
[ '2012-10-01 00:00', '2012-10-01 02:00' ],
[ '2012-10-01 22:00', '2012-10-02 02:00' ],
[ '2012-10-02 22:00', '2012-10-03 02:00' ],
[ '2012-10-03 22:00', '2012-10-04 02:00' ],
[ '2012-10-04 22:00', '2012-10-05 02:00' ],
[ '2012-10-05 22:00', '2012-10-06 02:00' ],
[ '2012-10-06 22:00', '2012-10-07 02:00' ],
[ '2012-10-07 22:00', '2012-10-08 00:00' ],
], 1000 * 60 * 60 * 4 * 7, 0, true, nominatim_default);
test.addTest('Time ranges spanning midnight', [
'We 22:00-22:00',
'We22:00-22:00',
], '2012-10-01 0:00', '2012-10-08 0:00', [
[ '2012-10-03 22:00', '2012-10-04 22:00' ],
], 1000 * 60 * 60 * 24, 0, true, {}, 'not last test');
test.addTest('Time ranges spanning midnight with date overwriting', [
'22:00-02:00; Tu 12:00-14:00',
'22:00-02:00; Tu12:00-14:00',
], '2012-10-01 0:00', '2012-10-08 0:00', [
[ '2012-10-01 00:00', '2012-10-01 02:00' ],
[ '2012-10-01 22:00', '2012-10-02 00:00' ],
[ '2012-10-02 12:00', '2012-10-02 14:00' ],
[ '2012-10-03 00:00', '2012-10-03 02:00' ],
[ '2012-10-03 22:00', '2012-10-04 02:00' ],
[ '2012-10-04 22:00', '2012-10-05 02:00' ],
[ '2012-10-05 22:00', '2012-10-06 02:00' ],
[ '2012-10-06 22:00', '2012-10-07 02:00' ],
[ '2012-10-07 22:00', '2012-10-08 00:00' ],
], 1000 * 60 * 60 * (6 * 4 + 2), 0, true, {}, 'not last test');
test.addTest('Time ranges spanning midnight with date overwriting (complex real world example)', [
'Su-Tu 11:00-01:00, We-Th 11:00-03:00, Fr 11:00-06:00, Sa 11:00-07:00',
'Su-Tu 11:00-01:00, We-Th11:00-03:00, Fr 11:00-06:00, Sa 11:00-07:00',
], '2012-10-01 0:00', '2012-10-08 0:00', [
[ '2012-10-01 00:00', '2012-10-01 01:00', ], // Mo: Su-Tu 11:00-01:00
[ '2012-10-01 11:00', '2012-10-02 01:00', ], // Mo: Su-Tu 11:00-01:00
[ '2012-10-02 11:00', '2012-10-03 01:00', ], // Tu: Su-Tu 11:00-01:00
[ '2012-10-03 11:00', '2012-10-04 03:00', ], // We: We-Th 11:00-03:00
[ '2012-10-04 11:00', '2012-10-05 03:00', ], // Th: We-Th 11:00-03:00
[ '2012-10-05 11:00', '2012-10-06 06:00', ], // Fr: Fr 11:00-06:00
[ '2012-10-06 11:00', '2012-10-07 07:00', ], // Sa: Sa 11:00-07:00
[ '2012-10-07 11:00', '2012-10-08 00:00', ], // Su: Su-Tu 11:00-01:00
], 1000 * 60 * 60 * (1 + 14 * 2 + 16 * 2 + 19 + 20 + 13), 0, true);
test.addTest('Time ranges spanning midnight (maximum supported)', [
'Tu 23:59-48:00',
], '2012-10-01 0:00', '2012-10-08 0:00', [
[ '2012-10-02 23:59', '2012-10-04 00:00' ],
], 1000 * 60 * (24 * 60 + 1), 0, true, {}, 'not last test');
test.addTest('Time ranges spanning midnight with open ened (maximum supported)', [
'Tu 23:59-40:00+',
// 'Tu 23:59-00:00 open, 24:00-40:00 open, 40:00+ open, 40:00+',
], '2012-10-01 0:00', '2012-10-08 0:00', [
[ '2012-10-02 23:59', '2012-10-03 16:00' ],
[ '2012-10-03 16:00', '2012-10-04 00:00', true, 'Specified as open end. Closing time was guessed.' ],
], 1000 * 60 * (16 * 60 + 1), 1000 * 60 * 60 * 8, true, {}, 'not only test');
// }}}
// }}}
// open end {{{
test.addTest('Open end', [
'07:00+ open "visit there website to know if they did already close"', // specified comments should not be overridden
'07:00+ unknown "visit there website to know if they did already close"', // will always interpreted as unknown
], '2012-10-01 0:00', '2012-10-02 0:00', [
[ '2012-10-01 07:00', '2012-10-02 00:00', true, 'visit there website to know if they did already close' ],
], 0, 1000 * 60 * 60 * (24 - 7), true, {}, 'not last test');
test.addTest('Open end', [
'17:00+',
'17:00-late',
'17:00 til late',
'17:00 till late',
'17:00 bis Open End',
'17:00-open end',
// '17:00 – Open End', // '–' matches first.
'17:00-openend',
'17:00+; 15:00-16:00 off',
'15:00-16:00 off; 17:00+',
], '2012-10-01 0:00', '2012-10-02 0:00', [
[ '2012-10-01 00:00', '2012-10-01 03:00', true, 'Specified as open end. Closing time was guessed.' ],
[ '2012-10-01 17:00', '2012-10-02 00:00', true, 'Specified as open end. Closing time was guessed.' ],
], 0, 1000 * 60 * 60 * (3 + 24 - 17), true, nominatim_default, 'not last test');
test.addTest('Open end, variable time', [
'sunrise+',
], '2012-10-01 0:00', '2012-10-02 0:00', [
[ '2012-10-01 07:22', '2012-10-02 00:00', true, 'Specified as open end. Closing time was guessed.' ],
], 0, 1000 * 60 * (60 * 16 + 60 - 22), false, nominatim_default, 'not last test');
test.addTest('Open end, variable time', [
'(sunrise+01:00)+',
], '2012-10-01 0:00', '2012-10-02 0:00', [
[ '2012-10-01 08:22', '2012-10-02 00:00', true, 'Specified as open end. Closing time was guessed.' ],
], 0, 1000 * 60 * (60 * 15 + 60 - 22), false, nominatim_default, 'not last test');
test.addTest('Open end', [
'17:00+ off',
'17:00+off',
'17:00-19:00 off',
], '2012-10-01 0:00', '2012-10-02 0:00', [
], 0, 0, true, {}, 'not last test');
test.addTest('Open end', [
// '12:00-16:00,07:00+', // Fails. This is ok. Just put your time selectors in the correct order.
'07:00+,12:00-16:00',
'07:00+,12:00-13:00,13:00-16:00',
'07:00+,12:00-16:00; 16:00-24:00 closed "needed because of open end"', // Now obsolete: https://github.com/opening-hours/opening_hours.js/issues/48
], '2012-10-01 0:00', '2012-10-02 5:00', [
[ '2012-10-01 07:00', '2012-10-01 12:00', true, 'Specified as open end. Closing time was guessed.' ],
[ '2012-10-01 12:00', '2012-10-01 16:00' ],
], 1000 * 60 * 60 * 4, 1000 * 60 * 60 * 5, true, {}, 'not only test');
test.addTest('Open end', [
'05:00-06:00,06:45-07:00+,13:00-16:00',
'06:45-07:00+,05:00-06:00,13:00-16:00',
'06:45-07:00+,05:00-06:00,13:00-14:00,14:00-16:00',
], '2012-10-01 0:00', '2012-10-02 5:00', [
[ '2012-10-01 05:00', '2012-10-01 06:00' ],
[ '2012-10-01 06:45', '2012-10-01 07:00' ],
[ '2012-10-01 07:00', '2012-10-01 13:00', true, 'Specified as open end. Closing time was guessed.' ],
[ '2012-10-01 13:00', '2012-10-01 16:00' ],
], 1000 * 60 * 60 * (4 + 0.25), 1000 * 60 * 60 * 6, true, {}, 'not only test');
/* To complicated, just don‘t use them … {{{ */
test.addTest('Open end', [
'17:00+,13:00-02:00; 02:00-03:00 closed "needed because of open end"',
'17:00+,13:00-02:00; 02:00-03:00 closed "needed because of open end"',
// '17:00-00:00 unknown "Specified as open end. Closing time was guessed.", 13:00-00:00 open' // First internal rule.
// + ', ' [> overwritten part: 00:00-03:00 open' <] + '00:00-02:00 open', // Second internal rule.
], '2012-10-01 0:00', '2012-10-02 5:00', [
[ '2012-10-01 00:00', '2012-10-01 02:00' ],
[ '2012-10-01 13:00', '2012-10-02 02:00' ],
], 1000 * 60 * 60 * (2 + 24 - 13 + 2), 0, true, {}, 'not only test');
test.addTest('Open end', [
'13:00-17:00+', // Use this.
'13:00-17:00,17:00+',
'13:00-02:00,17:00+', // Do not use.
'13:00-17:00 open, 17:00+'
], '2012-10-01 0:00', '2012-10-02 5:00', [
[ '2012-10-01 00:00', '2012-10-01 03:00', true, 'Specified as open end. Closing time was guessed.' ],
[ '2012-10-01 13:00', '2012-10-01 17:00' ],
[ '2012-10-01 17:00', '2012-10-02 03:00', true, 'Specified as open end. Closing time was guessed.' ],
], 1000 * 60 * 60 * 4, 1000 * 60 * 60 * (3 + (3+4+3)), true, {}, 'not only test');
test.addTest('Open end', [
// '05:00-06:00,17:00+,13:00-02:00',
// '05:00-06:00,13:00-02:00,17:00+',
], '2012-10-01 0:00', '2012-10-02 5:00', [
[ '2012-10-01 00:00', '2012-10-01 02:00' ],
[ '2012-10-01 05:00', '2012-10-01 06:00' ],
[ '2012-10-01 13:00', '2012-10-02 02:00' ],
], 1000 * 60 * 60 * (2 + 1 + (24 - 13 + 2)), 0, true, {}, 'not only test');
/* }}} */
// proposal: opening hours open end fixed time extension {{{
// https://wiki.openstreetmap.org/wiki/Proposed_features/opening_hours_open_end_fixed_time_extension
test.addTest('Fixed time followed by open end', [
'14:00-17:00+',
], '2012-10-01 0:00', '2012-10-02 0:00', [
[ '2012-10-01 00:00', '2012-10-01 03:00', true, 'Specified as open end. Closing time was guessed.' ],
[ '2012-10-01 14:00', '2012-10-01 17:00' ],
[ '2012-10-01 17:00', '2012-10-02 00:00', true, 'Specified as open end. Closing time was guessed.' ],
], 1000 * 60 * 60 * 3, 1000 * 60 * 60 * (3 + 7), true, {}, 'not last test');
test.addTest('Fixed time followed by open end, wrapping over midnight', [
'Mo 22:00-04:00+',
'Mo 22:00-28:00+',
], '2012-10-01 0:00', '2012-10-03 0:00', [
[ '2012-10-01 22:00', '2012-10-02 04:00' ],
[ '2012-10-02 04:00', '2012-10-02 12:00', true, 'Specified as open end. Closing time was guessed.' ],
], 1000 * 60 * 60 * 6, 1000 * 60 * 60 * 8, true, {}, 'not last test');
test.addTest('variable time range followed by open end', [
'14:00-sunset+',
], '2012-10-01 0:00', '2012-10-02 0:00', [
[ '2012-10-01 00:00', '2012-10-01 04:00', true, 'Specified as open end. Closing time was guessed.' ],
[ '2012-10-01 14:00', '2012-10-01 19:00' ],
[ '2012-10-01 19:00', '2012-10-02 00:00', true, 'Specified as open end. Closing time was guessed.' ],
], 1000 * 60 * 60 * 5, 1000 * 60 * 60 * (4 + 5), false, nominatim_default, 'not last test');
test.addTest('variable time range followed by open end', [
'sunrise-14:00+',
'sunrise-14:00,14:00+', // Internally represented as two time selectors.
'sunrise-14:00 open, 14:00+',
], '2012-10-01 0:00', '2012-10-02 5:00', [
[ '2012-10-01 07:22', '2012-10-01 14:00' ],
[ '2012-10-01 14:00', '2012-10-02 00:00', true, 'Specified as open end. Closing time was guessed.' ],
], 1000 * 60 * (38 + 60 * 6), 1000 * 60 * 60 * 10, false, nominatim_default, 'not only test');
test.addTest('variable time range followed by open end', [
'sunrise-(sunset+01:00)+',
'sunrise-(sunset+01:00)+; Su off',
], '2012-10-06 0:00', '2012-10-07 0:00', [
[ '2012-10-06 00:00', '2012-10-06 05:00', true, 'Specified as open end. Closing time was guessed.' ],
[ '2012-10-06 07:29', '2012-10-06 19:50' ],
[ '2012-10-06 19:50', '2012-10-07 00:00', true, 'Specified as open end. Closing time was guessed.' ],
], 1000 * 60 * (31 + (19 - 8) * 60 + 50), 1000 * 60 * (60 * 5 + 60 * 4 + 10), false, nominatim_default, 'not last test');
test.addTest('variable time range followed by open end, day wrap and different states', [
'Fr 11:00-24:00+ open "geöffnet täglich von 11:00 Uhr bis tief in die Nacht"',
'Fr 11:00-24:00+ open"geöffnet täglich von 11:00 Uhr bis tief in die Nacht"',
'Fr 11:00-24:00+open "geöffnet täglich von 11:00 Uhr bis tief in die Nacht"',
'Fr 11:00-24:00+open"geöffnet täglich von 11:00 Uhr bis tief in die Nacht"',
'Fr11:00-24:00+open"geöffnet täglich von 11:00 Uhr bis tief in die Nacht"',
], '2012-10-01 0:00', '2012-10-08 0:00', [
[ '2012-10-05 11:00', '2012-10-06 00:00', false, 'geöffnet täglich von 11:00 Uhr bis tief in die Nacht' ],
[ '2012-10-06 00:00', '2012-10-06 08:00', true, 'geöffnet täglich von 11:00 Uhr bis tief in die Nacht' ],
], 1000 * 60 * 60 * 13, 1000 * 60 * 60 * 8, true, nominatim_default, 'not last test');
// }}}
// }}}
// variable times {{{
test.addTest('Variable times e.g. dawn, dusk', [
'Mo dawn-dusk',
'dawn-dusk',
], '2012-10-01 0:00', '2012-10-02 0:00', [
[ '2012-10-01 06:50', '2012-10-01 19:32' ],
], 1000 * 60 * (60 * 12 + 10 + 32), 0, false, nominatim_default, 'not last test');
test.addTest('Variable times e.g. sunrise, sunset', [
'Mo sunrise-sunset',
'sunrise-sunset',
], '2012-10-01 0:00', '2012-10-02 0:00', [
[ '2012-10-01 07:22', '2012-10-01 19:00' ],
], 1000 * 60 * (60 * 11 + 38), 0, false, nominatim_default);
test.addTest('Variable times e.g. sunrise, sunset without coordinates (→ constant times)', [
'sunrise-sunset',
], '2012-10-01 0:00', '2012-10-03 0:00', [
[ '2012-10-01 06:00', '2012-10-01 18:00' ],
[ '2012-10-02 06:00', '2012-10-02 18:00' ],
], 1000 * 60 * 60 * 12 * 2, 0, true);
test.addTest('Variable times e.g. sunrise, sunset', [
'sunrise-sunset open "Beware of sunburn!"',
// 'sunrise-sunset closed "Beware of sunburn!"', // Not so intuitive I guess.
], '2012-10-01 0:00', '2012-10-02 0:00', [
[ '2012-10-01 07:22', '2012-10-01 19:00', false, 'Beware of sunburn!' ],
], 1000 * 60 * (60 * 11 + 38), 0, false, nominatim_default, 'not only test');
test.addTest('Variable times calculation without coordinates', [
'(sunrise+01:02)-(sunset-00:30)',
], '2012-10-01 0:00', '2012-10-03 0:00', [
[ '2012-10-01 07:02', '2012-10-01 17:30' ],
[ '2012-10-02 07:02', '2012-10-02 17:30' ],
], 1000 * 60 * (60 * 10 + 28) * 2, 0, true, {}, 'not last test');
test.addTest('Variable times e.g. dawn, dusk without coordinates (→ constant times)', [
'dawn-dusk',
'(dawn+00:00)-dusk', // testing variable time calculation, should not change time
'dawn-(dusk-00:00)',
'(dawn+00:00)-(dusk-00:00)',
], '2012-10-01 0:00', '2012-10-03 0:00', [
[ '2012-10-01 05:30', '2012-10-01 18:30' ],
[ '2012-10-02 05:30', '2012-10-02 18:30' ],
], 1000 * 60 * 60 * 13 * 2, 0, true);
test.addTest('Variable times e.g. sunrise, sunset over a few days', [
'sunrise-sunset', // If your timezone uses daylight saving times you will see a difference of around one hours between two days.
'daylight', // Throws a warning.
], '2012-10-01 0:00', '2012-10-04 0:00', [
[ '2012-10-01 07:22', '2012-10-01 19:00' ],
[ '2012-10-02 07:23', '2012-10-02 18:58' ],
[ '2012-10-03 07:25', '2012-10-03 18:56' ],
], 1000 * 60 * ((60 * 11 + 38) + (60 * 11 + 37 - 2) + (60 * 11 + 35 - 4)), 0, false, nominatim_default, 'not only test');
test.addTest('Variable times calculation with coordinates', [
'(sunrise+02:00)-sunset',
], '2012-10-01 0:00', '2012-10-04 0:00', [
[ '2012-10-01 09:22', '2012-10-01 19:00' ],
[ '2012-10-02 09:23', '2012-10-02 18:58' ],
[ '2012-10-03 09:25', '2012-10-03 18:56' ],
], 1000 * 60 * ((60 * 11 + 38) + (60 * 11 + 37 - 2) + (60 * 11 + 35 - 4) - 60 * 2 * 3), 0, false, nominatim_default, 'not last test');
test.addTest('Variable times which moves over fix end time', [
'sunrise-08:02',
], '2013-01-26 0:00', '2013-02-03 0:00', [
// [ '2013-01-26 08:03', '2013-01-26 08:02' ], // Ignored because it would be interpreted as time range spanning midnight
// [ '2013-01-27 08:02', '2013-01-27 08:02' ], // which is probably not what you want.
[ '2013-01-28 08:00', '2013-01-28 08:02' ],
[ '2013-01-29 07:59', '2013-01-29 08:02' ],
[ '2013-01-30 07:58', '2013-01-30 08:02' ],
[ '2013-01-31 07:56', '2013-01-31 08:02' ],
[ '2013-02-01 07:55', '2013-02-01 08:02' ],
[ '2013-02-02 07:54', '2013-02-02 08:02' ],
], 1000 * 60 * (6 * 2 + 1 + 2 + 4 + 5 + 6), 0, false, nominatim_default);
test.addTest('Variable times which moves over fix end time', [
'sunrise-08:00',
], '2013-01-26 0:00', '2013-02-03 0:00', [
[ '2013-01-29 07:59', '2013-01-29 08:00' ],
[ '2013-01-30 07:58', '2013-01-30 08:00' ],
[ '2013-01-31 07:56', '2013-01-31 08:00' ],
[ '2013-02-01 07:55', '2013-02-01 08:00' ],
[ '2013-02-02 07:54', '2013-02-02 08:00' ],
], 1000 * 60 * (1 + 2 + 4 + 5 + 6), 0, false, nominatim_default);
test.addTest('Variable times which moves over fix end time', [
'sunrise-07:58',
], '2013-01-26 0:00', '2013-02-03 0:00', [
[ '2013-01-31 07:56', '2013-01-31 07:58' ],
[ '2013-02-01 07:55', '2013-02-01 07:58' ],
[ '2013-02-02 07:54', '2013-02-02 07:58' ],
], 1000 * 60 * (2 + 3 + 4), 0, false, nominatim_default);
test.addTest('Variable times which moves over fix end time', [
'sunrise-06:00',
], '2013-01-26 0:00', '2013-02-03 0:00', [
// Not open in range. Constant sunrise <= end time < from time
], 0, 0, false, nominatim_default);
test.addTest('Variable times which moves over fix end time', [
'sunrise-05:59', // end time < constant time < from time
], '2013-01-26 0:00', '2013-01-28 0:00', [
[ '2013-01-26 00:00', '2013-01-26 05:59' ],
[ '2013-01-26 08:02', '2013-01-27 05:59' ],
[ '2013-01-27 08:00', '2013-01-28 00:00' ],
], 1000 * 60 * ((60 * 5 + 59) + (60 * 22 - 3) + (60 * 16)), 0, false, nominatim_default, 'not last test');
test.addTest('Variable times which moves over fix end time', [
'sunrise-06:00', // from time < constant time <= end time
], '2013-04-15 0:00', '2013-04-19 0:00', [
[ '2013-04-17 05:59', '2013-04-17 06:00' ],
[ '2013-04-18 05:56', '2013-04-18 06:00' ],
], 1000 * 60 * (1 + 4), 0, false, nominatim_sunrise_below);
test.addTest('Variable times which moves over fix end time', [
ignored('sunrise-05:59'), // from time < end time <= constant time
], '2013-04-13 0:00', '2013-04-19 0:00', [
[ 'something else', '' ],
], 1000 * 60 * 3, 0, false, nominatim_sunrise_below, 'not last test');
test.addTest('Variable times spanning midnight', [
'sunset-sunrise',
'Mo-Su sunset-sunrise',
], '2012-10-01 0:00', '2012-10-03 0:00', [
[ '2012-10-01 00:00', '2012-10-01 07:22' ],
[ '2012-10-01 19:00', '2012-10-02 07:23' ],
[ '2012-10-02 18:58', '2012-10-03 00:00' ],
], 1000 * 60 * ((60 * 7 + 22) + (60 * (5 + 7) + 23) + (60 * 5 + 2)), 0, false, nominatim_default, 'not last test');
test.addTest('Variable times spanning midnight', [
'sunset-sunrise',
'Mo-Su sunset-sunrise',
// '19:00-07:22 Mo-Su', // also works but is week stable
'Mo-Su sunset-07:22',
'Mo-Su 19:00-sunrise',
], '2012-10-01 0:00', '2012-10-02 0:00', [
[ '2012-10-01 00:00', '2012-10-01 07:22' ],
[ '2012-10-01 19:00', '2012-10-02 00:00' ],
], 1000 * 60 * ((60 * 7 + 22) + (60 * 5)), 0, false, nominatim_default, 'not last test');
// }}}
// holidays {{{
/* Germany {{{ */
test.addTest('Variable days: public holidays', [
'PH',
'holiday', // Throws a warning.
'holidays', // Throws a warning.
'public holidays', // Throws a warning.
'public holiday', // Throws a warning.
], '2013-01-01 0:00', '2015-01-01 0:00', [
[ '2013-01-01 00:00', '2013-01-02 00:00', false, 'Neujahrstag' ],
[ '2013-01-06 00:00', '2013-01-07 00:00', false, 'Heilige Drei Könige' ],
[ '2013-03-29 00:00', '2013-03-30 00:00', false, 'Karfreitag' ],
[ '2013-04-01 00:00', '2013-04-02 00:00', false, 'Ostermontag' ],
[ '2013-05-01 00:00', '2013-05-02 00:00', false, 'Tag der Arbeit' ],
[ '2013-05-09 00:00', '2013-05-10 00:00', false, 'Christi Himmelfahrt' ],
[ '2013-05-20 00:00', '2013-05-21 00:00', false, 'Pfingstmontag' ],
[ '2013-05-30 00:00', '2013-05-31 00:00', false, 'Fronleichnam' ],
[ '2013-10-03 00:00', '2013-10-04 00:00', false, 'Tag der Deutschen Einheit' ],
[ '2013-11-01 00:00', '2013-11-02 00:00', false, 'Allerheiligen' ],
[ '2013-12-25 00:00', '2013-12-26 00:00', false, '1. Weihnachtstag' ],
[ '2013-12-26 00:00', '2013-12-27 00:00', false, '2. Weihnachtstag' ],
[ '2014-01-01 00:00', '2014-01-02 00:00', false, 'Neujahrstag' ],
[ '2014-01-06 00:00', '2014-01-07 00:00', false, 'Heilige Drei Könige' ],
[ '2014-04-18 00:00', '2014-04-19 00:00', false, 'Karfreitag' ],
[ '2014-04-21 00:00', '2014-04-22 00:00', false, 'Ostermontag' ],
[ '2014-05-01 00:00', '2014-05-02 00:00', false, 'Tag der Arbeit' ],
[ '2014-05-29 00:00', '2014-05-30 00:00', false, 'Christi Himmelfahrt' ],
[ '2014-06-09 00:00', '2014-06-10 00:00', false, 'Pfingstmontag' ],
[ '2014-06-19 00:00', '2014-06-20 00:00', false, 'Fronleichnam' ],
[ '2014-10-03 00:00', '2014-10-04 00:00', false, 'Tag der Deutschen Einheit' ],
[ '2014-11-01 00:00', '2014-11-02 00:00', false, 'Allerheiligen' ],
[ '2014-12-25 00:00', '2014-12-26 00:00', false, '1. Weihnachtstag' ],
[ '2014-12-26 00:00', '2014-12-27 00:00', false, '2. Weihnachtstag' ],
], 1000 * 60 * 60 * 24 * (20 + 2 * 2), 0, false, nominatim_default, 'not only test');
// http://www.schulferien.org/Kalender_mit_Ferien/kalender_2014_ferien_Baden_Wuerttemberg.html
test.addTest('Variable days: school holidays', [
'SH',
], '2014-01-01 0:00', '2015-02-01 0:00', [
[ '2014-01-01 00:00', '2014-01-05 00:00', false, 'Weihnachtsferien' ],
[ '2014-04-14 00:00', '2014-04-26 00:00', false, 'Osterferien' ],
[ '2014-06-10 00:00', '2014-06-22 00:00', false, 'Pfingstferien' ],
[ '2014-07-31 00:00', '2014-09-14 00:00', false, 'Sommerferien' ],
[ '2014-10-27 00:00', '2014-10-31 00:00', false, 'Herbstferien' ],
[ '2014-12-22 00:00', '2015-01-06 00:00', false, 'Weihnachtsferien' ],
], 1000 * 60 * 60 * 24 * (4 + 12 + 12 + 1 + 31 + 13 + 4 + 15), 0, false, nominatim_default, 'not only test');
// http://www.schulferien.org/Kalender_mit_Ferien/kalender_2015_ferien_Baden_Wuerttemberg.html
// https://github.com/opening-hours/opening_hours.js/issues/83
test.addTest('Variable days: school holidays', [
'SH',
], '2015-01-05 1:00', '2015-01-05 5:00', [
[ '2015-01-05 01:00', '2015-01-05 05:00', false, 'Weihnachtsferien' ],
], 1000 * 60 * 60 * 4, 0, false, nominatim_default, 'not only test');
test.addTest('Variable days: Germany school holidays', [
'SH',
], '2014-01-01 0:00', '2015-01-10 0:00', [
[ '2014-01-01 00:00', '2014-01-04 00:00', false, 'Weihnachtsferien' ], // 3
[ '2014-01-30 00:00', '2014-02-01 00:00', false, 'Winterferien' ], // 2
[ '2014-04-03 00:00', '2014-04-23 00:00', false, 'Osterferien' ], // 20
[ '2014-05-02 00:00', '2014-05-03 00:00', false, 'Osterferien' ], // 1
[ '2014-05-30 00:00', '2014-05-31 00:00', false, 'Pfingstferien' ], // 1
[ '2014-06-10 00:00', '2014-06-11 00:00', false, 'Pfingstferien' ], // 1
[ '2014-07-31 00:00', '2014-09-11 00:00', false, 'Sommerferien' ], // 1 + 31 + 10
[ '2014-10-27 00:00', '2014-11-09 00:00', false, 'Herbstferien' ], // 5 + 8
[ '2014-12-22 00:00', '2015-01-06 00:00', false, 'Weihnachtsferien' ], // 10 + 5
], 1000 * 60 * 60 * 24 * (3 + 2 + 20 + 1 + 1 + 1 + (1 + 31 + 10) + (5 + 8) + (10 + 5)), 0, false, nominatim_by_loc.de_hb, 'not last test');
test.addTest('Variable days: Germany school holidays. Rheinland-Pfalz', [
'SH',
], '2016-01-10 0:00', '2023-12-30 0:00', [
[ '2016-03-18 00:00', '2016-04-02 00:00', false, 'Osterferien' ],
[ '2016-07-18 00:00', '2016-08-27 00:00', false, 'Sommerferien' ],
[ '2016-10-10 00:00', '2016-10-22 00:00', false, 'Herbstferien' ],
[ '2016-12-22 00:00', '2017-01-07 00:00', false, 'Weihnachtsferien' ],
[ '2017-04-10 00:00', '2017-04-22 00:00', false, 'Osterferien' ],
[ '2017-07-03 00:00', '2017-08-12 00:00', false, 'Sommerferien' ],
[ '2017-10-02 00:00', '2017-10-14 00:00', false, 'Herbstferien' ],
[ '2017-12-22 00:00', '2018-01-10 00:00', false, 'Weihnachtsferien' ],
[ '2018-03-26 00:00', '2018-04-07 00:00', false, 'Osterferien' ],
[ '2018-06-25 00:00', '2018-08-04 00:00', false, 'Sommerferien' ],
[ '2018-10-01 00:00', '2018-10-13 00:00', false, 'Herbstferien' ],
[ '2018-12-20 00:00', '2019-01-05 00:00', false, 'Weihnachtsferien' ],
[ '2019-02-25 00:00', '2019-03-02 00:00', false, 'Winterferien' ],
[ '2019-04-23 00:00', '2019-05-01 00:00', false, 'Osterferien' ],
[ '2019-07-01 00:00', '2019-08-10 00:00', false, 'Sommerferien' ],
[ '2019-09-30 00:00', '2019-10-12 00:00', false, 'Herbstferien' ],
[ '2019-12-23 00:00', '2020-01-07 00:00', false, 'Weihnachtsferien' ],
[ '2020-02-17 00:00', '2020-02-22 00:00', false, 'Winterferien' ],
[ '2020-04-09 00:00', '2020-04-18 00:00', false, 'Osterferien' ],
[ '2020-07-06 00:00', '2020-08-15 00:00', false, 'Sommerferien' ],
[ '2020-10-12 00:00', '2020-10-24 00:00', false, 'Herbstferien' ],
[ '2020-12-21 00:00', '2021-01-01 00:00', false, 'Weihnachtsferien' ],
[ '2021-03-29 00:00', '2021-04-07 00:00', false, 'Osterferien' ],
[ '2021-05-25 00:00', '2021-06-03 00:00', false, 'Pfingstferien' ],
[ '2021-07-19 00:00', '2021-08-28 00:00', false, 'Sommerferien' ],
[ '2021-10-11 00:00', '2021-10-23 00:00', false, 'Herbstferien' ],
[ '2021-12-23 00:00', '2022-01-01 00:00', false, 'Weihnachtsferien' ],
[ '2022-02-21 00:00', '2022-02-26 00:00', false, 'Winterferien' ],
[ '2022-04-13 00:00', '2022-04-23 00:00', false, 'Osterferien' ],
[ '2022-07-25 00:00', '2022-09-03 00:00', false, 'Sommerferien' ],
[ '2022-10-17 00:00', '2022-11-01 00:00', false, 'Herbstferien' ],
[ '2022-12-23 00:00', '2023-01-03 00:00', false, 'Weihnachtsferien' ],
[ '2023-04-03 00:00', '2023-04-07 00:00', false, 'Osterferien' ],
[ '2023-05-30 00:00', '2023-06-08 00:00', false, 'Pfingstferien' ],
[ '2023-07-24 00:00', '2023-09-02 00:00', false, 'Sommerferien' ],
[ '2023-10-16 00:00', '2023-10-28 00:00', false, 'Herbstferien' ],
[ '2023-12-27 00:00', '2023-12-30 00:00', false, 'Weihnachtsferien' ],
], 54518400000, 0, false, nominatim_by_loc.de_rp, 'not only test');
/* }}} */
/* Holidays combined with other features {{{ */
test.addTest('Variable days: public holidays', [
'open; PH off',
// 'PH off; 24/7', // should not be the same if following the rules
], '2013-04-01 0:00', '2013-05-11 0:00', [
[ '2013-04-02 00:00', '2013-05-01 00:00' ],
[ '2013-05-02 00:00', '2013-05-09 00:00' ],
[ '2013-05-10 00:00', '2013-05-11 00:00' ],
], 1000 * 60 * 60 * 24 * (30 - 1 + 7 + 1), 0, false, nominatim_default, 'not last test');
test.addTest('Variable days: public holidays (with time range)', [
'PH 12:00-13:00',
], '2012-01-01 0:00', '2012-04-01 0:00', [
[ '2012-01-01 12:00', '2012-01-01 13:00', false, 'Neujahrstag' ],
[ '2012-01-06 12:00', '2012-01-06 13:00', false, 'Heilige Drei Könige' ],
], 1000 * 60 * 60 * 2, 0, false, nominatim_default, 'not last test');
test.addTest('Variable days: public holidays (with time range)', [
'PH 12:00-13:00 open "this comment should override the holiday name which is returned as comment if PH matches."',
], '2012-01-01 0:00', '2012-04-01 0:00', [
[ '2012-01-01 12:00', '2012-01-01 13:00', false, 'this comment should override the holiday name which is returned as comment if PH matches.' ],
[ '2012-01-06 12:00', '2012-01-06 13:00', false, 'this comment should override the holiday name which is returned as comment if PH matches.' ],
], 1000 * 60 * 60 * 2, 0, false, nominatim_default, 'not last test');
test.addTest('PH: Only if PH is Wednesday', [
'PH We,Fr',
'PH: We,Fr', // Please don’t use ":" after holiday.
' We,Fr: PH', // Please don’t use ":" after holiday.
], '2012-01-01 0:00', '2012-10-08 0:00', [
[ '2012-01-06 00:00', '2012-01-07 00:00', false, 'Heilige Drei Könige' ], // Fr
[ '2012-04-06 00:00', '2012-04-07 00:00', false, 'Karfreitag' ], // Fr
[ '2012-10-03 00:00', '2012-10-04 00:00', false, 'Tag der Deutschen Einheit' ], // We
], 1000 * 60 * 60 * 24 * 3, 0, false, nominatim_default, 'not only test');
test.addTest('SH', [
'SH Mo-Fr',
'Schulferien Mo-Fr',
'Ferien Mo-Fr',
'schoolholiday Mo-Fr',
'school holiday Mo-Fr',
'school holidays Mo-Fr',
'SH: Mo-Fr', // Please don’t use ":" after holiday.
'SH on work day',
'SH on work days',
], '2012-12-22 0:00', '2013-01-08 0:00', [
[ '2012-12-24 00:00', '2012-12-29 00:00', false, 'Weihnachtsferien' ],
[ '2012-12-31 00:00', '2013-01-05 00:00', false, 'Weihnachtsferien' ],
], 1000 * 60 * 60 * 24 * (5 * 2), 0, false, nominatim_default, 'not only test');
test.addTest('SH', [
'SH Mo-Fr',
], '2012-12-22 0:00', '2013-01-08 0:00', [
[ '2012-12-24 00:00', '2012-12-29 00:00', false, 'Weihnachtsferien' ],
[ '2012-12-31 00:00', '2013-01-05 00:00', false, 'Weihnachtsferien' ],
], 1000 * 60 * 60 * 24 * (5 * 2), 0, false, null, 'not only test');
test.addTest('Variable days: public holidays', [
'PH +1 day',
'day after public holiday',
'one day after public holiday',
], '2014-10-22 0:00', '2015-01-15 0:00', [
[ '2014-11-02 00:00', '2014-11-03 00:00', false, 'Day after Allerheiligen' ],
[ '2014-12-26 00:00', '2014-12-27 00:00', false, 'Day after 1. Weihnachtstag' ],
[ '2014-12-27 00:00', '2014-12-28 00:00', false, 'Day after 2. Weihnachtstag' ],
[ '2015-01-02 00:00', '2015-01-03 00:00', false, 'Day after Neujahrstag' ],
[ '2015-01-07 00:00', '2015-01-08 00:00', false, 'Day after Heilige Drei Könige' ],
], 1000 * 60 * 60 * 24 * (3 + 2), 0, false, nominatim_default, 'not last test');
test.addTest('Variable days: public holidays', [
'PH -1 day Mo-We',
'Mo-We PH -1 day',
'day before public holiday Mo-We',
'one day before public holiday Mo-We',
], '2014-10-25 0:00', '2015-01-15 0:00', [
// [ '2014-10-31 00:00', '2014-11-01 00:00', false, 'Day before Allerheiligen' ], // 31: Fr
[ '2014-12-24 00:00', '2014-12-25 00:00', false, 'Day before 1. Weihnachtstag' ], // 24: We
// [ '2014-12-25 00:00', '2014-12-26 00:00', false, 'Day before 2. Weihnachtstag' ], // 25: Th
[ '2014-12-31 00:00', '2015-01-01 00:00', false, 'Day before Neujahrstag' ], // 31: We
[ '2015-01-05 00:00', '2015-01-06 00:00', false, 'Day before Heilige Drei Könige' ], // 05: Mo
], 1000 * 60 * 60 * 24 * 3, 0, false, nominatim_default, 'not last test');
// FIXME
test.addTest('Variable days: public holidays', [
'SH PH -1 day Mo-We',
'PH -1 day SH Mo-We',
], '2014-10-25 0:00', '2015-01-15 0:00', [
// [ '2014-10-31 00:00', '2014-11-01 00:00', false, 'Day before Allerheiligen' ], // 31: Fr
[ '2014-12-24 00:00', '2014-12-25 00:00', false, 'Day before 1. Weihnachtstag' ], // 24: We
// [ '2014-12-25 00:00', '2014-12-26 00:00', false, 'Day before 2. Weihnachtstag' ], // 25: Th
[ '2014-12-31 00:00', '2015-01-01 00:00', false, 'Day before Neujahrstag' ], // 31: We
[ '2015-01-05 00:00', '2015-01-06 00:00', false, 'Day before Heilige Drei Könige' ], // 05: Mo
], 1000 * 60 * 60 * 24 * 3, 0, false, nominatim_default, 'not last test');
test.addTest('Variable days: public holidays', [
'PH -1 day',
'PH-1day',
'day before public holiday',
'one day before public holiday',
], '2014-10-25 0:00', '2015-01-15 0:00', [
// [ '2014-11-01 00:00', '2014-11-02 00:00' ],
// [ '2014-12-25 00:00', '2014-12-27 00:00' ],
[ '2014-10-31 00:00', '2014-11-01 00:00', false, 'Day before Allerheiligen' ],
[ '2014-12-24 00:00', '2014-12-25 00:00', false, 'Day before 1. Weihnachtstag' ],
[ '2014-12-25 00:00', '2014-12-26 00:00', false, 'Day before 2. Weihnachtstag' ],
[ '2014-12-31 00:00', '2015-01-01 00:00', false, 'Day before Neujahrstag' ],
[ '2015-01-05 00:00', '2015-01-06 00:00', false, 'Day before Heilige Drei Könige' ],
], 1000 * 60 * 60 * 24 * (3 + 2), 0, false, nominatim_default, 'not last test');
test.addTest('Variable days: school holiday', [
'open; SH off',
], '2014-01-01 0:00', '2014-06-15 0:00', [
[ '2014-01-05 00:00', '2014-04-14 00:00' ],
[ '2014-04-26 00:00', '2014-06-10 00:00' ],
], 1000 * 60 * 60 * 24 * (31 - 5 + 28 + 31 + 14 + 4 + 31 + 10) -(/* daylight saving time CEST */ 1000 * 60 * 60),
0, false, nominatim_default, 'not last test');
test.addTest('SH: Only if SH is Wednesday', [
'SH We',
'SHWe',
'2014 SH We',
], '2014-01-01 0:00', '2014-05-10 0:00', [
[ '2014-01-01 00:00', '2014-01-02 00:00', false, 'Weihnachtsferien' ],
[ '2014-04-16 00:00', '2014-04-17 00:00', false, 'Osterferien' ],
[ '2014-04-23 00:00', '2014-04-24 00:00', false, 'Osterferien' ],
], 1000 * 60 * 60 * 24 * 3, 0, false, nominatim_default, 'not only test');
test.addTest('Variable days: school holidays', [
'SH,PH',
'2014 SH,PH',
'Jan-Feb SH,PH',
// 'PH,SH', // Note that later holidays override the comment for the first holidays.
], '2014-01-01 0:00', '2014-02-15 0:00', [
[ '2014-01-01 00:00', '2014-01-02 00:00', false, 'Neujahrstag' ],
[ '2014-01-02 00:00', '2014-01-05 00:00', false, 'Weihnachtsferien' ],
[ '2014-01-06 00:00', '2014-01-07 00:00', false, 'Heilige Drei Könige' ],
], 1000 * 60 * 60 * 24 * (4 + 1), 0, false, nominatim_default, 'not last test');
test.addTest('Variable days: school holidays', [
'Su,SH,PH',
'SH,Su,PH',
'SH,PH,Su',
'PH,Su,SH',
ignored('SH,Sonntag und an Feiertagen', 'prettifyValue'),
ignored('SH,Sonn und Feiertag', 'prettifyValue'),
ignored('SH,Sonn und Feiertags', 'prettifyValue'),
ignored('SH,Sonn- und Feiertags', 'prettifyValue'),
ignored('SH,Sonn- und Feiertage', 'prettifyValue'),
ignored('SH,Sonn-/Feiertag', 'prettifyValue'),
ignored('SH,Sonn-/Feiertags', 'prettifyValue'),
ignored('SH und nur Sonn-/Feiertags', 'prettifyValue'),
ignored('SH und Sonn-/Feiertags', 'prettifyValue'),
ignored('SH und an Sonn- und Feiertagen', 'prettifyValue'),
], '2014-01-01 0:00', '2014-02-15 0:00', [
[ '2014-01-01 00:00', '2014-01-02 00:00', false, 'Neujahrstag' ],
[ '2014-01-02 00:00', '2014-01-05 00:00', false, 'Weihnachtsferien' ],
[ '2014-01-05 00:00', '2014-01-06 00:00' ],
[ '2014-01-06 00:00', '2014-01-07 00:00', false, 'Heilige Drei Könige' ],
[ '2014-01-12 00:00', '2014-01-13 00:00' ],
[ '2014-01-19 00:00', '2014-01-20 00:00' ],
[ '2014-01-26 00:00', '2014-01-27 00:00' ],
[ '2014-02-02 00:00', '2014-02-03 00:00' ],
[ '2014-02-09 00:00', '2014-02-10 00:00' ],
], 1000 * 60 * 60 * 24 * (4 + 1 + 6), 0, false, nominatim_default, 'not only test');
test.addTest('Variable days: Everyday including public holidays', [
'Mo-Su,PH',
'PH,Mo-Su',