@mccaskie-labs/workbench-bookings 0.2.1 → 0.2.2
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.md +6 -0
- package/dist/bookings.js +2 -2
- package/dist/time.d.ts +6 -0
- package/dist/time.js +15 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @mccaskie-labs/workbench-bookings
|
|
2
2
|
|
|
3
|
+
## 0.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- A reminder given in days ("1d") is now counted on the business's local clock, the way workbench-messages and workbench-nudges count days: a day before a 10:00 booking is 10:00 the day before, also when daylight saving changes in between. It was 24 elapsed hours, so across a clock change the email reminder and a WhatsApp reminder for the same booking went an hour apart. Hours and minutes ("24h", "30m") are still elapsed time. `cancel_until`, `notice` and `hold` are unchanged.
|
|
8
|
+
|
|
3
9
|
## 0.2.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/bookings.js
CHANGED
|
@@ -13,7 +13,7 @@ import { BookingsError } from "./errors.js";
|
|
|
13
13
|
import { DEFAULT_LOCALE, whenText, words } from "./format.js";
|
|
14
14
|
import { bookingIcs, feedIcs } from "./ical.js";
|
|
15
15
|
import { offered, openSlots, serviceOf } from "./slots.js";
|
|
16
|
-
import { addDays, durationMinutes, localInstant, todayIn, validDate } from "./time.js";
|
|
16
|
+
import { addDays, durationMinutes, localInstant, minusDuration, todayIn, validDate } from "./time.js";
|
|
17
17
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
18
18
|
const TOKEN = /^[A-Za-z0-9_-]{43}$/;
|
|
19
19
|
const EMAIL = /^[^\s@<>(),;:"[\]\\]+@[^\s@<>(),;:"[\]\\]+\.[^\s@<>(),;:"[\]\\]+$/;
|
|
@@ -78,7 +78,7 @@ export function customerOf(v, ask = {}) {
|
|
|
78
78
|
}
|
|
79
79
|
/** When the next reminder goes: the earliest reminder time after `after`, before the start. */
|
|
80
80
|
export function nextReminder(config, start, after) {
|
|
81
|
-
const times = (config.reminders ?? ["1d"]).map((d) => start.getTime()
|
|
81
|
+
const times = (config.reminders ?? ["1d"]).map((d) => minusDuration(start, d, config.time_zone).getTime()).filter((t) => t > after.getTime() && t < start.getTime());
|
|
82
82
|
return times.length ? new Date(Math.min(...times)) : null;
|
|
83
83
|
}
|
|
84
84
|
/** The Gateway's Idempotency-Key for one email: the same for a retry, and inside workbench-email's [A-Za-z0-9._:-]. */
|
package/dist/time.d.ts
CHANGED
|
@@ -3,6 +3,12 @@ export declare function durationMinutes(text: unknown): number | null;
|
|
|
3
3
|
/** "21:00" in minutes after midnight, or null. */
|
|
4
4
|
export declare function clockMinutes(text: unknown): number | null;
|
|
5
5
|
export declare function validZone(tz: unknown): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* `at` minus a length: days on the local clock ("1d" before 10:00 is 10:00
|
|
8
|
+
* the day before, also across a daylight saving change, as workbench-messages
|
|
9
|
+
* and workbench-nudges count them), minutes and hours as elapsed time.
|
|
10
|
+
*/
|
|
11
|
+
export declare function minusDuration(at: Date, duration: string, timeZone: string): Date;
|
|
6
12
|
/** Today in the zone, YYYY-MM-DD. */
|
|
7
13
|
export declare function todayIn(timeZone: string, at: Date): string;
|
|
8
14
|
/** A real calendar day, YYYY-MM-DD. */
|
package/dist/time.js
CHANGED
|
@@ -48,6 +48,21 @@ function fromLocal(wall, timeZone) {
|
|
|
48
48
|
const guess = wall - offsetAt(new Date(wall), timeZone);
|
|
49
49
|
return new Date(wall - offsetAt(new Date(guess), timeZone));
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* `at` minus a length: days on the local clock ("1d" before 10:00 is 10:00
|
|
53
|
+
* the day before, also across a daylight saving change, as workbench-messages
|
|
54
|
+
* and workbench-nudges count them), minutes and hours as elapsed time.
|
|
55
|
+
*/
|
|
56
|
+
export function minusDuration(at, duration, timeZone) {
|
|
57
|
+
const minutes = durationMinutes(duration);
|
|
58
|
+
if (minutes === null)
|
|
59
|
+
throw new Error(`${duration} isn't a length such as 1d, 2h or 30m`);
|
|
60
|
+
if (!duration.endsWith("d"))
|
|
61
|
+
return new Date(at.getTime() - minutes * 60_000);
|
|
62
|
+
const p = localParts(at, timeZone);
|
|
63
|
+
const wall = Date.UTC(p.year, p.month - 1, p.day, p.hour, p.minute, p.second) + (at.getTime() % 1000);
|
|
64
|
+
return fromLocal(wall - minutes * 60_000, timeZone);
|
|
65
|
+
}
|
|
51
66
|
/** Today in the zone, YYYY-MM-DD. */
|
|
52
67
|
export function todayIn(timeZone, at) {
|
|
53
68
|
const p = localParts(at, timeZone);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mccaskie-labs/workbench-bookings",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "A bookings calendar for Workbench apps: customers pick a free time, book it with their name and email, and get a confirmation email with a calendar file, reminders before it starts and a private link to change or cancel. The owner gets an email for each booking, a list in the app and a calendar feed. Stored in the app's own database, with tick() from the app's cron for reminders. No AI.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|