Skip to content

Commit dd42a58

Browse files
Merge branch 'develop' into master
2 parents f9d388c + 7e5ca62 commit dd42a58

28 files changed

+4430
-3098
lines changed
File renamed without changes.

CONTRIBUTING.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,13 @@ Thank you for contributing!
105105
[i18next]: https://www.i18next.com
106106
[Vim folds]: https://vimhelp.org/fold.txt.html#folding
107107

108-
[ohlib.opening_hours.js]: /index.js
108+
[opening_hours_map]: https://github.com/opening-hours/opening_hours_map
109+
[ohlib.docs.holiday]: /holidays/README.md
110+
[ohlib.holidays]: README.md#holidays
109111
[ohlib.js/locales/opening_hours_resources.yaml]: src/locales/opening_hours_resources.yaml
110112
[ohlib.js/i18n-resources.js]: site/js/i18n-resources.js
111-
[site/index.html]: site/index.html
113+
[ohlib.makefile]: /Makefile
114+
[ohlib.opening_hours.js]: /index.js
112115
[ohlib.test.js]: test/test.js
113116
[ohlib.testing]: README.md#testing
117+
[site/index.html]: site/index.html

README.md

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,7 @@ An around-the-clock shop with some breaks.
105105
- [Related links](#related-links)
106106
- [ToDo](#todo)
107107
- [How to contribute](#how-to-contribute)
108-
- [Translating the evaluation tool and the map](#translating-the-evaluation-tool-and-the-map)
109-
- [Translating error messages and warnings](#translating-error-messages-and-warnings)
110-
- [Holiday Data](#holiday-data)
111-
- [Core code](#core-code)
112-
- [Commit hooks](#commit-hooks)
113-
- [Documentation](#documentation)
114-
- [Authors](#authors)
108+
- [Maintainers](#maintainers)
115109
- [Contributors](#contributors)
116110
- [Credits](#credits)
117111
- [Stats](#stats)
@@ -188,15 +182,15 @@ Check [releases on GitHub] for a list of the releases and their Changelog.
188182

189183
```js
190184
const opening_hours = require("opening_hours");
191-
var oh = new opening_hours("We 12:00-14:00");
185+
let oh = new opening_hours("We 12:00-14:00");
192186

193-
var from = new Date("01 Jan 2012");
194-
var to = new Date("01 Feb 2012");
187+
let from = new Date("01 Jan 2012");
188+
let to = new Date("01 Feb 2012");
195189

196190
// high-level API
197191
{
198-
var intervals = oh.getOpenIntervals(from, to);
199-
for (var i in intervals)
192+
let intervals = oh.getOpenIntervals(from, to);
193+
for (let i in intervals)
200194
console.log(
201195
"We are " +
202196
(intervals[i][2] ? "maybe " : "") +
@@ -208,7 +202,7 @@ var to = new Date("01 Feb 2012");
208202
"."
209203
);
210204

211-
var duration_hours = oh.getOpenDuration(from, to).map(function (x) {
205+
let duration_hours = oh.getOpenDuration(from, to).map(function (x) {
212206
return x / 1000 / 60 / 60;
213207
});
214208
if (duration_hours[0])
@@ -228,7 +222,7 @@ function getReadableState(startString, endString, oh, past) {
228222
if (past === true) past = "d";
229223
else past = "";
230224

231-
var output = "";
225+
let output = "";
232226
if (oh.getUnknown()) {
233227
output +=
234228
" maybe open" +
@@ -246,10 +240,10 @@ function getReadableState(startString, endString, oh, past) {
246240

247241
// simple API
248242
{
249-
var state = oh.getState(); // we use current date
250-
var unknown = oh.getUnknown();
251-
var comment = oh.getComment();
252-
var nextchange = oh.getNextChange();
243+
let state = oh.getState(); // we use current date
244+
let unknown = oh.getUnknown();
245+
let comment = oh.getComment();
246+
let nextchange = oh.getNextChange();
253247

254248
console.log(getReadableState("We're", "", oh, true));
255249

@@ -267,7 +261,7 @@ function getReadableState(startString, endString, oh, past) {
267261

268262
// iterator API
269263
{
270-
var iterator = oh.getIterator(from);
264+
let iterator = oh.getIterator(from);
271265

272266
console.log(getReadableState("Initially, we're", "", iterator, true));
273267

@@ -283,7 +277,7 @@ function getReadableState(startString, endString, oh, past) {
283277

284278
## Library API
285279

286-
- `var oh = new opening_hours('We 12:00-14:00', nominatim_object, mode);`
280+
- `let oh = new opening_hours('We 12:00-14:00', nominatim_object, mode);`
287281

288282
- `value (mandatory, type: string)`: Constructs opening_hours object, given the opening_hours tag value. Throws an error string if the expression is malformed or unsupported.
289283

@@ -328,13 +322,13 @@ function getReadableState(startString, endString, oh, past) {
328322
329323
- additional_rule_separator (type boolean, default true)`: Allows to disable the "additional_rule_separator not used after time wrapping midnight" check giving rise to the warning "This rule overwrites parts of the previous rule. This happens because normal rules apply to the whole day and overwrite any definition made by previous rules. You can make this rule an additional rule by using a "," instead of the normal ";" to separate the rules. Note that the overwriting can also be desirable in which case you can ignore this warning."
330324
331-
- `var warnings = oh.getWarnings();`
325+
- `let warnings = oh.getWarnings();`
332326
333327
Get warnings which appeared during parsing as human readable string array with one element per violation. Almost all warnings can be auto-corrected and are probably interpreted as intended by the mapper. However, this is not a granite of course.
334328
335329
This function performs some additional testing and can thus also theoretically throw an error like all other functions which parse the time.
336330
337-
- `var prettified = oh.prettifyValue(argument_hash);`
331+
- `let prettified = oh.prettifyValue(argument_hash);`
338332
339333
Return a prettified version of the opening_hours value. The value is generated by putting the tokens back together to a string.
340334
@@ -355,11 +349,11 @@ function getReadableState(startString, endString, oh, past) {
355349

356350
If the key 'get_internals' is true then an object containing internal stuff will be returned instead. The format of this internal object may change in minor release.
357351

358-
- `var every_week_is_same = oh.isWeekStable();`
352+
- `let every_week_is_same = oh.isWeekStable();`
359353

360354
Checks whether open intervals are same for every week. Useful for giving a user hint whether time table may change for another week.
361355

362-
- `var is_equal_to = oh.isEqualTo(new opening_hours('We 12:00-16:00'), start_date);`
356+
- `let is_equal_to = oh.isEqualTo(new opening_hours('We 12:00-16:00'), start_date);`
363357

364358
Check if this opening_hours object has the same meaning as the given
365359
opening_hours object (evaluates to the same state for every given time).
@@ -391,51 +385,51 @@ function getReadableState(startString, endString, oh, past) {
391385

392386
This API is useful for one-shot checks, but for iteration over intervals you should use the more efficient [iterator API][ohlib.iterator-api].
393387

394-
- `var is_open = oh.getState(date);`
388+
- `let is_open = oh.getState(date);`
395389

396390
Checks whether the facility is open at the given *date*. You may omit *date* to use current date.
397391

398-
- `var unknown = oh.getUnknown(date);`
392+
- `let unknown = oh.getUnknown(date);`
399393

400394
Checks whether the opening state is conditional or unknown at the given *date*. You may omit *date* to use current date.
401395
Conditions can be expressed in comments.
402396
If unknown is true then is_open will be false since it is not sure if it is open.
403397

404-
- `var state_string = oh.getStateString(date, past);`
398+
- `let state_string = oh.getStateString(date, past);`
405399

406400
Return state string at given *date*. Either 'open', 'unknown' or 'closed?'. You may omit *date* to use current date.
407401

408402
If the boolean parameter `past` is true you will get 'closed' else you will get 'close'.
409403

410-
- `var comment = oh.getComment(date);`
404+
- `let comment = oh.getComment(date);`
411405

412406
Returns the comment (if one is specified) for the facility at the given *date*. You may omit *date* to use current date.
413407
Comments can be specified for any state.
414408

415409
If no comment is specified this function will return undefined.
416410

417-
- `var next_change = oh.getNextChange(date, limit);`
411+
- `let next_change = oh.getNextChange(date, limit);`
418412

419413
Returns date of next state change. You may omit *date* to use current date.
420414

421415
Returns undefined if the next change cannot be found. This may happen if the state won't ever change (e.g. `24/7`) or if search goes beyond *limit* (which is *date* + ~5 years if omitted).
422416

423-
- `var rule_index = oh.getMatchingRule(date);`
417+
- `let rule_index = oh.getMatchingRule(date);`
424418

425419
Returns the internal rule number of the matching rule. You may omit *date* to use current date.
426420
A opening_hours string can consist of multiple rules from which one of them is used to evaluate the state for a given point in time. If no rule applies, the state will be closed and this function returns undefined.
427421

428422
To prettify this rule, you can specify `rule_index` as parameter for `oh.prettifyValue` like this:
429423

430424
```js
431-
var matching_rule = oh.prettifyValue({ rule_index: rule_index });
425+
let matching_rule = oh.prettifyValue({ rule_index: rule_index });
432426
```
433427

434428
### High-level API
435429

436430
Here and below, unless noted otherwise, all arguments are expected to be and all output will be in the form of Date objects.
437431

438-
- `var intervals = oh.getOpenIntervals(from, to);`
432+
- `let intervals = oh.getOpenIntervals(from, to);`
439433

440434
Returns array of open intervals in a given range, in a form of
441435

@@ -445,49 +439,49 @@ Here and below, unless noted otherwise, all arguments are expected to be and all
445439

446440
Intervals are cropped with the input range.
447441

448-
- `var duration = oh.getOpenDuration(from, to);`
442+
- `let duration = oh.getOpenDuration(from, to);`
449443

450444
Returns an array with two durations for a given date range, in milliseconds. The first element is the duration for which the facility is open and the second is the duration for which the facility is maybe open (unknown is used).
451445

452446
### Iterator API
453447

454-
- `var iterator = oh.getIterator(date);`
448+
- `let iterator = oh.getIterator(date);`
455449

456450
Constructs an iterator which can go through open/close points, starting at *date*. You may omit *date* to use current date.
457451

458-
- `var current_date = iterator.getDate();`
452+
- `let current_date = iterator.getDate();`
459453

460454
Returns current iterator position.
461455

462456
- `iterator.setDate(date);`
463457

464458
Set iterator position to date.
465459

466-
- `var is_open = iterator.getState();`
460+
- `let is_open = iterator.getState();`
467461

468462
Returns whether the facility is open at the current iterator position.
469463

470-
- `var unknown = iterator.getUnknown();`
464+
- `let unknown = iterator.getUnknown();`
471465

472466
Checks whether the opening state is conditional or unknown at the current iterator position.
473467

474-
- `var state_string = iterator.getStateString(past);`
468+
- `let state_string = iterator.getStateString(past);`
475469

476470
Return state string. Either 'open', 'unknown' or 'closed?'.
477471

478472
If the boolean parameter `past` is true you will get 'closed' else you will get 'close'.
479473

480-
- `var comment = iterator.getComment();`
474+
- `let comment = iterator.getComment();`
481475

482476
Returns the comment (if one is specified) for the facility at the current iterator position in time.
483477

484478
If no comment is specified this function will return undefined.
485479

486-
- `var matching_rule = iterator.getMatchingRule();`
480+
- `let matching_rule = iterator.getMatchingRule();`
487481

488482
Returns the index of the matching rule starting with zero.
489483

490-
- `var had_advanced = iterator.advance(limit);`
484+
- `let had_advanced = iterator.advance(limit);`
491485

492486
Advances an iterator to the next position, but not further than *limit* (which is current position + ~5 years if omitted and is used to prevent infinite loop on non-periodic opening_hours, e.g. `24/7`), returns whether the iterator was moved.
493487

@@ -586,7 +580,7 @@ Almost everything from opening_hours definition is supported, as well as some ex
586580
- [Croatia][ph-hr]
587581
- [Czech Republic][ph-cz]
588582
- [Denmark][ph-dk]
589-
- [England and Wales][ph-gb]
583+
- [England, Wales, Scotland and Northern Ireland][ph-gb]
590584
- [France][ph-fr]
591585
- Finland
592586
- [Germany][ph-de] ([footnotes][ph-de] are ignored)
@@ -849,7 +843,7 @@ Note that the original work from Dmitry Marakasov is published under the BSD 2-c
849843

850844
<https://reuse.software> is used. The year of initial publication is used and not updated. When you as new author make copyrightable changes, you are free of course to add a `SPDX-FileCopyrightText` line to the file(s) you changed with the year of the contribution. Please use a format like this:
851845

852-
```
846+
```text
853847
SPDX-FileCopyrightText: © 2021 Humble Hacker <hh@example.org>
854848
```
855849

@@ -878,12 +872,9 @@ Edit: This does also work on npmjs in this short version … -->
878872
[ohlib.iterator-api]: #iterator-api
879873
[ohlib.time-ranges]: #time-ranges
880874
[ohlib.states]: #states
881-
[ohlib.holidays]: #holidays
882875
[ohlib.contribute.holidays]: /src/holidays/
883876
[ohlib.evaluation-tool]: #evaluation-tool
884877
[ohlib.library-api]: #library-api
885-
[ohlib.docs.holiday]: /holidays/README.md
886-
[ohlib.makefile]: /Makefile
887878
[ohlib.npmjs]: https://www.npmjs.org/package/opening_hours
888879
[ohlib.github]: https://github.com/opening-hours/opening_hours.js
889880
[hc]: https://gitlab.com/ypid/hc

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,6 @@ The most inner array represents one token:
168168
]
169169
```
170170

171-
# ToDo
171+
## ToDo
172172

173173
* Make implementation of weekday and holiday interaction clearer.

eslint.config.mjs

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,37 @@
1-
import eslint from '@eslint/js'
2-
import globals from "globals";
1+
import { defineConfig, globalIgnores } from 'eslint/config'
2+
import globals from 'globals'
3+
import js from '@eslint/js'
4+
import markdown from '@eslint/markdown'
5+
import stylistic from '@stylistic/eslint-plugin'
36
import tseslint from 'typescript-eslint'
47

5-
export default tseslint.config(
6-
eslint.configs.recommended,
8+
export default defineConfig([
9+
globalIgnores(['build/*', 'submodules/*', '**/yohours_model.js']),
710
{
8-
files: ['**/*.ts'],
9-
extends: [
10-
eslint.configs.recommended,
11-
tseslint.configs.recommended,
12-
],
13-
rules: {
14-
'@typescript-eslint/array-type': 'error',
15-
'@typescript-eslint/consistent-type-imports': 'error',
16-
},
17-
},
18-
{
19-
"files": ["**/*.js", "**/*.mjs"],
20-
"languageOptions": {
21-
"ecmaVersion": "latest",
22-
"globals": {
11+
files: ['**/*.js', '**/*.mjs'],
12+
extends: [js.configs.recommended],
13+
plugins: { '@stylistic': stylistic },
14+
languageOptions: {
15+
ecmaVersion: 'latest',
16+
globals: {
2317
...globals.browser,
24-
...globals.node
18+
...globals.node,
2519
},
26-
"sourceType": "module"
20+
sourceType: 'module',
2721
},
2822
rules: {
29-
'no-cond-assign': 'warn',
30-
'no-constant-binary-expression': 'warn',
31-
'no-empty': 'warn',
32-
'no-empty-function': 'warn',
33-
'no-func-assign': 'warn',
34-
'no-prototype-builtins': 'warn',
35-
'no-redeclare': 'warn',
36-
'no-undef': 'warn',
37-
'no-unused-vars': 'warn',
38-
'no-useless-escape': 'warn',
39-
}
23+
'@stylistic/quotes': [ 'error', 'single' ],
24+
'prefer-const': 'error',
25+
'no-var': 'error'
26+
},
4027
},
28+
{ files: ['**/*.md'], plugins: { markdown }, language: 'markdown/gfm', extends: ['markdown/recommended'] },
4129
{
42-
ignores: ['build/*', 'submodules/*', '**/yohours_model.js']
43-
}
44-
)
30+
files: ['**/*.ts'],
31+
extends: [tseslint.configs.recommended],
32+
rules: {
33+
'@typescript-eslint/array-type': 'error',
34+
'@typescript-eslint/consistent-type-imports': 'error',
35+
},
36+
},
37+
])

0 commit comments

Comments
 (0)