opening_hours 3.8.0 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.rst +65 -6
- package/LICENSES/AGPL-3.0-only.txt +149 -517
- package/LICENSES/CC0-1.0.txt +121 -0
- package/LICENSES/LGPL-3.0-only.txt +304 -0
- package/Makefile +28 -32
- package/README.md +55 -27
- package/build/opening_hours.js +4491 -2277
- package/package.json +43 -31
- package/site/js/helpers.js +17 -11
- package/site/js/i18n-resources.js +211 -60
- package/site/js/opening_hours_table.js +121 -114
- package/types/index.d.ts +3 -3
|
@@ -1,44 +1,54 @@
|
|
|
1
|
+
/* global i18next */
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line no-unused-vars
|
|
1
4
|
var OpeningHoursTable = {
|
|
2
5
|
|
|
3
6
|
// JS functions for generating the table {{{
|
|
4
7
|
// In English. Localization is done somewhere else (above).
|
|
5
|
-
months: ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'],
|
|
6
|
-
weekdays: ['su','mo','tu','we','th','fr','sa'],
|
|
8
|
+
months: ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'],
|
|
9
|
+
weekdays: ['su', 'mo', 'tu', 'we', 'th', 'fr', 'sa'],
|
|
7
10
|
|
|
8
|
-
formatdate
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
formatdate (now, nextchange, from) {
|
|
12
|
+
const now_daystart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
13
|
+
const nextdays = (nextchange.getTime() - now_daystart.getTime()) / 1000 / 60 / 60 / 24;
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
let timediff = '';
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
if (delta < 60)
|
|
16
|
-
timediff = i18next.t(
|
|
17
|
+
let delta = Math.floor((nextchange.getTime() - now.getTime()) / 1000 / 60); // delta is minutes
|
|
18
|
+
if (delta < 60) {
|
|
19
|
+
timediff = `${i18next.t('words.in duration')} ${delta} ${this.plural(delta, 'words.time.minute')}`;
|
|
20
|
+
}
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
const deltaminutes = delta % 60;
|
|
19
23
|
delta = Math.floor(delta / 60); // delta is now hours
|
|
20
24
|
|
|
21
|
-
if (delta < 48 && timediff === '')
|
|
22
|
-
timediff =
|
|
23
|
-
|
|
25
|
+
if (delta < 48 && timediff === '') {
|
|
26
|
+
timediff =
|
|
27
|
+
`${i18next.t('words.in duration')} `
|
|
28
|
+
+ `${delta} `
|
|
29
|
+
+ `${this.plural(delta, 'words.time.hour')} `
|
|
30
|
+
+ `${i18next.t('words.time.hours minutes sep')}`
|
|
31
|
+
+ `${this.pad(deltaminutes)} `
|
|
32
|
+
+ `${this.plural(deltaminutes, 'words.time.minute')}`;
|
|
33
|
+
}
|
|
24
34
|
|
|
25
|
-
|
|
35
|
+
const deltahours = delta % 24;
|
|
26
36
|
delta = Math.floor(delta / 24); // delta is now days
|
|
27
37
|
|
|
28
|
-
if (delta < 14 && timediff === '')
|
|
29
|
-
timediff = i18next.t(
|
|
30
|
-
|
|
31
|
-
else if (timediff === '')
|
|
32
|
-
timediff = i18next.t(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (from ? (nextdays < 1) : (nextdays <= 1))
|
|
38
|
+
if (delta < 14 && timediff === '') {
|
|
39
|
+
timediff = `${i18next.t('words.in duration')} ${delta} ${this.plural(delta, 'words.time.day')
|
|
40
|
+
} ${deltahours} ${this.plural(deltahours, 'words.time.hour')}`;
|
|
41
|
+
} else if (timediff === '') {
|
|
42
|
+
timediff = `${i18next.t('words.in duration')} ${delta} ${this.plural(delta, 'words.time.day')}`;
|
|
43
|
+
}
|
|
44
|
+
let atday = '';
|
|
45
|
+
if (from ? (nextdays < 1) : (nextdays <= 1)) {
|
|
36
46
|
atday = i18next.t('words.today');
|
|
37
|
-
else if (from ? (nextdays < 2) : (nextdays <= 2))
|
|
47
|
+
} else if (from ? (nextdays < 2) : (nextdays <= 2)) {
|
|
38
48
|
atday = i18next.t('words.tomorrow');
|
|
39
|
-
else if (from ? (nextdays < 7) : (nextdays <= 7)) {
|
|
40
|
-
if (i18next.exists(
|
|
41
|
-
atday = i18next.t(
|
|
49
|
+
} else if (from ? (nextdays < 7) : (nextdays <= 7)) {
|
|
50
|
+
if (i18next.exists(`weekdays.days next week.${this.weekdays[nextchange.getDay()]}`)) {
|
|
51
|
+
atday = i18next.t(`weekdays.days next week.${this.weekdays[nextchange.getDay()]}`, {
|
|
42
52
|
day: nextchange.toLocaleString(i18next.language, {weekday: 'long'})
|
|
43
53
|
});
|
|
44
54
|
} else {
|
|
@@ -48,8 +58,8 @@ var OpeningHoursTable = {
|
|
|
48
58
|
}
|
|
49
59
|
}
|
|
50
60
|
|
|
51
|
-
|
|
52
|
-
|
|
61
|
+
let month_name = nextchange.toLocaleString(i18next.language, {month: 'long'});
|
|
62
|
+
const month_name_match = month_name.match(/\(([^|]+?)\|.*\)/);
|
|
53
63
|
if (month_name_match && typeof month_name_match[1] === 'string') {
|
|
54
64
|
/* The language has multiple words for the month (nominative, subjective).
|
|
55
65
|
* Use the first one.
|
|
@@ -58,9 +68,8 @@ var OpeningHoursTable = {
|
|
|
58
68
|
month_name = month_name_match[1];
|
|
59
69
|
}
|
|
60
70
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var res = [];
|
|
71
|
+
const atdate = `${nextchange.getDate()} ${month_name}`;
|
|
72
|
+
const res = [];
|
|
64
73
|
|
|
65
74
|
if (atday !== '') res.push(atday);
|
|
66
75
|
if (atdate !== '') res.push(atdate);
|
|
@@ -69,55 +78,49 @@ var OpeningHoursTable = {
|
|
|
69
78
|
return res.join(', ');
|
|
70
79
|
},
|
|
71
80
|
|
|
72
|
-
pad
|
|
81
|
+
pad (n) { return n < 10 ? `0${n}` : n; },
|
|
73
82
|
|
|
74
|
-
plural
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return i18next.t(trans_base); // singular form
|
|
78
|
-
} else if (n < 2) { // FIXME: Is this correct for Russian?
|
|
79
|
-
return i18next.t(trans_base + ' many');
|
|
80
|
-
} else {
|
|
81
|
-
return i18next.t(trans_base + '_plural');
|
|
82
|
-
}*/
|
|
83
|
+
plural (n, trans_base) {
|
|
84
|
+
// i18next plural function call
|
|
85
|
+
return i18next.t(trans_base, {count: n});
|
|
83
86
|
},
|
|
84
87
|
|
|
85
|
-
printDate
|
|
88
|
+
printDate (date) {
|
|
86
89
|
// return date.toLocaleDateString('en-CA');
|
|
87
|
-
return date.getFullYear()
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
return `${date.getFullYear()}-${
|
|
91
|
+
this.pad(date.getMonth() + 1)}-${
|
|
92
|
+
this.pad(date.getDate())}`;
|
|
90
93
|
},
|
|
91
94
|
|
|
92
|
-
printTime
|
|
95
|
+
printTime (date) {
|
|
93
96
|
// return date.toLocaleTimeString('de');
|
|
94
|
-
return this.pad(date.getHours())
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
return `${this.pad(date.getHours())}:${
|
|
98
|
+
this.pad(date.getMinutes())}:${
|
|
99
|
+
this.pad(date.getSeconds())}`;
|
|
97
100
|
},
|
|
98
101
|
|
|
99
|
-
drawTable
|
|
100
|
-
|
|
102
|
+
drawTable (it, date_today, has_next_change) {
|
|
103
|
+
date_today = new Date(date_today);
|
|
101
104
|
date_today.setHours(0, 0, 0, 0);
|
|
102
105
|
|
|
103
|
-
|
|
106
|
+
const date = new Date(date_today);
|
|
104
107
|
// date.setDate(date.getDate() - date.getDay() + 7);
|
|
105
108
|
date.setDate(date.getDate() - date.getDay() - 1); // start at begin of the week
|
|
106
109
|
|
|
107
|
-
|
|
110
|
+
const table = [];
|
|
108
111
|
|
|
109
|
-
for (
|
|
110
|
-
date.setDate(date.getDate()+1);
|
|
112
|
+
for (let row = 0; row < 7; row++) {
|
|
113
|
+
date.setDate(date.getDate() + 1);
|
|
111
114
|
// if (date.getDay() === date_today.getDay()) {
|
|
112
115
|
// date.setDate(date.getDate()-7);
|
|
113
116
|
// }
|
|
114
117
|
|
|
115
118
|
it.setDate(date);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
let is_open = it.getState();
|
|
120
|
+
let unknown = it.getUnknown();
|
|
121
|
+
let state_string = it.getStateString(false);
|
|
122
|
+
let prevdate = date;
|
|
123
|
+
let curdate = date;
|
|
121
124
|
// console.log(state_string, is_open, unknown, date.toString());
|
|
122
125
|
|
|
123
126
|
table[row] = {
|
|
@@ -126,28 +129,30 @@ var OpeningHoursTable = {
|
|
|
126
129
|
text: []
|
|
127
130
|
};
|
|
128
131
|
|
|
129
|
-
while (has_next_change && it.advance() && curdate.getTime() - date.getTime() < 24*60*60*1000) {
|
|
132
|
+
while (has_next_change && it.advance() && curdate.getTime() - date.getTime() < 24 * 60 * 60 * 1000) {
|
|
130
133
|
curdate = it.getDate();
|
|
131
134
|
|
|
132
|
-
|
|
133
|
-
|
|
135
|
+
let fr = prevdate.getTime() - date.getTime();
|
|
136
|
+
let to = curdate.getTime() - date.getTime();
|
|
134
137
|
|
|
135
|
-
if (to > 24*60*60*1000)
|
|
136
|
-
to = 24*60*60*1000;
|
|
138
|
+
if (to > 24 * 60 * 60 * 1000) {
|
|
139
|
+
to = 24 * 60 * 60 * 1000;
|
|
140
|
+
}
|
|
137
141
|
|
|
138
|
-
fr *= 100/1000/60/60/24;
|
|
139
|
-
to *= 100/1000/60/60/24;
|
|
142
|
+
fr *= 100 / 1000 / 60 / 60 / 24;
|
|
143
|
+
to *= 100 / 1000 / 60 / 60 / 24;
|
|
140
144
|
|
|
141
|
-
table[row].times +=
|
|
142
|
-
|
|
145
|
+
table[row].times += `<div class="timebar ${is_open ? 'open' : unknown ? 'unknown' : 'closed'
|
|
146
|
+
}" style="width:${to - fr}%"></div>`;
|
|
143
147
|
if (is_open || unknown) {
|
|
144
|
-
|
|
145
|
-
i18next.t('words.from')
|
|
146
|
-
|
|
147
|
-
if (prevdate.getDay() !== curdate.getDay())
|
|
148
|
+
let text = `${i18next.t(`words.${state_string}`)} ${
|
|
149
|
+
i18next.t('words.from')} ${this.printTime(prevdate)
|
|
150
|
+
} ${i18next.t('words.to')} `;
|
|
151
|
+
if (prevdate.getDay() !== curdate.getDay()) {
|
|
148
152
|
text += '24:00';
|
|
149
|
-
else
|
|
153
|
+
} else {
|
|
150
154
|
text += this.printTime(curdate);
|
|
155
|
+
}
|
|
151
156
|
|
|
152
157
|
table[row].text.push(text);
|
|
153
158
|
}
|
|
@@ -159,23 +164,24 @@ var OpeningHoursTable = {
|
|
|
159
164
|
}
|
|
160
165
|
|
|
161
166
|
if (!has_next_change && table[row].text.length === 0) { // 24/7
|
|
162
|
-
table[row].times +=
|
|
163
|
-
|
|
164
|
-
if (is_open)
|
|
165
|
-
table[row].text.push(i18next.t('words.open')
|
|
167
|
+
table[row].times += `<div class="timebar ${is_open ? 'open' : unknown ? 'unknown' : 'closed'
|
|
168
|
+
}" style="width:100%"></div>`;
|
|
169
|
+
if (is_open) {
|
|
170
|
+
table[row].text.push(`${i18next.t('words.open')} 00:00 ${i18next.t('words.to')} 24:00`);
|
|
171
|
+
}
|
|
166
172
|
}
|
|
167
173
|
}
|
|
168
174
|
|
|
169
|
-
|
|
175
|
+
let output = '';
|
|
170
176
|
output += '<table>';
|
|
171
|
-
for (
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
177
|
+
for (const row in table) {
|
|
178
|
+
const today = table[row].date.getDay() === date_today.getDay();
|
|
179
|
+
const endweek = (table[row].date.getDay() + 1) % 7 === date_today.getDay();
|
|
180
|
+
const cl = today ? ' class="today"' : (endweek ? ' class="endweek"' : '');
|
|
175
181
|
|
|
176
182
|
// if (today && date_today.getDay() !== 1)
|
|
177
183
|
// output += '<tr class="separator"><td colspan="3"></td></tr>';
|
|
178
|
-
output +=
|
|
184
|
+
output += `<tr${cl}><td class="day ${table[row].date.getDay() % 6 === 0 ? 'weekend' : 'workday'}">`;
|
|
179
185
|
output += this.printDate(table[row].date);
|
|
180
186
|
output += '</td><td class="times">';
|
|
181
187
|
output += table[row].times;
|
|
@@ -187,58 +193,59 @@ var OpeningHoursTable = {
|
|
|
187
193
|
return output;
|
|
188
194
|
},
|
|
189
195
|
|
|
190
|
-
getReadableState
|
|
196
|
+
getReadableState (startString, endString, oh, past) {
|
|
191
197
|
if (past === true) past = 'd';
|
|
192
198
|
else past = '';
|
|
193
199
|
|
|
194
|
-
|
|
195
|
-
return startString + output + endString
|
|
200
|
+
const output = '';
|
|
201
|
+
return `${startString + output + endString}.`;
|
|
196
202
|
},
|
|
197
203
|
|
|
198
|
-
drawTableAndComments
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
var comment = it.getComment();
|
|
205
|
-
var has_next_change = it.advance();
|
|
204
|
+
drawTableAndComments (oh, it, value) {
|
|
205
|
+
const prevdate = it.getDate();
|
|
206
|
+
const unknown = it.getUnknown();
|
|
207
|
+
const state_string_past = it.getStateString(true);
|
|
208
|
+
const comment = it.getComment();
|
|
209
|
+
const has_next_change = it.advance();
|
|
206
210
|
|
|
207
|
-
|
|
211
|
+
let output = '';
|
|
208
212
|
|
|
209
|
-
output +=
|
|
210
|
-
|
|
213
|
+
output += `<p class="${state_string_past}">${
|
|
214
|
+
i18next.t(`texts.${state_string_past} ${has_next_change ? 'now' : 'always'}`)}`;
|
|
211
215
|
if (typeof comment !== 'undefined') {
|
|
212
216
|
if (unknown) {
|
|
213
|
-
output += i18next.t('texts.depends on', {
|
|
217
|
+
output += i18next.t('texts.depends on', {comment: `"${comment}"`});
|
|
214
218
|
} else {
|
|
215
|
-
output +=
|
|
219
|
+
output += `, ${i18next.t('words.comment')}: "${comment}"`;
|
|
216
220
|
}
|
|
217
221
|
}
|
|
218
222
|
output += '</p>';
|
|
219
223
|
|
|
220
224
|
if (has_next_change) {
|
|
221
|
-
|
|
222
|
-
time_diff
|
|
225
|
+
let time_diff = it.getDate().getTime() - prevdate.getTime();
|
|
226
|
+
time_diff /= 1000;
|
|
223
227
|
time_diff += 60; // go one second after
|
|
224
|
-
output +=
|
|
225
|
-
|
|
228
|
+
output += `<p class="${it.getStateString(true)}">${
|
|
229
|
+
i18next.t(`texts.will ${it.getStateString(false)}`, {
|
|
226
230
|
timestring: this.formatdate(prevdate, it.getDate(), true),
|
|
227
|
-
href:
|
|
228
|
-
comment:
|
|
229
|
-
?
|
|
230
|
-
|
|
231
|
-
|
|
231
|
+
href: `javascript:Evaluate(${time_diff}, false, '${value}')`,
|
|
232
|
+
comment: typeof it.getComment() === 'string' || typeof comment === 'string'
|
|
233
|
+
? `, ${i18next.t('words.comment')}: ${typeof it.getComment() === 'string'
|
|
234
|
+
? `"${it.getComment()}"`
|
|
235
|
+
: i18next.t('words.undefined')}`
|
|
236
|
+
: ''
|
|
237
|
+
})}</p>`;
|
|
232
238
|
}
|
|
233
239
|
|
|
234
240
|
output += this.drawTable(it, prevdate, has_next_change);
|
|
235
241
|
|
|
236
|
-
if (oh.isWeekStable())
|
|
237
|
-
output +=
|
|
238
|
-
else
|
|
239
|
-
output +=
|
|
242
|
+
if (oh.isWeekStable()) {
|
|
243
|
+
output += `<p><b>${i18next.t('texts.week stable')}</b></p>`;
|
|
244
|
+
} else {
|
|
245
|
+
output += `<p><b>${i18next.t('texts.not week stable')}</b></p>`;
|
|
246
|
+
}
|
|
240
247
|
|
|
241
248
|
return output;
|
|
242
249
|
},
|
|
243
250
|
// }}}
|
|
244
|
-
}
|
|
251
|
+
};
|
package/types/index.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ declare module 'opening_hours' {
|
|
|
28
28
|
start_date?: Date
|
|
29
29
|
): boolean
|
|
30
30
|
isWeekStable(): boolean
|
|
31
|
-
prettifyValue(argument_hash?: argument_hash): string
|
|
31
|
+
prettifyValue(argument_hash?: Partial<argument_hash>): string
|
|
32
32
|
getIterator(date?: Date): opening_hours_iterator
|
|
33
33
|
}
|
|
34
34
|
export default opening_hours
|
|
@@ -57,7 +57,7 @@ declare module 'opening_hours' {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
export interface argument_hash {
|
|
60
|
-
rule_index:
|
|
60
|
+
rule_index: number | undefined
|
|
61
61
|
zero_pad_hour: boolean
|
|
62
62
|
one_zero_if_hour_zero: boolean
|
|
63
63
|
leave_off_closed: boolean
|
|
@@ -84,7 +84,7 @@ declare module 'opening_hours' {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
export interface optional_conf {
|
|
87
|
-
mode: mode
|
|
87
|
+
mode: mode | undefined
|
|
88
88
|
tag_key: string | undefined
|
|
89
89
|
map_value: boolean | undefined
|
|
90
90
|
warnings_severity: warnings_severity | undefined
|