@escape-game-over/atlas 0.1.92 → 0.1.93
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/package.json +1 -1
- package/src/hours.ts +13 -22
package/package.json
CHANGED
package/src/hours.ts
CHANGED
|
@@ -356,27 +356,18 @@ export function schemaDays(group: HoursGroup): readonly string[] {
|
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
/**
|
|
359
|
-
* The day
|
|
360
|
-
*
|
|
359
|
+
* The day `offset` days from `day`: -1 is yesterday, 1 is tomorrow.
|
|
360
|
+
*
|
|
361
|
+
* The week wraps around, so the index is taken modulo 7. The `+ 7` keeps it
|
|
362
|
+
* from going negative: the day before Monday is `(0 - 1 + 7) % 7 = 6`, Sunday.
|
|
361
363
|
*/
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
sunday: "saturday",
|
|
370
|
-
};
|
|
371
|
-
const TOMORROW: Readonly<Record<Weekday, Weekday>> = {
|
|
372
|
-
monday: "tuesday",
|
|
373
|
-
tuesday: "wednesday",
|
|
374
|
-
wednesday: "thursday",
|
|
375
|
-
thursday: "friday",
|
|
376
|
-
friday: "saturday",
|
|
377
|
-
saturday: "sunday",
|
|
378
|
-
sunday: "monday",
|
|
379
|
-
};
|
|
364
|
+
function dayFrom(day: Weekday, offset: -1 | 1): Weekday {
|
|
365
|
+
const next = WEEK[(WEEK.indexOf(day) + offset + 7) % 7];
|
|
366
|
+
if (next === undefined) {
|
|
367
|
+
throw new Error(`No day ${offset} from ${day}.`);
|
|
368
|
+
}
|
|
369
|
+
return next;
|
|
370
|
+
}
|
|
380
371
|
|
|
381
372
|
/**
|
|
382
373
|
* The venue's wall clock at `now`: the day, and the time.
|
|
@@ -473,7 +464,7 @@ export function openStatus(
|
|
|
473
464
|
function statusAt(hours: WeeklyHours, day: Weekday, time: string): OpenStatus {
|
|
474
465
|
// 1. Still in last night's opening: yesterday has a span past midnight
|
|
475
466
|
// (`14:00`–`00:45`) and it is not yet 00:45.
|
|
476
|
-
const lateYesterday = spansOn(hours,
|
|
467
|
+
const lateYesterday = spansOn(hours, dayFrom(day, -1)).find(
|
|
477
468
|
(range) => pastMidnight(range) && time < range.closes
|
|
478
469
|
);
|
|
479
470
|
if (lateYesterday !== undefined) {
|
|
@@ -499,7 +490,7 @@ function statusAt(hours: WeeklyHours, day: Weekday, time: string): OpenStatus {
|
|
|
499
490
|
}
|
|
500
491
|
|
|
501
492
|
// 4. Done for today: when tomorrow's first span opens.
|
|
502
|
-
const [tomorrow] = spansOn(hours,
|
|
493
|
+
const [tomorrow] = spansOn(hours, dayFrom(day, 1));
|
|
503
494
|
if (tomorrow !== undefined) {
|
|
504
495
|
return { state: "opensTomorrow", time: tomorrow.opens };
|
|
505
496
|
}
|