@camstack/server 1.2.942 → 1.2.944
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 +26 -0
- package/closure-pins.json +350 -0
- package/dist/api/core/auth-sessions.procedures.js +18 -0
- package/dist/api/core/auth.router.js +19 -6
- package/dist/api/server-upload.js +17 -1
- package/dist/api/trpc/generated-cap-routers.js +83 -0
- package/dist/auth/native-return.js +9 -3
- package/dist/auth/sso-routes.js +5 -1
- package/dist/core/addon/instance-lifecycle.js +4 -1
- package/dist/core/auth/handoff-code.service.js +35 -1
- package/dist/server-root/index.js +313 -70
- package/package.json +22 -26
- package/system/dist/{action-index-B1fgpQBt.mjs → action-index-DpYmsOKh.mjs} +1 -1
- package/system/dist/{action-index-B_cLRwXJ.js → action-index-Dz9rd1qa.js} +1 -1
- package/system/dist/{addon-settings.cap-CZ4MC7ha.mjs → addon-settings.cap-CHpmuaQG.mjs} +1 -1
- package/system/dist/{addon-settings.cap-DrLdMFIe.js → addon-settings.cap-nZVHPo3X.js} +1 -1
- package/system/dist/{alert-episode-Be--PngO.mjs → alert-episode-D-1VUUkZ.mjs} +1 -1
- package/system/dist/{alert-episode-Bqktmt-i.js → alert-episode-DaQ3prSe.js} +1 -1
- package/system/dist/{base-addon-CRsXtYFG.js → base-addon-BG7p06Hb.js} +136 -15
- package/system/dist/{base-addon-BcS6r1cT.mjs → base-addon-BcVoYZbC.mjs} +136 -15
- package/system/dist/{base-device-DAdWzDOl.js → base-device-DeSNiwZ4.js} +4 -4
- package/system/dist/{base-device-DJXF5eDN.mjs → base-device-w_MD0Bf4.mjs} +4 -4
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/alerts/alerts.addon.js +3 -3
- package/system/dist/builtins/alerts/alerts.addon.mjs +3 -3
- package/system/dist/builtins/autotrack/index.js +1 -1
- package/system/dist/builtins/autotrack/index.mjs +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/calendars/calendars.addon.js +1 -1
- package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/system/dist/builtins/camera-grid/index.js +3 -3
- package/system/dist/builtins/camera-grid/index.mjs +3 -3
- package/system/dist/builtins/composer/composer.addon.js +7 -7
- package/system/dist/builtins/composer/composer.addon.mjs +7 -7
- package/system/dist/builtins/console-logging/index.js +1 -1
- package/system/dist/builtins/console-logging/index.mjs +1 -1
- package/system/dist/builtins/core-blocks/actions-store.d.ts +2 -0
- package/system/dist/builtins/core-blocks/block-supervisor.d.ts +16 -4
- package/system/dist/builtins/core-blocks/core-block-store.d.ts +2 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +1018 -323
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +986 -291
- package/system/dist/builtins/core-blocks/migrations/index.d.ts +5 -2
- package/system/dist/builtins/core-blocks/migrations/tag-ids.d.ts +42 -0
- package/system/dist/builtins/core-blocks/migrations/tags-as-records.d.ts +47 -0
- package/system/dist/builtins/core-blocks/record-kinds.d.ts +12 -1
- package/system/dist/builtins/core-blocks/runs-api.d.ts +3 -1
- package/system/dist/builtins/core-blocks/runs-ledger.d.ts +3 -1
- package/system/dist/builtins/core-blocks/scheduler/scheduler-store.d.ts +2 -0
- package/system/dist/builtins/core-blocks/tags-service.d.ts +52 -27
- package/system/dist/builtins/core-blocks/tags-wiring.d.ts +2 -0
- package/system/dist/builtins/core-notifier/core-notifier.addon.js +76 -67
- package/system/dist/builtins/core-notifier/core-notifier.addon.mjs +76 -67
- package/system/dist/builtins/device-history/device-history.addon.js +4 -4
- package/system/dist/builtins/device-history/device-history.addon.mjs +4 -4
- package/system/dist/builtins/device-manager/device-config-secrets.d.ts +14 -0
- package/system/dist/builtins/device-manager/device-manager.addon.js +1655 -764
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +1641 -750
- package/system/dist/builtins/device-manager/device-meta-actions.d.ts +13 -136
- package/system/dist/builtins/device-manager/device-meta-types.d.ts +5 -1
- package/system/dist/builtins/device-manager/device-provider-context.d.ts +9 -0
- package/system/dist/builtins/device-manager/device-row-store.d.ts +21 -4
- package/system/dist/builtins/device-manager/device-search.d.ts +6 -0
- package/system/dist/builtins/device-manager/location-alignment.d.ts +9 -2
- package/system/dist/builtins/device-manager/migrate-device.d.ts +7 -2
- package/system/dist/builtins/device-manager/migrate-hardware-state.d.ts +132 -1
- package/system/dist/builtins/device-manager/migrations/device-tag-ids.d.ts +25 -0
- package/system/dist/builtins/device-manager/migrations/index.d.ts +16 -0
- package/system/dist/builtins/device-manager/migrations/orphan-children.d.ts +33 -0
- package/system/dist/builtins/device-manager/migrations/ports.d.ts +17 -0
- package/system/dist/builtins/device-manager/migrations/rooms-as-records.d.ts +52 -0
- package/system/dist/builtins/device-manager/record-kinds.d.ts +3 -1
- package/system/dist/builtins/device-manager/removal-cleanup.d.ts +7 -0
- package/system/dist/builtins/device-manager/room-actions.d.ts +27 -0
- package/system/dist/builtins/device-manager/room-store.d.ts +19 -0
- package/system/dist/builtins/device-manager/tag-names.d.ts +32 -0
- package/system/dist/builtins/device-manager/wireable-enum-catalog.d.ts +18 -0
- package/system/dist/builtins/hub-forwarder/index.js +1 -1
- package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/system/dist/builtins/keychain/index.js +2 -2
- package/system/dist/builtins/keychain/index.mjs +2 -2
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +1 -1
- package/system/dist/builtins/local-network/local-network.addon.js +2 -2
- package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
- package/system/dist/builtins/loki-logging/index.js +2 -2
- package/system/dist/builtins/loki-logging/index.mjs +2 -2
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
- package/system/dist/builtins/platform-probe/index.js +1 -1
- package/system/dist/builtins/platform-probe/index.mjs +1 -1
- package/system/dist/builtins/record-entries/index.js +1 -1
- package/system/dist/builtins/record-entries/index.mjs +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/snapshot/index.js +1 -1
- package/system/dist/builtins/snapshot/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/index.js +1 -1
- package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/migrations/migration-engine.d.ts +3 -1
- package/system/dist/builtins/sqlite-storage/migrations/migrations-provider.d.ts +1 -0
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +15 -10
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +15 -10
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/system-config/system-config.addon.js +1 -1
- package/system/dist/builtins/system-config/system-config.addon.mjs +1 -1
- package/system/dist/builtins/winston-logging/index.js +2 -2
- package/system/dist/builtins/winston-logging/index.mjs +2 -2
- package/system/dist/{command-catalog-C29hVOOg.js → command-catalog-CI0tu1Nt.js} +1 -1
- package/system/dist/{command-catalog-xAeqxbZk.mjs → command-catalog-zwlIA3T5.mjs} +1 -1
- package/system/dist/{composition-sources-C327LGFn.mjs → composition-sources-CXxXfh1z.mjs} +1 -1
- package/system/dist/{composition-sources-Do5qM6EB.js → composition-sources-DNgSItK-.js} +1 -1
- package/system/dist/{core-blocks.cap-CdTGUKtr.js → core-blocks.cap-BHEok4VO.js} +125 -373
- package/system/dist/{core-blocks.cap-DLkEfV5b.mjs → core-blocks.cap-CPgZRcpj.mjs} +109 -327
- package/system/dist/{device-manager.cap-DJs8izI6.js → device-manager.cap-B9qVf7ag.js} +163 -22
- package/system/dist/{device-manager.cap-eYrj1Ezp.mjs → device-manager.cap-CV4KGp3e.mjs} +134 -17
- package/system/dist/{error.cap-CU1FB6uE.mjs → error.cap-B8l7L8e4.mjs} +7 -1
- package/system/dist/{error.cap-BuKbL3Ac.js → error.cap-BqlvgBJd.js} +7 -1
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/index.js +7 -7
- package/system/dist/index.mjs +6 -6
- package/system/dist/{legacy-integration-rows-door-CdqYAj-o.js → legacy-integration-rows-door-BK8eoGlF.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-LSgpClpX.mjs → legacy-integration-rows-door-CwzC5XNk.mjs} +1 -1
- package/system/dist/{migration-DGAc6ywR.mjs → migration-BvbfW9g-.mjs} +6 -0
- package/system/dist/{migration-BOQlFZCN.js → migration-CHPdAdNh.js} +6 -0
- package/system/dist/{prefix-walk-BFnw8NBu.js → named-entity-store-DFwLij9c.js} +244 -90
- package/system/dist/{prefix-walk-Mtij0NNT.mjs → named-entity-store-DOnyyFFf.mjs} +195 -89
- package/system/dist/{notification-rules.cap-BUIuYPlQ.mjs → notification-rules.cap-ClvK6QT1.mjs} +10 -5
- package/system/dist/{notification-rules.cap-BJKUjizS.js → notification-rules.cap-uSLoe2pA.js} +10 -5
- package/system/dist/{notification-targets-DMW7xgR2.js → notification-targets-ChqpBbtR.js} +2 -2
- package/system/dist/{notification-targets-4bGYH5J7.mjs → notification-targets-DUA6-F2t.mjs} +2 -2
- package/system/dist/{device-row-store-CTocYKqC.mjs → record-kinds-BD2xv4Pd.mjs} +222 -93
- package/system/dist/{device-row-store-C0P2H18h.js → record-kinds-BV8Gcpsx.js} +246 -93
- package/system/dist/records/named-entity-store.d.ts +60 -0
- package/system/dist/{rename-composition-block-Cdh-dRmY.mjs → rename-composition-block-C3QQ9UUE.mjs} +134 -33
- package/system/dist/{rename-composition-block-D9Uc1AF7.js → rename-composition-block-Cx3X8QSm.js} +134 -33
- package/system/dist/{retention-source.cap-C6Hy0hlM.js → retention-source.cap-A-TMhU5O.js} +1 -1
- package/system/dist/{retention-source.cap-550kkyp5.mjs → retention-source.cap-Ct07pM30.mjs} +1 -1
- package/system/dist/{storage-admin.cap-Ci4QbL6P.mjs → storage-admin.cap-C54s9_B9.mjs} +8 -2
- package/system/dist/{storage-admin.cap-DqW1ol4j.js → storage-admin.cap-DSPHi7ut.js} +8 -2
- package/system/dist/{stream-catalog.cap-CjEQFknc.js → stream-catalog.cap-7WPsugOy.js} +1 -1
- package/system/dist/{stream-catalog.cap-DVniDdRD.mjs → stream-catalog.cap-CzwRDaqT.mjs} +1 -1
- package/system/dist/{tag-BxLazvVb.js → tag-BLraBqvp.js} +12 -0
- package/system/dist/{tag-uZBAq6ox.mjs → tag-DU8pm9Bi.mjs} +7 -1
- package/system/dist/time-window-B6UhCArd.js +679 -0
- package/system/dist/time-window-BnUBULgu.mjs +578 -0
- package/system/dist/{wal-maintenance-BgYiAy5b.js → wal-maintenance-CkPfVApC.js} +0 -0
- package/system/dist/{wal-maintenance-Bey5ChBb.mjs → wal-maintenance-u84_1sVl.mjs} +0 -0
- package/system/package.json +1 -1
|
@@ -0,0 +1,578 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region ../types/dist/esm/time/solar.mjs
|
|
3
|
+
/**
|
|
4
|
+
* Where the sun is, from a latitude and a longitude — the one solar
|
|
5
|
+
* calculation in the repo. Compact NOAA sunrise equation (accurate to about a
|
|
6
|
+
* minute away from the poles), so no astronomy dependency is needed.
|
|
7
|
+
*
|
|
8
|
+
* Two consumers read it: the scene-condition resolver (day / night / dawn /
|
|
9
|
+
* dusk of a camera) and a schedule's sun time (`time-spec.ts`).
|
|
10
|
+
*/
|
|
11
|
+
var DEG = Math.PI / 180;
|
|
12
|
+
/** The sun's upper limb on the horizon, refraction included: sunrise and sunset. */
|
|
13
|
+
var SUNRISE_ALTITUDE_DEG = -.833;
|
|
14
|
+
/** Julian day number for a JS Date (UTC). */
|
|
15
|
+
function toJulian(date) {
|
|
16
|
+
return date.getTime() / 864e5 + 2440587.5;
|
|
17
|
+
}
|
|
18
|
+
/** Julian day → epoch ms (UTC). */
|
|
19
|
+
function fromJulian(j) {
|
|
20
|
+
return (j - 2440587.5) * 864e5;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* When the sun crosses `altitudeDeg` on the day `date` falls in at this place.
|
|
24
|
+
* Pass an instant near local midday of the civil day you mean: the day is
|
|
25
|
+
* chosen from the instant, and midday is the one that never straddles two.
|
|
26
|
+
*
|
|
27
|
+
* `null` when the sun never crosses that altitude that day (polar day or polar
|
|
28
|
+
* night, or — for a twilight altitude — a summer night that never gets dark
|
|
29
|
+
* enough). The caller decides what that means; nothing here guesses.
|
|
30
|
+
*/
|
|
31
|
+
function sunCrossings(lat, lng, date, altitudeDeg) {
|
|
32
|
+
const jDate = toJulian(date);
|
|
33
|
+
const jStar = Math.round(jDate - 2451545 + 8e-4) - lng / 360;
|
|
34
|
+
const m = (357.5291 + .98560028 * jStar) % 360;
|
|
35
|
+
const mRad = m * DEG;
|
|
36
|
+
const lambda = (m + (1.9148 * Math.sin(mRad) + .02 * Math.sin(2 * mRad) + 3e-4 * Math.sin(3 * mRad)) + 180 + 102.9372) % 360 * DEG;
|
|
37
|
+
const jTransit = 2451545 + jStar + .0053 * Math.sin(mRad) - .0069 * Math.sin(2 * lambda);
|
|
38
|
+
const declination = Math.asin(Math.sin(lambda) * Math.sin(23.44 * DEG));
|
|
39
|
+
const latRad = lat * DEG;
|
|
40
|
+
const cosOmega = (Math.sin(altitudeDeg * DEG) - Math.sin(latRad) * Math.sin(declination)) / (Math.cos(latRad) * Math.cos(declination));
|
|
41
|
+
if (cosOmega > 1 || cosOmega < -1) return null;
|
|
42
|
+
const omega = Math.acos(cosOmega) / DEG;
|
|
43
|
+
return {
|
|
44
|
+
rise: fromJulian(jTransit - omega / 360),
|
|
45
|
+
set: fromJulian(jTransit + omega / 360)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region ../types/dist/esm/time/time-spec.mjs
|
|
50
|
+
/**
|
|
51
|
+
* WHEN something happens, as data (D983) — the one time vocabulary of the
|
|
52
|
+
* scheduler and of an automation's schedule leaf. Three shapes, no cron:
|
|
53
|
+
*
|
|
54
|
+
* - `clock` — a wall-clock time every day (`07:30`), read in the site's zone;
|
|
55
|
+
* - `sun` — a sun event (`sunrise`, `sunset`, `dawn`, `dusk`) plus or minus
|
|
56
|
+
* up to twelve hours, from the site's coordinates;
|
|
57
|
+
* - `date` — one local date and time (`2026-12-24T18:00`), once.
|
|
58
|
+
*
|
|
59
|
+
* A site is a place and its IANA zone ({@link TimeSite}). Every function here
|
|
60
|
+
* is pure: the zone arithmetic uses `Intl`, no date library.
|
|
61
|
+
*
|
|
62
|
+
* Wall-clock honesty across a DST change: a local time that does not exist
|
|
63
|
+
* (02:30 on the spring-forward day) happens at the first minute that does
|
|
64
|
+
* (03:00); one that happens twice (02:30 on the fall-back day) happens at its
|
|
65
|
+
* FIRST occurrence.
|
|
66
|
+
*/
|
|
67
|
+
var SunEventSchema = /* @__PURE__ */ z.enum([
|
|
68
|
+
"sunrise",
|
|
69
|
+
"sunset",
|
|
70
|
+
"dawn",
|
|
71
|
+
"dusk"
|
|
72
|
+
]);
|
|
73
|
+
var LOCAL_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
74
|
+
var LOCAL_DATE_TIME = /^(\d{4}-\d{2}-\d{2})T([01]\d|2[0-3]):([0-5]\d)$/;
|
|
75
|
+
var TimeSpecSchema = /* @__PURE__ */ z.discriminatedUnion("kind", [
|
|
76
|
+
/* @__PURE__ */ z.object({
|
|
77
|
+
kind: /* @__PURE__ */ z.literal("clock"),
|
|
78
|
+
hh: /* @__PURE__ */ z.number().int().min(0).max(23),
|
|
79
|
+
mm: /* @__PURE__ */ z.number().int().min(0).max(59)
|
|
80
|
+
}),
|
|
81
|
+
/* @__PURE__ */ z.object({
|
|
82
|
+
kind: /* @__PURE__ */ z.literal("sun"),
|
|
83
|
+
event: SunEventSchema,
|
|
84
|
+
/** Minutes after the event (negative: before). */
|
|
85
|
+
offsetMin: /* @__PURE__ */ z.number().int().min(-720).max(720)
|
|
86
|
+
}),
|
|
87
|
+
/* @__PURE__ */ z.object({
|
|
88
|
+
kind: /* @__PURE__ */ z.literal("date"),
|
|
89
|
+
/** `YYYY-MM-DDTHH:mm`, site-local. */
|
|
90
|
+
local: /* @__PURE__ */ z.string().regex(LOCAL_DATE_TIME, "expected YYYY-MM-DDTHH:mm")
|
|
91
|
+
})
|
|
92
|
+
]);
|
|
93
|
+
/** A day of the week as a schedule names it. */
|
|
94
|
+
var WeekdayKeySchema = /* @__PURE__ */ z.enum([
|
|
95
|
+
"mon",
|
|
96
|
+
"tue",
|
|
97
|
+
"wed",
|
|
98
|
+
"thu",
|
|
99
|
+
"fri",
|
|
100
|
+
"sat",
|
|
101
|
+
"sun"
|
|
102
|
+
]);
|
|
103
|
+
var WEEKDAY_BY_INDEX = [
|
|
104
|
+
"sun",
|
|
105
|
+
"mon",
|
|
106
|
+
"tue",
|
|
107
|
+
"wed",
|
|
108
|
+
"thu",
|
|
109
|
+
"fri",
|
|
110
|
+
"sat"
|
|
111
|
+
];
|
|
112
|
+
/** The key of a numeric weekday (0 = Sunday … 6 = Saturday, as `Date.getDay`), or undefined out of range. */
|
|
113
|
+
function weekdayKeyOfIndex(index) {
|
|
114
|
+
return WEEKDAY_BY_INDEX[index];
|
|
115
|
+
}
|
|
116
|
+
var MINUTE_MS = 6e4;
|
|
117
|
+
var DAY_MS = 864e5;
|
|
118
|
+
var formatters = /* @__PURE__ */ new Map();
|
|
119
|
+
function formatterFor(timeZone) {
|
|
120
|
+
const cached = formatters.get(timeZone);
|
|
121
|
+
if (cached !== void 0) return cached;
|
|
122
|
+
const created = new Intl.DateTimeFormat("en-US", {
|
|
123
|
+
timeZone,
|
|
124
|
+
hourCycle: "h23",
|
|
125
|
+
year: "numeric",
|
|
126
|
+
month: "2-digit",
|
|
127
|
+
day: "2-digit",
|
|
128
|
+
hour: "2-digit",
|
|
129
|
+
minute: "2-digit",
|
|
130
|
+
second: "2-digit"
|
|
131
|
+
});
|
|
132
|
+
formatters.set(timeZone, created);
|
|
133
|
+
return created;
|
|
134
|
+
}
|
|
135
|
+
function wallClockOf(epochMs, timeZone) {
|
|
136
|
+
const out = {};
|
|
137
|
+
for (const part of formatterFor(timeZone).formatToParts(new Date(epochMs))) if (part.type !== "literal") out[part.type] = Number(part.value);
|
|
138
|
+
return {
|
|
139
|
+
year: out["year"] ?? 0,
|
|
140
|
+
month: out["month"] ?? 0,
|
|
141
|
+
day: out["day"] ?? 0,
|
|
142
|
+
hour: out["hour"] ?? 0,
|
|
143
|
+
minute: out["minute"] ?? 0,
|
|
144
|
+
second: out["second"] ?? 0
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** Minutes since local midnight at an instant, read on the zone's wall clock (a repeated hour reads twice). */
|
|
148
|
+
function localMinuteOfDay(epochMs, timeZone) {
|
|
149
|
+
const w = wallClockOf(epochMs, timeZone);
|
|
150
|
+
return w.hour * 60 + w.minute;
|
|
151
|
+
}
|
|
152
|
+
/** The zone's offset from UTC at an instant, in ms (positive east of Greenwich). */
|
|
153
|
+
function offsetMs(epochMs, timeZone) {
|
|
154
|
+
const w = wallClockOf(epochMs, timeZone);
|
|
155
|
+
return Date.UTC(w.year, w.month - 1, w.day, w.hour, w.minute, w.second) - Math.floor(epochMs / 1e3) * 1e3;
|
|
156
|
+
}
|
|
157
|
+
/** Is `timeZone` a zone this runtime knows? */
|
|
158
|
+
function isKnownTimeZone(timeZone) {
|
|
159
|
+
try {
|
|
160
|
+
formatterFor(timeZone);
|
|
161
|
+
return true;
|
|
162
|
+
} catch {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/** `YYYY-MM-DD` of an instant, read in the zone. */
|
|
167
|
+
function localDateOf(epochMs, timeZone) {
|
|
168
|
+
const w = wallClockOf(epochMs, timeZone);
|
|
169
|
+
return `${String(w.year).padStart(4, "0")}-${String(w.month).padStart(2, "0")}-${String(w.day).padStart(2, "0")}`;
|
|
170
|
+
}
|
|
171
|
+
function parseLocalDate(localDate) {
|
|
172
|
+
if (!LOCAL_DATE.test(localDate)) throw new Error(`not a local date (YYYY-MM-DD): ${localDate}`);
|
|
173
|
+
const [y, m, d] = localDate.split("-").map(Number);
|
|
174
|
+
return {
|
|
175
|
+
y: y ?? 0,
|
|
176
|
+
m: m ?? 1,
|
|
177
|
+
d: d ?? 1
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/** The weekday of a `YYYY-MM-DD` civil date (zone-independent). */
|
|
181
|
+
function weekdayOfLocalDate(localDate) {
|
|
182
|
+
const { y, m, d } = parseLocalDate(localDate);
|
|
183
|
+
return WEEKDAY_BY_INDEX[new Date(Date.UTC(y, m - 1, d)).getUTCDay()] ?? "sun";
|
|
184
|
+
}
|
|
185
|
+
function addDays$1(localDate, days) {
|
|
186
|
+
const { y, m, d } = parseLocalDate(localDate);
|
|
187
|
+
return new Date(Date.UTC(y, m - 1, d + days)).toISOString().slice(0, 10);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The instant a wall-clock time happens in a zone. A time that does not exist
|
|
191
|
+
* happens at the first minute that does; one that happens twice, at its first
|
|
192
|
+
* occurrence.
|
|
193
|
+
*/
|
|
194
|
+
function wallToEpoch(localDate, hh, mm, timeZone) {
|
|
195
|
+
const { y, m, d } = parseLocalDate(localDate);
|
|
196
|
+
const wall = Date.UTC(y, m - 1, d, hh, mm);
|
|
197
|
+
const before = offsetMs(wall - DAY_MS, timeZone);
|
|
198
|
+
const after = offsetMs(wall + DAY_MS, timeZone);
|
|
199
|
+
const valid = [wall - before, wall - after].filter((c) => c + offsetMs(c, timeZone) === wall);
|
|
200
|
+
if (valid.length > 0) return Math.min(...valid);
|
|
201
|
+
let lo = wall - DAY_MS;
|
|
202
|
+
let hi = wall + DAY_MS;
|
|
203
|
+
while (hi - lo > MINUTE_MS) {
|
|
204
|
+
const mid = Math.floor((lo + hi) / 2 / MINUTE_MS) * MINUTE_MS;
|
|
205
|
+
if (offsetMs(mid, timeZone) === before) lo = mid;
|
|
206
|
+
else hi = mid;
|
|
207
|
+
}
|
|
208
|
+
return hi;
|
|
209
|
+
}
|
|
210
|
+
function sunEventAltitude(event) {
|
|
211
|
+
return event === "sunrise" || event === "sunset" ? SUNRISE_ALTITUDE_DEG : -6;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* The moment `spec` happens on the site-local date `localDate` (`YYYY-MM-DD`).
|
|
215
|
+
* See {@link Occurrence} for what `null` means.
|
|
216
|
+
*/
|
|
217
|
+
function occurrenceOn(spec, localDate, site) {
|
|
218
|
+
switch (spec.kind) {
|
|
219
|
+
case "clock": return wallToEpoch(localDate, spec.hh, spec.mm, site.timeZone);
|
|
220
|
+
case "date": {
|
|
221
|
+
const match = LOCAL_DATE_TIME.exec(spec.local);
|
|
222
|
+
if (match === null || match[1] !== localDate) return null;
|
|
223
|
+
return wallToEpoch(localDate, Number(match[2]), Number(match[3]), site.timeZone);
|
|
224
|
+
}
|
|
225
|
+
case "sun": {
|
|
226
|
+
const midday = new Date(wallToEpoch(localDate, 12, 0, site.timeZone));
|
|
227
|
+
const crossings = sunCrossings(site.lat, site.lon, midday, sunEventAltitude(spec.event));
|
|
228
|
+
if (crossings === null) return null;
|
|
229
|
+
return (spec.event === "sunrise" || spec.event === "dawn" ? crossings.rise : crossings.set) + spec.offsetMin * MINUTE_MS;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* The first moment strictly after `afterMs` at which `spec` happens, or `null`
|
|
235
|
+
* when none does within {@link NEXT_OCCURRENCE_HORIZON_DAYS} (a `date` spec in
|
|
236
|
+
* the past, a sun event that never happens, an empty `days` list).
|
|
237
|
+
*/
|
|
238
|
+
function nextOccurrence(spec, afterMs, site, options = {}) {
|
|
239
|
+
const days = options.days;
|
|
240
|
+
if (days !== void 0 && days.length === 0) return null;
|
|
241
|
+
if (spec.kind === "date") {
|
|
242
|
+
const own = LOCAL_DATE_TIME.exec(spec.local)?.[1];
|
|
243
|
+
if (own === void 0 || days !== void 0 && !days.includes(weekdayOfLocalDate(own))) return null;
|
|
244
|
+
const at = occurrenceOn(spec, own, site);
|
|
245
|
+
return at !== null && at > afterMs ? at : null;
|
|
246
|
+
}
|
|
247
|
+
const first = addDays$1(localDateOf(afterMs, site.timeZone), -1);
|
|
248
|
+
for (let i = 0; i < 400; i += 1) {
|
|
249
|
+
const localDate = addDays$1(first, i);
|
|
250
|
+
if (days !== void 0 && !days.includes(weekdayOfLocalDate(localDate))) continue;
|
|
251
|
+
const at = occurrenceOn(spec, localDate, site);
|
|
252
|
+
if (at !== null && at > afterMs) return at;
|
|
253
|
+
}
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Can `spec` be scheduled at this site? A sun spec without a location is
|
|
258
|
+
* REFUSED with its reason — never read as a guessed sunrise. A clock or date
|
|
259
|
+
* spec needs only a zone, and `site` is `null` in that case when there is no
|
|
260
|
+
* location (it is not needed to place them; use {@link siteFor} to read them).
|
|
261
|
+
*/
|
|
262
|
+
function validateTimeSpecForSite(spec, reading) {
|
|
263
|
+
if (!isKnownTimeZone(reading.timeZone)) return {
|
|
264
|
+
ok: false,
|
|
265
|
+
reason: "unknown-time-zone",
|
|
266
|
+
message: `the site time zone "${reading.timeZone}" is not a known IANA zone`
|
|
267
|
+
};
|
|
268
|
+
const site = siteFor(reading);
|
|
269
|
+
if (spec.kind === "sun" && site === null) return {
|
|
270
|
+
ok: false,
|
|
271
|
+
reason: "sun-needs-site-location",
|
|
272
|
+
message: `a ${spec.event} time needs the site location, and none is set — set it in Settings, or use a clock time`
|
|
273
|
+
};
|
|
274
|
+
return {
|
|
275
|
+
ok: true,
|
|
276
|
+
site
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
/** The site, when it has a location; a clock spec on a site without one uses {@link zoneOnlySite}. */
|
|
280
|
+
function siteFor(reading) {
|
|
281
|
+
if (reading.location === null) return null;
|
|
282
|
+
return {
|
|
283
|
+
lat: reading.location.latitude,
|
|
284
|
+
lon: reading.location.longitude,
|
|
285
|
+
timeZone: reading.timeZone
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
/** A site that can place a clock or date spec but no sun event (coordinates are unused by those). */
|
|
289
|
+
function zoneOnlySite(timeZone) {
|
|
290
|
+
return {
|
|
291
|
+
lat: 0,
|
|
292
|
+
lon: 0,
|
|
293
|
+
timeZone,
|
|
294
|
+
zoneOnly: true
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region ../types/dist/esm/time/time-window-flip.mjs
|
|
299
|
+
/**
|
|
300
|
+
* The next instant a wall-clock verdict flips. Kept apart from the judgement so
|
|
301
|
+
* a caller that only asks "inside?" never pays for the search, and so the
|
|
302
|
+
* search takes the verdict as a function: it holds no copy of the window rule.
|
|
303
|
+
*/
|
|
304
|
+
var MS_PER_MINUTE = 6e4;
|
|
305
|
+
var MS_PER_HOUR = 60 * MS_PER_MINUTE;
|
|
306
|
+
var MS_PER_DAY = 24 * MS_PER_HOUR;
|
|
307
|
+
var MINUTES_PER_DAY = 1440;
|
|
308
|
+
var JUMP_CACHE_LIMIT = 64;
|
|
309
|
+
/**
|
|
310
|
+
* Wall-clock minus elapsed time between two instants, as minutes in (-720, 720]:
|
|
311
|
+
* 0 while the zone's offset is unchanged, the shift once it has changed.
|
|
312
|
+
*/
|
|
313
|
+
function driftMinutes(fromMs, toMs, timeZone) {
|
|
314
|
+
const d = ((localMinuteOfDay(toMs, timeZone) - localMinuteOfDay(fromMs, timeZone) - Math.round((toMs - fromMs) / MS_PER_MINUTE)) % MINUTES_PER_DAY + MINUTES_PER_DAY) % MINUTES_PER_DAY;
|
|
315
|
+
return d > MINUTES_PER_DAY / 2 ? d - MINUTES_PER_DAY : d;
|
|
316
|
+
}
|
|
317
|
+
var jumpCache = /* @__PURE__ */ new Map();
|
|
318
|
+
/**
|
|
319
|
+
* The clock jumps of a zone around `nowMs`. The offset is only visible through
|
|
320
|
+
* the wall clock, so it is sampled hourly and each jump located to the minute.
|
|
321
|
+
* Cached per (zone, day bucket): a zone's rules do not change within a process,
|
|
322
|
+
* and every call in a day shares the bucket.
|
|
323
|
+
*/
|
|
324
|
+
function clockJumpsAround(nowMs, timeZone) {
|
|
325
|
+
const bucket = Math.floor(nowMs / MS_PER_DAY);
|
|
326
|
+
const key = `${timeZone}|${bucket}`;
|
|
327
|
+
const cached = jumpCache.get(key);
|
|
328
|
+
if (cached !== void 0) return cached;
|
|
329
|
+
const jumps = [];
|
|
330
|
+
const origin = (bucket - 1) * MS_PER_DAY;
|
|
331
|
+
for (let h = 0; h < 288; h += 1) {
|
|
332
|
+
const a = origin + h * MS_PER_HOUR;
|
|
333
|
+
const b = a + MS_PER_HOUR;
|
|
334
|
+
const total = driftMinutes(a, b, timeZone);
|
|
335
|
+
if (total === 0) continue;
|
|
336
|
+
let lo = a;
|
|
337
|
+
let hi = b;
|
|
338
|
+
while (hi - lo > MS_PER_MINUTE) {
|
|
339
|
+
const mid = Math.floor((lo + hi) / 2 / MS_PER_MINUTE) * MS_PER_MINUTE;
|
|
340
|
+
if (driftMinutes(a, mid, timeZone) === 0) lo = mid;
|
|
341
|
+
else hi = mid;
|
|
342
|
+
}
|
|
343
|
+
jumps.push({
|
|
344
|
+
atMs: hi,
|
|
345
|
+
deltaMs: total * MS_PER_MINUTE
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
if (jumpCache.size >= JUMP_CACHE_LIMIT) jumpCache.clear();
|
|
349
|
+
jumpCache.set(key, jumps);
|
|
350
|
+
return jumps;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* The first instant after `nowMs` at which the verdict differs from the verdict
|
|
354
|
+
* at `nowMs`, or null when it does not within the lookahead. The verdict only
|
|
355
|
+
* changes where the wall clock reads a boundary minute or jumps, so only those
|
|
356
|
+
* instants are asked. A boundary minute a jump repeats is probed one jump-shift
|
|
357
|
+
* from its first occurrence, whatever the shift (an hour, or half of one).
|
|
358
|
+
*/
|
|
359
|
+
function nextVerdictFlip(search) {
|
|
360
|
+
const { nowMs, timeZone, verdictAt } = search;
|
|
361
|
+
const current = verdictAt(nowMs);
|
|
362
|
+
const jumps = clockJumpsAround(nowMs, timeZone);
|
|
363
|
+
const shifts = [...new Set(jumps.map((j) => Math.abs(j.deltaMs)))];
|
|
364
|
+
const candidates = new Set(jumps.map((j) => j.atMs));
|
|
365
|
+
for (let offset = -1; offset <= search.lookaheadDays + 1; offset += 1) for (const boundary of search.boundaries) {
|
|
366
|
+
const base = boundary.baseOn(offset);
|
|
367
|
+
if (base === null) continue;
|
|
368
|
+
for (const t of [base, ...shifts.flatMap((s) => [base - s, base + s])]) if (localMinuteOfDay(t, timeZone) === boundary.minuteOfDay) candidates.add(t);
|
|
369
|
+
}
|
|
370
|
+
return [...candidates].filter((t) => t > nowMs).sort((a, b) => a - b).find((t) => verdictAt(t) !== current) ?? null;
|
|
371
|
+
}
|
|
372
|
+
//#endregion
|
|
373
|
+
//#region ../types/dist/esm/time/time-window.mjs
|
|
374
|
+
/**
|
|
375
|
+
* A daily window as a STATE: is this instant inside it, and when does that
|
|
376
|
+
* next change? Pure — the answer is built per local date from
|
|
377
|
+
* {@link occurrenceOn}, so a DST change needs no special case.
|
|
378
|
+
*
|
|
379
|
+
* Rules:
|
|
380
|
+
* - A window whose `to` is not after its `from` on the same local date WRAPS:
|
|
381
|
+
* it runs from `from` on day D to `to` on D+1.
|
|
382
|
+
* - `days` names the local day a window STARTS on. 22:00-06:00 on weekdays is
|
|
383
|
+
* inside at 01:00 Saturday (it started Friday). With `days` and no
|
|
384
|
+
* `between` the window is the whole local day.
|
|
385
|
+
* - A sun event that does not happen on a day (polar day or night) gives that
|
|
386
|
+
* day no window. A sun event on a site WITHOUT a location (or an unknown
|
|
387
|
+
* zone) cannot be judged at all: the result is `unknown`, never a guess.
|
|
388
|
+
*/
|
|
389
|
+
/** A named daily window, resolved to a sun range: `night` is sunset to sunrise, `day` the reverse. */
|
|
390
|
+
var TimeWindowPresetSchema = /* @__PURE__ */ z.enum(["day", "night"]);
|
|
391
|
+
var timeWindowShape = {
|
|
392
|
+
between: /* @__PURE__ */ z.object({
|
|
393
|
+
from: TimeSpecSchema,
|
|
394
|
+
to: TimeSpecSchema
|
|
395
|
+
}).optional(),
|
|
396
|
+
days: /* @__PURE__ */ z.array(WeekdayKeySchema).min(1).max(7).readonly().optional(),
|
|
397
|
+
preset: /* @__PURE__ */ TimeWindowPresetSchema.optional()
|
|
398
|
+
};
|
|
399
|
+
var TimeWindowObjectSchema = /* @__PURE__ */ z.object(timeWindowShape);
|
|
400
|
+
/** The cross-field rules of a window, for a schema that embeds the window's fields. */
|
|
401
|
+
function refineTimeWindow(window, ctx) {
|
|
402
|
+
if (window.between === void 0 && window.days === void 0 && window.preset === void 0) ctx.addIssue({
|
|
403
|
+
code: "custom",
|
|
404
|
+
message: "a time window needs a between range, a preset, days, or a combination"
|
|
405
|
+
});
|
|
406
|
+
if (window.preset !== void 0 && window.between !== void 0) ctx.addIssue({
|
|
407
|
+
code: "custom",
|
|
408
|
+
message: "a preset and a between range name the same thing: give one",
|
|
409
|
+
path: ["preset"]
|
|
410
|
+
});
|
|
411
|
+
for (const end of ["from", "to"]) if (window.between?.[end].kind === "date") ctx.addIssue({
|
|
412
|
+
code: "custom",
|
|
413
|
+
message: "a one-date time cannot bound a daily window: use a clock time or a sun event",
|
|
414
|
+
path: ["between", end]
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
var TimeWindowSchema = /* @__PURE__ */ TimeWindowObjectSchema.superRefine(refineTimeWindow);
|
|
418
|
+
var SUNSET = {
|
|
419
|
+
kind: "sun",
|
|
420
|
+
event: "sunset",
|
|
421
|
+
offsetMin: 0
|
|
422
|
+
};
|
|
423
|
+
var SUNRISE = {
|
|
424
|
+
kind: "sun",
|
|
425
|
+
event: "sunrise",
|
|
426
|
+
offsetMin: 0
|
|
427
|
+
};
|
|
428
|
+
var PRESET_RANGE = {
|
|
429
|
+
night: {
|
|
430
|
+
from: SUNSET,
|
|
431
|
+
to: SUNRISE
|
|
432
|
+
},
|
|
433
|
+
day: {
|
|
434
|
+
from: SUNRISE,
|
|
435
|
+
to: SUNSET
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
/** The window with its preset expanded into a `between` range (both ends are sun events). */
|
|
439
|
+
function expandTimeWindowPreset(window) {
|
|
440
|
+
if (window.preset === void 0) return window;
|
|
441
|
+
return {
|
|
442
|
+
...window.days === void 0 ? {} : { days: window.days },
|
|
443
|
+
between: PRESET_RANGE[window.preset]
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
var MIDNIGHT = {
|
|
447
|
+
kind: "clock",
|
|
448
|
+
hh: 0,
|
|
449
|
+
mm: 0
|
|
450
|
+
};
|
|
451
|
+
/** Start dates looked at for a boundary: yesterday .. the day after tomorrow. */
|
|
452
|
+
var LOOKAHEAD_DAYS = 2;
|
|
453
|
+
/** A weekday restriction repeats every 7 days: its next boundary is within a week plus the day it started on. */
|
|
454
|
+
var WEEKDAY_LOOKAHEAD_DAYS = 8;
|
|
455
|
+
function addDays(localDate, days) {
|
|
456
|
+
const [y, m, d] = localDate.split("-").map(Number);
|
|
457
|
+
return new Date(Date.UTC(y ?? 0, (m ?? 1) - 1, (d ?? 1) + days)).toISOString().slice(0, 10);
|
|
458
|
+
}
|
|
459
|
+
function unresolvable(window, site) {
|
|
460
|
+
if (!isKnownTimeZone(site.timeZone)) return `the site time zone "${site.timeZone}" is not a known IANA zone`;
|
|
461
|
+
if (window.between !== void 0 && (window.between.from.kind === "sun" || window.between.to.kind === "sun") && site.zoneOnly === true) return "a sun time needs the site location, and none is set";
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
/** The interval that STARTS on local day `startDate`, or null when that day has none. */
|
|
465
|
+
function intervalStartingOn(window, startDate, site) {
|
|
466
|
+
if (window.days !== void 0 && !window.days.includes(weekdayOfLocalDate(startDate))) return null;
|
|
467
|
+
if (window.between === void 0) {
|
|
468
|
+
const start = occurrenceOn(MIDNIGHT, startDate, site);
|
|
469
|
+
const end = occurrenceOn(MIDNIGHT, addDays(startDate, 1), site);
|
|
470
|
+
return start === null || end === null ? null : {
|
|
471
|
+
start,
|
|
472
|
+
end
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
const start = occurrenceOn(window.between.from, startDate, site);
|
|
476
|
+
const sameDayEnd = occurrenceOn(window.between.to, startDate, site);
|
|
477
|
+
if (start === null || sameDayEnd === null) return null;
|
|
478
|
+
if (sameDayEnd > start) return {
|
|
479
|
+
start,
|
|
480
|
+
end: sameDayEnd
|
|
481
|
+
};
|
|
482
|
+
const end = occurrenceOn(window.between.to, addDays(startDate, 1), site);
|
|
483
|
+
return end === null || end <= start ? null : {
|
|
484
|
+
start,
|
|
485
|
+
end
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
var MINUTES_PER_HOUR = 60;
|
|
489
|
+
/**
|
|
490
|
+
* A window whose ends are both wall-clock times names MINUTES OF THE DAY, so it
|
|
491
|
+
* is judged on the wall clock itself: the hour a fall-back change repeats is
|
|
492
|
+
* inside a window that names it on both passes, and a window wholly inside the
|
|
493
|
+
* hour a spring-forward change skips never matches. `null` when an end is a sun
|
|
494
|
+
* event or a date, which are instants and are judged as such.
|
|
495
|
+
*/
|
|
496
|
+
function insideOnWallClock(window, nowMs, today, site) {
|
|
497
|
+
const between = window.between;
|
|
498
|
+
if (between === void 0 || between.from.kind !== "clock" || between.to.kind !== "clock") return null;
|
|
499
|
+
const start = between.from.hh * MINUTES_PER_HOUR + between.from.mm;
|
|
500
|
+
const end = between.to.hh * MINUTES_PER_HOUR + between.to.mm;
|
|
501
|
+
const minute = localMinuteOfDay(nowMs, site.timeZone);
|
|
502
|
+
const listed = (date) => window.days === void 0 || window.days.includes(weekdayOfLocalDate(date));
|
|
503
|
+
if (start < end) return listed(today) && minute >= start && minute < end;
|
|
504
|
+
return listed(today) && minute >= start || listed(addDays(today, -1)) && minute < end;
|
|
505
|
+
}
|
|
506
|
+
/** How many local days ahead a boundary is searched: a full week when a weekday restriction applies. */
|
|
507
|
+
function lookaheadFor(window) {
|
|
508
|
+
return window.days === void 0 ? LOOKAHEAD_DAYS : WEEKDAY_LOOKAHEAD_DAYS;
|
|
509
|
+
}
|
|
510
|
+
/** The first instant after `nowMs` the clock window's verdict flips; null for a sun or date window. */
|
|
511
|
+
function nextWallClockFlip(window, nowMs, site) {
|
|
512
|
+
const between = window.between;
|
|
513
|
+
if (between === void 0 || between.from.kind !== "clock" || between.to.kind !== "clock") return null;
|
|
514
|
+
const today = localDateOf(nowMs, site.timeZone);
|
|
515
|
+
const boundaryOf = (spec, minuteOfDay) => ({
|
|
516
|
+
minuteOfDay,
|
|
517
|
+
baseOn: (dayOffset) => occurrenceOn(spec, addDays(today, dayOffset), site)
|
|
518
|
+
});
|
|
519
|
+
return nextVerdictFlip({
|
|
520
|
+
nowMs,
|
|
521
|
+
timeZone: site.timeZone,
|
|
522
|
+
lookaheadDays: lookaheadFor(window),
|
|
523
|
+
boundaries: [
|
|
524
|
+
boundaryOf(between.from, between.from.hh * MINUTES_PER_HOUR + between.from.mm),
|
|
525
|
+
boundaryOf(between.to, between.to.hh * MINUTES_PER_HOUR + between.to.mm),
|
|
526
|
+
boundaryOf(MIDNIGHT, 0)
|
|
527
|
+
],
|
|
528
|
+
verdictAt: (t) => insideOnWallClock(window, t, localDateOf(t, site.timeZone), site)
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
/** Is `nowMs` inside the window. False when the window cannot be placed on the site (never a guess). */
|
|
532
|
+
function isWithinTimeWindow(window, nowMs, site) {
|
|
533
|
+
return judge(window, nowMs, site, false).inside;
|
|
534
|
+
}
|
|
535
|
+
/** The full judgement, including the next change. Costlier than {@link isWithinTimeWindow}: ask only when the boundary is needed. */
|
|
536
|
+
function judgeTimeWindow(rawWindow, nowMs, site) {
|
|
537
|
+
return judge(rawWindow, nowMs, site, true);
|
|
538
|
+
}
|
|
539
|
+
function judge(rawWindow, nowMs, site, withWallClockNext) {
|
|
540
|
+
const window = expandTimeWindowPreset(rawWindow);
|
|
541
|
+
const blocked = unresolvable(window, site);
|
|
542
|
+
if (blocked !== null) return {
|
|
543
|
+
inside: false,
|
|
544
|
+
unknown: true,
|
|
545
|
+
nextChangeAtMs: null,
|
|
546
|
+
why: `cannot be judged: ${blocked}`
|
|
547
|
+
};
|
|
548
|
+
const today = localDateOf(nowMs, site.timeZone);
|
|
549
|
+
let inside = false;
|
|
550
|
+
let next = null;
|
|
551
|
+
const wallClock = insideOnWallClock(window, nowMs, today, site);
|
|
552
|
+
if (wallClock !== null) {
|
|
553
|
+
inside = wallClock;
|
|
554
|
+
next = withWallClockNext ? nextWallClockFlip(window, nowMs, site) : null;
|
|
555
|
+
} else {
|
|
556
|
+
const reach = withWallClockNext ? lookaheadFor(window) : LOOKAHEAD_DAYS;
|
|
557
|
+
for (let offset = -1; offset <= reach; offset += 1) {
|
|
558
|
+
const interval = intervalStartingOn(window, addDays(today, offset), site);
|
|
559
|
+
if (interval === null) continue;
|
|
560
|
+
if (interval.start <= nowMs && nowMs < interval.end) inside = true;
|
|
561
|
+
for (const boundary of [interval.start, interval.end]) if (boundary > nowMs && (next === null || boundary < next)) next = boundary;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (window.between === void 0) {
|
|
565
|
+
const midnight = occurrenceOn(MIDNIGHT, addDays(today, 1), site);
|
|
566
|
+
if (midnight !== null && midnight > nowMs && (next === null || midnight < next)) next = midnight;
|
|
567
|
+
}
|
|
568
|
+
const days = window.days === void 0 ? "" : ` on ${window.days.join(", ")}`;
|
|
569
|
+
const span = rawWindow.preset !== void 0 ? `the ${rawWindow.preset}` : window.between === void 0 ? "the whole day" : "the window";
|
|
570
|
+
return {
|
|
571
|
+
inside,
|
|
572
|
+
unknown: false,
|
|
573
|
+
nextChangeAtMs: next,
|
|
574
|
+
why: inside ? `inside ${span}${days}` : `outside ${span}${days}`
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
//#endregion
|
|
578
|
+
export { zoneOnlySite as _, judgeTimeWindow as a, WeekdayKeySchema as c, nextOccurrence as d, occurrenceOn as f, weekdayOfLocalDate as g, weekdayKeyOfIndex as h, isWithinTimeWindow as i, isKnownTimeZone as l, validateTimeSpecForSite as m, TimeWindowSchema as n, refineTimeWindow as o, siteFor as p, expandTimeWindowPreset as r, TimeSpecSchema as s, TimeWindowObjectSchema as t, localDateOf as u };
|
|
Binary file
|
|
Binary file
|