@marktiderman/genesis-core 2.4.1 → 2.6.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/README.md +42 -0
- package/dist/{chunk-ZIMQUFXD.js → chunk-37RWGNIO.js} +9 -4
- package/dist/chunk-37RWGNIO.js.map +1 -0
- package/dist/chunk-BIIENNTW.js +497 -0
- package/dist/chunk-BIIENNTW.js.map +1 -0
- package/dist/{chunk-XMC4EJUE.js → chunk-EHFYSJJA.js} +6 -3
- package/dist/chunk-EHFYSJJA.js.map +1 -0
- package/dist/chunk-LZVU5NGV.js +82 -0
- package/dist/chunk-LZVU5NGV.js.map +1 -0
- package/dist/{chunk-X6EO3XBB.js → chunk-OKCSGNCU.js} +9 -4
- package/dist/chunk-OKCSGNCU.js.map +1 -0
- package/dist/{chunk-5NEOX2N7.js → chunk-OWYX4BEI.js} +4 -4
- package/dist/{chunk-5NEOX2N7.js.map → chunk-OWYX4BEI.js.map} +1 -1
- package/dist/csv.d.ts +1 -3
- package/dist/dates.d.ts +199 -1
- package/dist/dates.js +1 -1
- package/dist/errors.d.ts +8 -1
- package/dist/errors.js +1 -1
- package/dist/form-types.d.ts +1 -70
- package/dist/hooks/index.d.ts +3 -4
- package/dist/hooks/index.js +7 -6
- package/dist/hooks/mutation-mode.d.ts +1 -3
- package/dist/hooks/related-keys.d.ts +1 -3
- package/dist/hooks/use-capabilities.d.ts +1 -2
- package/dist/hooks/use-infinite-resource.d.ts +1 -3
- package/dist/hooks/use-link-options.d.ts +58 -0
- package/dist/hooks/use-link-options.js +10 -0
- package/dist/hooks/use-link-options.js.map +1 -0
- package/dist/hooks/use-live.d.ts +1 -3
- package/dist/hooks/use-one.d.ts +1 -3
- package/dist/hooks/use-relation-label.d.ts +8 -4
- package/dist/hooks/use-relation-label.js +1 -1
- package/dist/hooks/use-resource-form.d.ts +1 -3
- package/dist/hooks/use-resource-form.js +2 -2
- package/dist/hooks/use-resource.d.ts +1 -3
- package/dist/hooks/use-write.d.ts +1 -3
- package/dist/index.d.ts +5 -6
- package/dist/index.js +7 -6
- package/dist/provider/index.d.ts +4 -6
- package/dist/resource-view/index.d.ts +118 -4
- package/dist/resource-view/index.js +148 -35
- package/dist/resource-view/index.js.map +1 -1
- package/dist/schema/index.d.ts +3 -5
- package/dist/testing/index.d.ts +2 -4
- package/dist/types-r_Rlw7BB.d.ts +800 -0
- package/dist/{write-outcome-CFnpciUI.d.ts → write-outcome-BWV34wh5.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/chunk-3B4IFDMK.js +0 -117
- package/dist/chunk-3B4IFDMK.js.map +0 -1
- package/dist/chunk-X6EO3XBB.js.map +0 -1
- package/dist/chunk-XMC4EJUE.js.map +0 -1
- package/dist/chunk-ZIMQUFXD.js.map +0 -1
- package/dist/types-CXhqXPN1.d.ts +0 -367
- package/dist/types-o8j7g6O6.d.ts +0 -331
package/README.md
CHANGED
|
@@ -686,4 +686,46 @@ const { start, end } = dayRangeIn(today, profile.timeZone); // the instants, for
|
|
|
686
686
|
- `addDays`, `daysBetween`, `weekdayOf`, `startOfWeek` and `isDay`: plain calendar arithmetic on
|
|
687
687
|
`YYYY-MM-DD` strings, with no zone involved. They refuse days that don't exist, such as `2026-02-30`.
|
|
688
688
|
|
|
689
|
+
### Calendar ranges
|
|
690
|
+
|
|
691
|
+
Ranges are `{ start, end }` days, `end` exclusive, for the windows a calendar shows:
|
|
692
|
+
|
|
693
|
+
- `startOfMonth`, `addMonths` (31 January + 1 is the last day of February), `daysInMonth`,
|
|
694
|
+
`startOfQuarter`, `addWeeks`.
|
|
695
|
+
- `monthRange(day)`, `quarterRange(day)`, `weeksRange(day, weeks, weekStartsOn)` (whole weeks from
|
|
696
|
+
the week `day` is in) and `monthGridRange(day, weekStartsOn)` (the whole weeks covering a month).
|
|
697
|
+
- `eachDay(range)` lists the days; `rangeIn(range, zone)` gives the instants to filter a timestamp by.
|
|
698
|
+
- `instantIn(day, "09:30", zone)` and `wallTimeIn(zone, at)` convert between a wall time and an
|
|
699
|
+
instant. A time the clock skips moves forward by the jump; a time it shows twice is the first.
|
|
700
|
+
- `readEventTime(value, { dateOnly, timeZone })` reads a stored date or timestamp as a day or an
|
|
701
|
+
instant; a timestamp without a zone is a wall time on `timeZone`'s clock.
|
|
702
|
+
|
|
703
|
+
### Repeating events
|
|
704
|
+
|
|
705
|
+
`expandRecurrence` lists a series' occurrences inside a window, with no dependencies:
|
|
706
|
+
|
|
707
|
+
```ts
|
|
708
|
+
import { expandRecurrence } from "@marktiderman/genesis-core/dates";
|
|
709
|
+
|
|
710
|
+
const { occurrences, truncated } = expandRecurrence({
|
|
711
|
+
rule: "FREQ=MONTHLY;BYDAY=2MO;COUNT=10",
|
|
712
|
+
start: { day: "2026-11-09", time: "18:30", timeZone: "America/Denver" },
|
|
713
|
+
exdates: ["2026-12-14"],
|
|
714
|
+
window: { start: "2026-11-01", end: "2027-03-01" },
|
|
715
|
+
}); // occurrences: [{ day, start }…], 18:30 in Denver whatever the daylight saving
|
|
716
|
+
if (truncated) {
|
|
717
|
+
// more than `limit` (default 1,000) in the window
|
|
718
|
+
}
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
- The rule is RFC 5545's: FREQ (DAILY, WEEKLY, MONTHLY, YEARLY), INTERVAL, COUNT, UNTIL, BYDAY
|
|
722
|
+
(with positions such as `2MO` or `-1FR` for MONTHLY and YEARLY), BYMONTHDAY, BYMONTH and WKST.
|
|
723
|
+
Any other part, a part set twice, or a combination the RFC forbids throws a `RangeError` naming
|
|
724
|
+
it (`parseRRule` does the same checks, and a rule passed as an object gets them too).
|
|
725
|
+
- A timed series keeps its wall time on its own zone's clock; an all-day series (`start` a day) has
|
|
726
|
+
days only. COUNT counts from the start whatever the window, EXDATE removes after counting, and a
|
|
727
|
+
floating UNTIL is read on the series' clock.
|
|
728
|
+
- `window` is required, and `limit` caps the result. Widen the window's start by an event's length
|
|
729
|
+
to catch ones that began earlier.
|
|
730
|
+
|
|
689
731
|
In SQL, the same day is `(now() at time zone person_zone)::date`.
|
|
@@ -5,7 +5,12 @@ import { isDataWriteError } from './chunk-LG6TUBVM.js';
|
|
|
5
5
|
// src/errors.ts
|
|
6
6
|
function isDevelopment() {
|
|
7
7
|
if (typeof __DEV__ !== "undefined") return Boolean(__DEV__);
|
|
8
|
-
|
|
8
|
+
let env;
|
|
9
|
+
try {
|
|
10
|
+
env = process.env.NODE_ENV;
|
|
11
|
+
} catch {
|
|
12
|
+
env = void 0;
|
|
13
|
+
}
|
|
9
14
|
return env !== "production";
|
|
10
15
|
}
|
|
11
16
|
var defaultErrorReporter = (error, context) => {
|
|
@@ -149,6 +154,6 @@ function classifyError(error, options = {}) {
|
|
|
149
154
|
return { ...base, message };
|
|
150
155
|
}
|
|
151
156
|
|
|
152
|
-
export { classifyError, defaultErrorReporter, errorMessages, getErrorReporter, reportError, setErrorReporter };
|
|
153
|
-
//# sourceMappingURL=chunk-
|
|
154
|
-
//# sourceMappingURL=chunk-
|
|
157
|
+
export { classifyError, defaultErrorReporter, errorMessages, getErrorReporter, isDevelopment, reportError, setErrorReporter };
|
|
158
|
+
//# sourceMappingURL=chunk-37RWGNIO.js.map
|
|
159
|
+
//# sourceMappingURL=chunk-37RWGNIO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts"],"names":[],"mappings":";;;;;AA6CO,SAAS,aAAA,GAAyB;AACvC,EAAA,IAAI,OAAO,OAAA,KAAY,WAAA,EAAa,OAAO,QAAQ,OAAO,CAAA;AAC1D,EAAA,IAAI,GAAA;AACJ,EAAA,IAAI;AAGF,IAAA,GAAA,GAAM,QAAQ,GAAA,CAAI,QAAA;AAAA,EACpB,CAAA,CAAA,MAAQ;AACN,IAAA,GAAA,GAAM,MAAA;AAAA,EACR;AACA,EAAA,OAAO,GAAA,KAAQ,YAAA;AACjB;AAGO,IAAM,oBAAA,GAAsC,CAAC,KAAA,EAAO,OAAA,KAAY;AACrE,EAAA,IAA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A,EAAK;AAC5C;AAWO,SAAS,aAAA,CAAc,KAAA,EAAgB,OAAA,GAAgC,EAAC,EAAoB;AACjG,EAAA,IAAI,IAAA;AACJ,EAAA,IAAI;AACF,IAAA,IAAA,GAAO,MAAA,CAAO,OAAO,OAAO,CAAA;AAAA,EAC9B,CAAA,CAAA,MAAQ;AAEN,IAAA,IAAA,GAAO,EAAE,IAAA,EAAM,YAAA,EAAc,MAAA,EAAQ,IAAA,EAAK;AAAA,EAC5C;AACA,EAAA,MAAM,OAAA,GAAU,QAAQ,QAAA,GAAW,IAAA,CAAK,IAAI,CAAA,IAAK,aAAA,CAAc,KAAK,IAAI,CAAA;AACxE,EAAA,OAAO,EAAE,GAAG,IAAA,EAAM,OAAA,EAAQ;AAC5B","file":"chunk-37RWGNIO.js","sourcesContent":["// ---------------------------------------------------------------------------\n// Errors: one way for every Genesis package to report a caught error, and one\n// way to say what kind of error it is.\n//\n// `reportError(error, context)` is the seam a package calls when it catches\n// something it can't handle itself (a card's action that threw, a draft that\n// couldn't be saved). The host app decides where it goes: a native app's\n// observability block registers itself with `setErrorReporter` and sends it,\n// scrubbed, to Sentry; with nothing registered it is written with\n// `console.warn` in development and dropped in production.\n//\n// `classifyError(error)` sorts anything thrown into a few kinds a screen can\n// act on (offline, signed out, refused, gone, conflict, bad input, a bug),\n// with a sentence that is safe to show and whether it is worth reporting.\n// It is built on the provider's read and write outcomes.\n// ---------------------------------------------------------------------------\n\nimport { readOutcomeFromCode, writeOutcomeFromCode } from \"./provider/postgrest-errors\";\nimport { isDataReadError } from \"./schema/read-outcome\";\nimport { isDataWriteError } from \"./schema/write-outcome\";\n\n/** Where a reported error came from. */\nexport interface ErrorReportContext {\n /**\n * Which part caught it, as `package:part` (`chat:attachment-action`,\n * `forms-native:draft-save`). Low-cardinality: never an id or text.\n */\n source: string;\n /** True when the app could not go on. Default false: a package that reports has handled it. */\n fatal?: boolean;\n /** Low-cardinality labels (`query.key: \"tasks\"`), never ids, emails or text someone typed. */\n tags?: Readonly<Record<string, string>>;\n}\n\n/** Where `reportError` sends errors. A throw inside it is ignored. */\nexport type ErrorReporter = (error: unknown, context: ErrorReportContext) => void;\n\ndeclare const __DEV__: boolean | undefined;\n\n/**\n * True in a development build: `__DEV__` on React Native, else `NODE_ENV`, else true (no bundler\n * and no `process`). For development-only hints.\n *\n * @stability Beta\n */\nexport function isDevelopment(): boolean {\n if (typeof __DEV__ !== \"undefined\") return Boolean(__DEV__);\n let env: string | undefined;\n try {\n // Written out in full: bundlers (Vite, webpack, esbuild) replace exactly `process.env.NODE_ENV`\n // at build time, and a browser has no `process` to read at run time.\n env = process.env.NODE_ENV;\n } catch {\n env = undefined;\n }\n return env !== \"production\";\n}\n\n/** The reporter used when the app registered none: `console.warn` in development, nothing in production. */\nexport const defaultErrorReporter: ErrorReporter = (error, context) => {\n if (!isDevelopment()) return;\n // genesis-allow-console: the development fallback of the reporting seam itself.\n console.warn(`[genesis] ${context.source}:`, error);\n};\n\n// Kept on globalThis so two copies of this package (a bundling slip) still share one reporter.\nconst KEY = Symbol.for(\"genesis.errorReporter\");\ntype Holder = { [KEY]?: ErrorReporter };\n\n/** The reporter `reportError` uses now. */\nexport function getErrorReporter(): ErrorReporter {\n return (globalThis as Holder)[KEY] ?? defaultErrorReporter;\n}\n\n/**\n * Send every `reportError` to `reporter` (`null` puts the default back).\n * Returns a function that restores the reporter that was there before.\n * The native observability block calls it when it is created.\n */\nexport function setErrorReporter(reporter: ErrorReporter | null): () => void {\n const holder = globalThis as Holder;\n const previous = holder[KEY];\n if (reporter) holder[KEY] = reporter;\n else delete holder[KEY];\n return () => {\n if (previous) holder[KEY] = previous;\n else delete holder[KEY];\n };\n}\n\n/**\n * Report an error a package caught and handled. Never throws: a failing\n * reporter must not take the caller (an event handler, a render) down.\n * `context` may be just the source.\n */\nexport function reportError(error: unknown, context: ErrorReportContext | string): void {\n const full: ErrorReportContext = typeof context === \"string\" ? { source: context } : context;\n try {\n getErrorReporter()(error, full);\n } catch {\n // A failing reporter is ignored; reporting is never worth a second error.\n }\n}\n\n// ---------------------------------------------------------------------------\n// classifyError\n// ---------------------------------------------------------------------------\n\n/**\n * - `offline`: the request never reached the server (no network).\n * - `unauthenticated`: nobody is signed in, or the session ended.\n * - `forbidden`: the server refused this user.\n * - `not-found`: the record doesn't exist, or this user can't see it.\n * - `conflict`: someone else changed it first, or it already exists.\n * - `invalid`: the request or a value in it was rejected.\n * - `unexpected`: anything else (a bug, a server error).\n */\nexport type ErrorKind = \"offline\" | \"unauthenticated\" | \"forbidden\" | \"not-found\" | \"conflict\" | \"invalid\" | \"unexpected\";\n\n/** The sentence shown for each kind. Override any of them with `classifyError(e, { messages })`. */\nexport type ErrorMessages = Readonly<Record<ErrorKind, string>>;\n\n/** The English catalogue. Plain words, never the store's text. */\nexport const errorMessages: ErrorMessages = {\n offline: \"You're offline. Check your connection and try again.\",\n unauthenticated: \"Your session has ended. Sign in again to continue.\",\n forbidden: \"You don't have permission to do that.\",\n \"not-found\": \"This isn't here any more, or you can't see it.\",\n conflict: \"Someone else changed this first. Refresh and try again.\",\n invalid: \"Something in this couldn't be accepted. Check it and try again.\",\n unexpected: \"Something went wrong. Try again.\",\n};\n\nexport interface ClassifiedError {\n kind: ErrorKind;\n /** Safe to show: from the messages catalogue, never the error's own text. */\n message: string;\n /** Worth reporting to a crash tracker: a bug or a server failure, not something the user or the network caused. */\n report: boolean;\n}\n\nexport interface ClassifyErrorOptions {\n /** Reworded or translated sentences; what you leave out stays English. */\n messages?: Partial<ErrorMessages>;\n /** True when the device knows it is offline (TanStack's `onlineManager`, NetInfo). */\n isOffline?: () => boolean;\n}\n\n// The text each runtime's fetch throws when the request never left the device.\nconst NETWORK_MESSAGES = [\n /^network request failed$/i, // React Native\n /^failed to fetch$/i, // Chromium\n /^load failed$/i, // Safari\n /^networkerror when attempting to fetch resource\\.?$/i, // Firefox\n /^network error$/i,\n /^the internet connection appears to be offline\\.?$/i,\n];\n// Supabase's wrappers around a fetch that never reached the server.\nconst NETWORK_NAMES = new Set([\"AuthRetryableFetchError\", \"FunctionsFetchError\", \"StorageUnknownError\"]);\n\nfunction field(error: unknown, name: string): unknown {\n return typeof error === \"object\" && error !== null ? (error as Record<string, unknown>)[name] : undefined;\n}\n\nfunction isNetworkError(error: unknown): boolean {\n const name = field(error, \"name\");\n const message = field(error, \"message\");\n if (typeof name === \"string\" && NETWORK_NAMES.has(name)) {\n // StorageUnknownError covers other failures too; only its network form counts.\n return name !== \"StorageUnknownError\" || (typeof message === \"string\" && NETWORK_MESSAGES.some((re) => re.test(message)));\n }\n return typeof message === \"string\" && NETWORK_MESSAGES.some((re) => re.test(message.trim()));\n}\n\nfunction fromStatus(status: number): Omit<ClassifiedError, \"message\"> | null {\n if (status === 401) return { kind: \"unauthenticated\", report: false };\n if (status === 403) return { kind: \"forbidden\", report: false };\n if (status === 404 || status === 410) return { kind: \"not-found\", report: false };\n if (status === 409 || status === 412) return { kind: \"conflict\", report: false };\n if (status === 400 || status === 422) return { kind: \"invalid\", report: true };\n if (status === 429) return { kind: \"unexpected\", report: false };\n return null;\n}\n\nfunction kindOf(error: unknown, options: ClassifyErrorOptions): Omit<ClassifiedError, \"message\"> {\n if (isDataWriteError(error)) {\n switch (error.outcome) {\n case \"conflict\":\n case \"duplicate\":\n return { kind: \"conflict\", report: false };\n case \"gone\":\n return { kind: \"not-found\", report: false };\n case \"forbidden\":\n return { kind: \"forbidden\", report: false };\n case \"invalid\":\n return { kind: \"invalid\", report: false };\n case \"unauthenticated\":\n return { kind: \"unauthenticated\", report: false };\n default:\n // `error` and `audit_failed`: a network failure surfaces here as the write's cause.\n if (isNetworkError(error.cause ?? error) || options.isOffline?.()) return { kind: \"offline\", report: false };\n return { kind: \"unexpected\", report: true };\n }\n }\n if (isDataReadError(error)) {\n switch (error.outcome) {\n case \"unauthenticated\":\n return { kind: \"unauthenticated\", report: false };\n case \"forbidden\":\n return { kind: \"forbidden\", report: false };\n case \"gone\":\n return { kind: \"not-found\", report: false };\n case \"invalid\":\n // The request itself was wrong (an unknown column): a bug worth seeing.\n return { kind: \"invalid\", report: true };\n default:\n if (isNetworkError(error.cause ?? error) || options.isOffline?.()) return { kind: \"offline\", report: false };\n return { kind: \"unexpected\", report: true };\n }\n }\n if (isNetworkError(error)) return { kind: \"offline\", report: false };\n const code = field(error, \"code\");\n if (typeof code === \"string\" && code) {\n const read = readOutcomeFromCode(code);\n if (read === \"invalid\" && writeOutcomeFromCode(code) === \"error\") return { kind: \"invalid\", report: true };\n switch (writeOutcomeFromCode(code)) {\n case \"unauthenticated\":\n return { kind: \"unauthenticated\", report: false };\n case \"forbidden\":\n return { kind: \"forbidden\", report: false };\n case \"gone\":\n return { kind: \"not-found\", report: false };\n case \"duplicate\":\n return { kind: \"conflict\", report: false };\n case \"invalid\":\n return { kind: \"invalid\", report: false };\n default:\n break;\n }\n }\n const name = field(error, \"name\");\n if (name === \"AuthSessionMissingError\") return { kind: \"unauthenticated\", report: false };\n const status = field(error, \"status\") ?? field(error, \"statusCode\");\n const numeric = typeof status === \"number\" ? status : typeof status === \"string\" ? Number(status) : NaN;\n if (Number.isInteger(numeric)) {\n const byStatus = fromStatus(numeric);\n if (byStatus) return byStatus;\n }\n if (options.isOffline?.()) return { kind: \"offline\", report: false };\n return { kind: \"unexpected\", report: true };\n}\n\n/**\n * What kind of error this is, a sentence that is safe to show, and whether it\n * is worth reporting. Understands the provider's `DataWriteError` and\n * `DataReadError`, Postgres and PostgREST codes, HTTP statuses, Supabase's\n * auth and fetch errors, and each runtime's \"network request failed\".\n *\n * Use it for a toast (`toast.error(classifyError(e).message)`) and to decide\n * whether to report (`if (classifyError(e).report) reportError(e, …)`).\n */\nexport function classifyError(error: unknown, options: ClassifyErrorOptions = {}): ClassifiedError {\n let base: Omit<ClassifiedError, \"message\">;\n try {\n base = kindOf(error, options);\n } catch {\n // A getter that throws on an exotic value: still an answer, never a second error.\n base = { kind: \"unexpected\", report: true };\n }\n const message = options.messages?.[base.kind] ?? errorMessages[base.kind];\n return { ...base, message };\n}\n"]}
|
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
// src/dates.ts
|
|
2
|
+
var DAY = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
3
|
+
function isDay(value) {
|
|
4
|
+
if (typeof value !== "string") return false;
|
|
5
|
+
const m = DAY.exec(value);
|
|
6
|
+
if (!m) return false;
|
|
7
|
+
const d = new Date(Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3])));
|
|
8
|
+
return d.getUTCFullYear() === Number(m[1]) && d.getUTCMonth() === Number(m[2]) - 1 && d.getUTCDate() === Number(m[3]);
|
|
9
|
+
}
|
|
10
|
+
function assertDay(day, where) {
|
|
11
|
+
if (!isDay(day)) throw new RangeError(`${where}: "${String(day)}" is not a YYYY-MM-DD day`);
|
|
12
|
+
const m = DAY.exec(day);
|
|
13
|
+
return [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
14
|
+
}
|
|
15
|
+
var formatters = /* @__PURE__ */ new Map();
|
|
16
|
+
function isTimeZone(zone) {
|
|
17
|
+
if (typeof zone !== "string" || !zone) return false;
|
|
18
|
+
if (formatters.has(zone)) return true;
|
|
19
|
+
try {
|
|
20
|
+
new Intl.DateTimeFormat("en-US", { timeZone: zone });
|
|
21
|
+
return true;
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function deviceTimeZone() {
|
|
27
|
+
try {
|
|
28
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
|
|
29
|
+
} catch {
|
|
30
|
+
return "UTC";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function partsFormatter(zone) {
|
|
34
|
+
let f = formatters.get(zone);
|
|
35
|
+
if (!f) {
|
|
36
|
+
f = new Intl.DateTimeFormat("en-US", {
|
|
37
|
+
timeZone: zone,
|
|
38
|
+
hourCycle: "h23",
|
|
39
|
+
year: "numeric",
|
|
40
|
+
month: "2-digit",
|
|
41
|
+
day: "2-digit",
|
|
42
|
+
hour: "2-digit",
|
|
43
|
+
minute: "2-digit",
|
|
44
|
+
second: "2-digit",
|
|
45
|
+
weekday: "short"
|
|
46
|
+
});
|
|
47
|
+
formatters.set(zone, f);
|
|
48
|
+
}
|
|
49
|
+
return f;
|
|
50
|
+
}
|
|
51
|
+
var WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
52
|
+
function wallClock(zone, at = /* @__PURE__ */ new Date()) {
|
|
53
|
+
if (!isTimeZone(zone)) throw new RangeError(`wallClock: unknown time zone "${zone}"`);
|
|
54
|
+
const parts = {};
|
|
55
|
+
for (const p of partsFormatter(zone).formatToParts(at)) parts[p.type] = p.value;
|
|
56
|
+
return {
|
|
57
|
+
year: Number(parts["year"]),
|
|
58
|
+
month: Number(parts["month"]),
|
|
59
|
+
day: Number(parts["day"]),
|
|
60
|
+
hour: Number(parts["hour"]),
|
|
61
|
+
minute: Number(parts["minute"]),
|
|
62
|
+
second: Number(parts["second"]),
|
|
63
|
+
weekday: WEEKDAYS.indexOf(parts["weekday"] ?? "")
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
var pad = (n, width = 2) => String(n).padStart(width, "0");
|
|
67
|
+
var dayOf = (y, m, d) => `${pad(y, 4)}-${pad(m)}-${pad(d)}`;
|
|
68
|
+
function dayIn(zone, at = /* @__PURE__ */ new Date()) {
|
|
69
|
+
const c = wallClock(zone, at);
|
|
70
|
+
return dayOf(c.year, c.month, c.day);
|
|
71
|
+
}
|
|
72
|
+
function personTimeZone(person) {
|
|
73
|
+
const saved = person?.timeZone;
|
|
74
|
+
return saved && isTimeZone(saved) ? saved : deviceTimeZone();
|
|
75
|
+
}
|
|
76
|
+
function personDay(person, at = /* @__PURE__ */ new Date()) {
|
|
77
|
+
return dayIn(personTimeZone(person), at);
|
|
78
|
+
}
|
|
79
|
+
function addDays(day, days) {
|
|
80
|
+
const [y, m, d] = assertDay(day, "addDays");
|
|
81
|
+
if (!Number.isInteger(days)) throw new RangeError(`addDays: ${days} is not a whole number of days`);
|
|
82
|
+
const t = new Date(Date.UTC(y, m - 1, d + days));
|
|
83
|
+
return dayOf(t.getUTCFullYear(), t.getUTCMonth() + 1, t.getUTCDate());
|
|
84
|
+
}
|
|
85
|
+
function daysBetween(from, to) {
|
|
86
|
+
const [y1, m1, d1] = assertDay(from, "daysBetween");
|
|
87
|
+
const [y2, m2, d2] = assertDay(to, "daysBetween");
|
|
88
|
+
return Math.round((Date.UTC(y2, m2 - 1, d2) - Date.UTC(y1, m1 - 1, d1)) / 864e5);
|
|
89
|
+
}
|
|
90
|
+
function weekdayOf(day) {
|
|
91
|
+
const [y, m, d] = assertDay(day, "weekdayOf");
|
|
92
|
+
return new Date(Date.UTC(y, m - 1, d)).getUTCDay();
|
|
93
|
+
}
|
|
94
|
+
function startOfWeek(day, weekStartsOn = 1) {
|
|
95
|
+
if (!Number.isInteger(weekStartsOn) || weekStartsOn < 0 || weekStartsOn > 6) throw new RangeError("startOfWeek: weekStartsOn is 0 to 6");
|
|
96
|
+
return addDays(day, -((weekdayOf(day) - weekStartsOn + 7) % 7));
|
|
97
|
+
}
|
|
98
|
+
function startOfDayIn(day, zone) {
|
|
99
|
+
const [y, m, d] = assertDay(day, "startOfDayIn");
|
|
100
|
+
const target = Date.UTC(y, m - 1, d);
|
|
101
|
+
let at = target;
|
|
102
|
+
for (let i = 0; i < 2; i++) {
|
|
103
|
+
const c = wallClock(zone, new Date(at));
|
|
104
|
+
const shown = Date.UTC(c.year, c.month - 1, c.day, c.hour, c.minute, c.second);
|
|
105
|
+
at -= shown - target;
|
|
106
|
+
}
|
|
107
|
+
while (dayIn(zone, new Date(at)) < day) at += 15 * 6e4;
|
|
108
|
+
while (dayIn(zone, new Date(at - 1)) === day) at -= 15 * 6e4;
|
|
109
|
+
return new Date(at);
|
|
110
|
+
}
|
|
111
|
+
function dayRangeIn(day, zone) {
|
|
112
|
+
return { start: startOfDayIn(day, zone), end: startOfDayIn(addDays(day, 1), zone) };
|
|
113
|
+
}
|
|
114
|
+
function daysInMonth(day) {
|
|
115
|
+
const [y, m] = assertDay(day, "daysInMonth");
|
|
116
|
+
return new Date(Date.UTC(y, m, 0)).getUTCDate();
|
|
117
|
+
}
|
|
118
|
+
function startOfMonth(day) {
|
|
119
|
+
const [y, m] = assertDay(day, "startOfMonth");
|
|
120
|
+
return dayOf(y, m, 1);
|
|
121
|
+
}
|
|
122
|
+
function addMonths(day, months) {
|
|
123
|
+
const [y, m, d] = assertDay(day, "addMonths");
|
|
124
|
+
if (!Number.isInteger(months)) throw new RangeError(`addMonths: ${months} is not a whole number of months`);
|
|
125
|
+
const index = y * 12 + (m - 1) + months;
|
|
126
|
+
const ny = Math.floor(index / 12);
|
|
127
|
+
const nm = index - ny * 12 + 1;
|
|
128
|
+
const last = new Date(Date.UTC(ny, nm, 0)).getUTCDate();
|
|
129
|
+
return dayOf(ny, nm, Math.min(d, last));
|
|
130
|
+
}
|
|
131
|
+
function startOfQuarter(day) {
|
|
132
|
+
const [y, m] = assertDay(day, "startOfQuarter");
|
|
133
|
+
return dayOf(y, m - (m - 1) % 3, 1);
|
|
134
|
+
}
|
|
135
|
+
function addWeeks(day, weeks) {
|
|
136
|
+
if (!Number.isInteger(weeks)) throw new RangeError(`addWeeks: ${weeks} is not a whole number of weeks`);
|
|
137
|
+
return addDays(day, weeks * 7);
|
|
138
|
+
}
|
|
139
|
+
function monthRange(day) {
|
|
140
|
+
const start = startOfMonth(day);
|
|
141
|
+
return { start, end: addMonths(start, 1) };
|
|
142
|
+
}
|
|
143
|
+
function quarterRange(day) {
|
|
144
|
+
const start = startOfQuarter(day);
|
|
145
|
+
return { start, end: addMonths(start, 3) };
|
|
146
|
+
}
|
|
147
|
+
function weeksRange(day, weeks, weekStartsOn = 1) {
|
|
148
|
+
if (!Number.isInteger(weeks) || weeks < 1) throw new RangeError(`weeksRange: ${weeks} is not a whole number of weeks, 1 or more`);
|
|
149
|
+
const start = startOfWeek(day, weekStartsOn);
|
|
150
|
+
return { start, end: addWeeks(start, weeks) };
|
|
151
|
+
}
|
|
152
|
+
function monthGridRange(day, weekStartsOn = 1) {
|
|
153
|
+
const month = monthRange(day);
|
|
154
|
+
const start = startOfWeek(month.start, weekStartsOn);
|
|
155
|
+
const lastWeek = startOfWeek(addDays(month.end, -1), weekStartsOn);
|
|
156
|
+
return { start, end: addWeeks(lastWeek, 1) };
|
|
157
|
+
}
|
|
158
|
+
function eachDay(range) {
|
|
159
|
+
const n = daysBetween(range.start, range.end);
|
|
160
|
+
return Array.from({ length: Math.max(0, n) }, (_, i) => addDays(range.start, i));
|
|
161
|
+
}
|
|
162
|
+
function rangeIn(range, zone) {
|
|
163
|
+
return { start: startOfDayIn(range.start, zone), end: startOfDayIn(range.end, zone) };
|
|
164
|
+
}
|
|
165
|
+
var WALL_TIME = /^(\d{2}):(\d{2})(?::(\d{2}))?$/;
|
|
166
|
+
function validWallTime(time) {
|
|
167
|
+
const m = WALL_TIME.exec(time);
|
|
168
|
+
return Boolean(m) && Number(m[1]) <= 23 && Number(m[2]) <= 59 && Number(m[3] ?? 0) <= 59;
|
|
169
|
+
}
|
|
170
|
+
function parseWallTime(time, where) {
|
|
171
|
+
const m = WALL_TIME.exec(time);
|
|
172
|
+
if (!m || Number(m[1]) > 23 || Number(m[2]) > 59 || Number(m[3] ?? 0) > 59) {
|
|
173
|
+
throw new RangeError(`${where}: "${time}" is not an HH:MM[:SS] time`);
|
|
174
|
+
}
|
|
175
|
+
return [Number(m[1]), Number(m[2]), Number(m[3] ?? 0)];
|
|
176
|
+
}
|
|
177
|
+
function offsetAt(zone, at) {
|
|
178
|
+
const c = wallClock(zone, new Date(at));
|
|
179
|
+
return Date.UTC(c.year, c.month - 1, c.day, c.hour, c.minute, c.second) - (at - (at % 1e3 + 1e3) % 1e3);
|
|
180
|
+
}
|
|
181
|
+
function instantIn(day, time, zone) {
|
|
182
|
+
const [y, m, d] = assertDay(day, "instantIn");
|
|
183
|
+
const [h, mi, s] = parseWallTime(time, "instantIn");
|
|
184
|
+
if (!isTimeZone(zone)) throw new RangeError(`instantIn: unknown time zone "${zone}"`);
|
|
185
|
+
const target = Date.UTC(y, m - 1, d, h, mi, s);
|
|
186
|
+
const before = offsetAt(zone, target - 864e5);
|
|
187
|
+
const after = offsetAt(zone, target + 864e5);
|
|
188
|
+
const shows = (at) => offsetAt(zone, at) + at === target;
|
|
189
|
+
const early = target - Math.max(before, after);
|
|
190
|
+
const late = target - Math.min(before, after);
|
|
191
|
+
if (shows(early)) return new Date(early);
|
|
192
|
+
if (shows(late)) return new Date(late);
|
|
193
|
+
return new Date(target - before);
|
|
194
|
+
}
|
|
195
|
+
function wallTimeIn(zone, at) {
|
|
196
|
+
const c = wallClock(zone, at);
|
|
197
|
+
return { day: dayOf(c.year, c.month, c.day), time: `${pad(c.hour)}:${pad(c.minute)}:${pad(c.second)}` };
|
|
198
|
+
}
|
|
199
|
+
var RULE_DAYS = ["SU", "MO", "TU", "WE", "TH", "FR", "SA"];
|
|
200
|
+
var FREQS = ["DAILY", "WEEKLY", "MONTHLY", "YEARLY"];
|
|
201
|
+
function ruleInts(value, part, min, max, signed) {
|
|
202
|
+
return value.split(",").map((raw) => {
|
|
203
|
+
const n = Number(raw);
|
|
204
|
+
if (!/^[+-]?\d+$/.test(raw) || Math.abs(n) < min || Math.abs(n) > max || !signed && n < 0) {
|
|
205
|
+
throw new RangeError(`parseRRule: ${part}=${value} is out of range`);
|
|
206
|
+
}
|
|
207
|
+
return n;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
function ruleDate(value) {
|
|
211
|
+
const m = /^(\d{4})(\d{2})(\d{2})(?:T(\d{2})(\d{2})(\d{2})(Z)?)?$/.exec(value);
|
|
212
|
+
if (!m) throw new RangeError(`parseRRule: UNTIL=${value} is not a date`);
|
|
213
|
+
const day = `${m[1]}-${m[2]}-${m[3]}`;
|
|
214
|
+
if (!isDay(day)) throw new RangeError(`parseRRule: UNTIL=${value} is not a date`);
|
|
215
|
+
if (!m[4]) return day;
|
|
216
|
+
if (!m[7]) {
|
|
217
|
+
const time = `${m[4]}:${m[5]}:${m[6]}`;
|
|
218
|
+
if (!WALL_TIME.test(time) || Number(m[4]) > 23 || Number(m[5]) > 59 || Number(m[6]) > 59) throw new RangeError(`parseRRule: UNTIL=${value} is not a date`);
|
|
219
|
+
return { day, time };
|
|
220
|
+
}
|
|
221
|
+
return new Date(Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3]), Number(m[4]), Number(m[5]), Number(m[6])));
|
|
222
|
+
}
|
|
223
|
+
function parseRRule(text) {
|
|
224
|
+
const body = text.trim().replace(/^RRULE:/i, "");
|
|
225
|
+
const rule = { interval: 1, weekStart: 1 };
|
|
226
|
+
const seen = /* @__PURE__ */ new Set();
|
|
227
|
+
for (const piece of body.split(";")) {
|
|
228
|
+
if (!piece) continue;
|
|
229
|
+
const eq = piece.indexOf("=");
|
|
230
|
+
const key = piece.slice(0, eq).toUpperCase();
|
|
231
|
+
const value = piece.slice(eq + 1).toUpperCase();
|
|
232
|
+
if (eq < 1 || !value) throw new RangeError(`parseRRule: "${piece}" is not KEY=VALUE`);
|
|
233
|
+
if (seen.has(key)) throw new RangeError(`parseRRule: ${key} is set twice`);
|
|
234
|
+
seen.add(key);
|
|
235
|
+
switch (key) {
|
|
236
|
+
case "FREQ":
|
|
237
|
+
if (!FREQS.includes(value)) throw new RangeError(`parseRRule: FREQ=${value} isn't supported`);
|
|
238
|
+
rule.freq = value;
|
|
239
|
+
break;
|
|
240
|
+
case "INTERVAL":
|
|
241
|
+
rule.interval = ruleInts(value, key, 1, 1e4, false)[0];
|
|
242
|
+
break;
|
|
243
|
+
case "COUNT":
|
|
244
|
+
rule.count = ruleInts(value, key, 1, 1e5, false)[0];
|
|
245
|
+
break;
|
|
246
|
+
case "UNTIL":
|
|
247
|
+
rule.until = ruleDate(value);
|
|
248
|
+
break;
|
|
249
|
+
case "BYDAY":
|
|
250
|
+
rule.byDay = value.split(",").map((raw) => {
|
|
251
|
+
const m = /^([+-]?\d{1,2})?(SU|MO|TU|WE|TH|FR|SA)$/.exec(raw);
|
|
252
|
+
if (!m) throw new RangeError(`parseRRule: BYDAY=${value} isn't a weekday list`);
|
|
253
|
+
const nth = m[1] ? Number(m[1]) : void 0;
|
|
254
|
+
if (nth !== void 0 && (nth === 0 || Math.abs(nth) > 53)) throw new RangeError(`parseRRule: BYDAY=${value} is out of range`);
|
|
255
|
+
return nth === void 0 ? { weekday: RULE_DAYS.indexOf(m[2]) } : { weekday: RULE_DAYS.indexOf(m[2]), nth };
|
|
256
|
+
});
|
|
257
|
+
break;
|
|
258
|
+
case "BYMONTHDAY":
|
|
259
|
+
rule.byMonthDay = ruleInts(value, key, 1, 31, true);
|
|
260
|
+
break;
|
|
261
|
+
case "BYMONTH":
|
|
262
|
+
rule.byMonth = ruleInts(value, key, 1, 12, false);
|
|
263
|
+
break;
|
|
264
|
+
case "WKST":
|
|
265
|
+
if (!RULE_DAYS.includes(value)) throw new RangeError(`parseRRule: WKST=${value} isn't a weekday`);
|
|
266
|
+
rule.weekStart = RULE_DAYS.indexOf(value);
|
|
267
|
+
break;
|
|
268
|
+
default:
|
|
269
|
+
throw new RangeError(`parseRRule: ${key} isn't supported`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return checkRule(rule, "parseRRule");
|
|
273
|
+
}
|
|
274
|
+
var intIn = (n, min, max) => typeof n === "number" && Number.isInteger(n) && n >= min && n <= max;
|
|
275
|
+
function checkRule(rule, where) {
|
|
276
|
+
if (!rule || typeof rule !== "object") throw new RangeError(`${where}: not a rule`);
|
|
277
|
+
if (!rule.freq) throw new RangeError(`${where}: FREQ is required`);
|
|
278
|
+
if (!FREQS.includes(rule.freq)) throw new RangeError(`${where}: FREQ=${String(rule.freq)} isn't supported`);
|
|
279
|
+
if (!intIn(rule.interval, 1, 1e4)) throw new RangeError(`${where}: INTERVAL=${String(rule.interval)} is out of range`);
|
|
280
|
+
if (rule.count !== void 0 && !intIn(rule.count, 1, 1e5)) throw new RangeError(`${where}: COUNT=${String(rule.count)} is out of range`);
|
|
281
|
+
if (rule.count !== void 0 && rule.until !== void 0) throw new RangeError(`${where}: COUNT and UNTIL can't both be set`);
|
|
282
|
+
if (!intIn(rule.weekStart, 0, 6)) throw new RangeError(`${where}: WKST=${String(rule.weekStart)} isn't a weekday`);
|
|
283
|
+
for (const b of rule.byDay ?? []) {
|
|
284
|
+
if (!intIn(b.weekday, 0, 6) || b.nth !== void 0 && (!intIn(Math.abs(b.nth), 1, 53) || b.nth === 0)) throw new RangeError(`${where}: BYDAY is out of range`);
|
|
285
|
+
if (b.nth !== void 0 && rule.freq !== "MONTHLY" && rule.freq !== "YEARLY") {
|
|
286
|
+
throw new RangeError(`${where}: BYDAY with a position (${b.nth}${RULE_DAYS[b.weekday]}) needs FREQ=MONTHLY or YEARLY`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
for (const d of rule.byMonthDay ?? []) if (!intIn(Math.abs(d), 1, 31)) throw new RangeError(`${where}: BYMONTHDAY=${d} is out of range`);
|
|
290
|
+
if (rule.byMonthDay && rule.freq === "WEEKLY") throw new RangeError(`${where}: BYMONTHDAY can't be used with FREQ=WEEKLY`);
|
|
291
|
+
for (const m of rule.byMonth ?? []) if (!intIn(m, 1, 12)) throw new RangeError(`${where}: BYMONTH=${m} is out of range`);
|
|
292
|
+
const until = rule.until;
|
|
293
|
+
if (until !== void 0) {
|
|
294
|
+
const ok = typeof until === "string" ? isDay(until) : until instanceof Date ? !Number.isNaN(until.getTime()) : Boolean(until) && typeof until === "object" && isDay(until.day) && typeof until.time === "string" && validWallTime(until.time);
|
|
295
|
+
if (!ok) throw new RangeError(`${where}: UNTIL isn't a day, an instant or a { day, time } wall time`);
|
|
296
|
+
}
|
|
297
|
+
for (const key of Object.keys(rule)) {
|
|
298
|
+
if (!["freq", "interval", "count", "until", "byDay", "byMonthDay", "byMonth", "weekStart"].includes(key)) throw new RangeError(`${where}: ${key} isn't supported`);
|
|
299
|
+
}
|
|
300
|
+
return rule;
|
|
301
|
+
}
|
|
302
|
+
function weekdayPositions(days, spec) {
|
|
303
|
+
const matching = days.filter((d) => weekdayOf(d) === spec.weekday);
|
|
304
|
+
if (spec.nth === void 0) return matching;
|
|
305
|
+
const pick = spec.nth > 0 ? matching[spec.nth - 1] : matching[matching.length + spec.nth];
|
|
306
|
+
return pick ? [pick] : [];
|
|
307
|
+
}
|
|
308
|
+
function monthDays(y, m) {
|
|
309
|
+
const n = new Date(Date.UTC(y, m, 0)).getUTCDate();
|
|
310
|
+
return Array.from({ length: n }, (_, i) => dayOf(y, m, i + 1));
|
|
311
|
+
}
|
|
312
|
+
function byMonthDays(days, byMonthDay) {
|
|
313
|
+
return byMonthDay.map((n) => n > 0 ? days[n - 1] : days[days.length + n]).filter((d) => d !== void 0);
|
|
314
|
+
}
|
|
315
|
+
function monthCandidates(rule, y, m, startDay, scope) {
|
|
316
|
+
const days = monthDays(y, m);
|
|
317
|
+
if (rule.byMonthDay) {
|
|
318
|
+
const picked = byMonthDays(days, rule.byMonthDay);
|
|
319
|
+
if (!rule.byDay) return picked;
|
|
320
|
+
const allowed = new Set(rule.byDay.flatMap((b) => weekdayPositions(scope ?? days, b)));
|
|
321
|
+
return picked.filter((d2) => allowed.has(d2));
|
|
322
|
+
}
|
|
323
|
+
if (rule.byDay) return rule.byDay.flatMap((b) => weekdayPositions(days, b));
|
|
324
|
+
const d = days[startDay - 1];
|
|
325
|
+
return d ? [d] : [];
|
|
326
|
+
}
|
|
327
|
+
function periodCandidates(rule, period, first) {
|
|
328
|
+
const [py, pm] = assertDay(period, "expandRecurrence");
|
|
329
|
+
let days;
|
|
330
|
+
switch (rule.freq) {
|
|
331
|
+
case "DAILY":
|
|
332
|
+
days = [period];
|
|
333
|
+
if (rule.byMonthDay) days = days.filter((d) => byMonthDays(monthDays(py, pm), rule.byMonthDay).includes(d));
|
|
334
|
+
if (rule.byDay) days = days.filter((d) => rule.byDay.some((b) => b.weekday === weekdayOf(d)));
|
|
335
|
+
break;
|
|
336
|
+
case "WEEKLY": {
|
|
337
|
+
const week = Array.from({ length: 7 }, (_, i) => addDays(period, i));
|
|
338
|
+
days = rule.byDay ? week.filter((d) => rule.byDay.some((b) => b.weekday === weekdayOf(d))) : week.filter((d) => weekdayOf(d) === weekdayOf(dayOf(...first)));
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
case "MONTHLY":
|
|
342
|
+
days = monthCandidates(rule, py, pm, first[2]);
|
|
343
|
+
break;
|
|
344
|
+
case "YEARLY":
|
|
345
|
+
if (rule.byDay && !rule.byMonth && !rule.byMonthDay) {
|
|
346
|
+
const year = Array.from({ length: 12 }, (_, i) => monthDays(py, i + 1)).flat();
|
|
347
|
+
days = rule.byDay.flatMap((b) => weekdayPositions(year, b));
|
|
348
|
+
} else {
|
|
349
|
+
const months = rule.byMonth ?? (rule.byDay || rule.byMonthDay ? [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] : [first[1]]);
|
|
350
|
+
const year = rule.byMonth ? void 0 : Array.from({ length: 12 }, (_, i) => monthDays(py, i + 1)).flat();
|
|
351
|
+
days = months.flatMap((m) => monthCandidates(rule, py, m, first[2], year));
|
|
352
|
+
}
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
if (rule.byMonth) days = days.filter((d) => rule.byMonth.includes(Number(d.slice(5, 7))));
|
|
356
|
+
return [...new Set(days)].sort();
|
|
357
|
+
}
|
|
358
|
+
function periodAt(rule, firstPeriod, k) {
|
|
359
|
+
switch (rule.freq) {
|
|
360
|
+
case "DAILY":
|
|
361
|
+
return addDays(firstPeriod, k);
|
|
362
|
+
case "WEEKLY":
|
|
363
|
+
return addWeeks(firstPeriod, k);
|
|
364
|
+
case "MONTHLY":
|
|
365
|
+
return addMonths(firstPeriod, k);
|
|
366
|
+
case "YEARLY":
|
|
367
|
+
return addMonths(firstPeriod, 12 * k);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
function periodsTo(rule, firstPeriod, day) {
|
|
371
|
+
switch (rule.freq) {
|
|
372
|
+
case "DAILY":
|
|
373
|
+
return daysBetween(firstPeriod, day);
|
|
374
|
+
case "WEEKLY":
|
|
375
|
+
return Math.floor(daysBetween(firstPeriod, day) / 7);
|
|
376
|
+
case "MONTHLY":
|
|
377
|
+
return (Number(day.slice(0, 4)) - Number(firstPeriod.slice(0, 4))) * 12 + Number(day.slice(5, 7)) - Number(firstPeriod.slice(5, 7));
|
|
378
|
+
case "YEARLY":
|
|
379
|
+
return Number(day.slice(0, 4)) - Number(firstPeriod.slice(0, 4));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
function startOf(start) {
|
|
383
|
+
if (typeof start === "string") {
|
|
384
|
+
assertDay(start, "expandRecurrence");
|
|
385
|
+
return { day: start };
|
|
386
|
+
}
|
|
387
|
+
if (!isTimeZone(start.timeZone)) throw new RangeError(`expandRecurrence: unknown time zone "${start.timeZone}"`);
|
|
388
|
+
if ("at" in start) return { ...wallTimeIn(start.timeZone, start.at), zone: start.timeZone };
|
|
389
|
+
assertDay(start.day, "expandRecurrence");
|
|
390
|
+
parseWallTime(start.time, "expandRecurrence");
|
|
391
|
+
return { day: start.day, time: start.time, zone: start.timeZone };
|
|
392
|
+
}
|
|
393
|
+
function expandRecurrence(options) {
|
|
394
|
+
const rule = typeof options.rule === "string" ? parseRRule(options.rule) : checkRule(options.rule, "expandRecurrence");
|
|
395
|
+
const given = options.start;
|
|
396
|
+
const { day: firstDay, time, zone } = startOf(given);
|
|
397
|
+
const { window } = options;
|
|
398
|
+
if (!window) throw new RangeError("expandRecurrence: a window is required");
|
|
399
|
+
if (options.limit !== void 0 && (!Number.isInteger(options.limit) || options.limit < 1)) {
|
|
400
|
+
throw new RangeError(`expandRecurrence: limit ${options.limit} is not a whole number, 1 or more`);
|
|
401
|
+
}
|
|
402
|
+
assertDay(window.start, "expandRecurrence");
|
|
403
|
+
assertDay(window.end, "expandRecurrence");
|
|
404
|
+
const limit = options.limit ?? 1e3;
|
|
405
|
+
const first = assertDay(firstDay, "expandRecurrence");
|
|
406
|
+
const timed = Boolean(time && zone);
|
|
407
|
+
const givenAt = typeof given === "object" && "at" in given ? given.at : void 0;
|
|
408
|
+
const ms = givenAt ? (givenAt.getTime() % 1e3 + 1e3) % 1e3 : 0;
|
|
409
|
+
const firstAt = givenAt ?? (timed ? instantIn(firstDay, time, zone) : void 0);
|
|
410
|
+
const at = (day) => day === firstDay ? firstAt : timed ? new Date(instantIn(day, time, zone).getTime() + ms) : void 0;
|
|
411
|
+
const exDays = /* @__PURE__ */ new Set();
|
|
412
|
+
const exInstants = /* @__PURE__ */ new Set();
|
|
413
|
+
for (const ex of options.exdates ?? []) {
|
|
414
|
+
if (ex instanceof Date) {
|
|
415
|
+
if (!timed) throw new RangeError("expandRecurrence: an all-day series' EXDATE is a day, not an instant");
|
|
416
|
+
exInstants.add(ex.getTime());
|
|
417
|
+
} else {
|
|
418
|
+
assertDay(ex, "expandRecurrence");
|
|
419
|
+
exDays.add(ex);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const until = rule.until;
|
|
423
|
+
const untilAt = until === void 0 || typeof until === "string" ? void 0 : until instanceof Date ? until : timed ? instantIn(until.day, until.time, zone) : void 0;
|
|
424
|
+
const untilDay = typeof until === "string" ? until : until instanceof Date ? timed ? void 0 : dayIn("UTC", until) : until && !timed ? until.day : void 0;
|
|
425
|
+
const pastUntil = (day) => {
|
|
426
|
+
if (untilDay !== void 0) return day > untilDay;
|
|
427
|
+
if (untilAt !== void 0) return at(day).getTime() > untilAt.getTime();
|
|
428
|
+
return false;
|
|
429
|
+
};
|
|
430
|
+
const firstPeriod = rule.freq === "WEEKLY" ? startOfWeek(firstDay, rule.weekStart) : rule.freq === "DAILY" ? firstDay : rule.freq === "MONTHLY" ? startOfMonth(firstDay) : dayOf(first[0], 1, 1);
|
|
431
|
+
const out = [];
|
|
432
|
+
let truncated = false;
|
|
433
|
+
const done = () => ({ occurrences: out, truncated });
|
|
434
|
+
let counted = 0;
|
|
435
|
+
const take = (day) => {
|
|
436
|
+
counted++;
|
|
437
|
+
if (day >= window.start && day < window.end && !exDays.has(day)) {
|
|
438
|
+
const start = at(day);
|
|
439
|
+
if (!(start && exInstants.has(start.getTime()))) {
|
|
440
|
+
if (out.length >= limit) {
|
|
441
|
+
truncated = true;
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
444
|
+
out.push(start ? { day, start } : { day });
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return rule.count !== void 0 && counted >= rule.count;
|
|
448
|
+
};
|
|
449
|
+
if (pastUntil(firstDay)) return done();
|
|
450
|
+
if (take(firstDay)) return done();
|
|
451
|
+
let k = 0;
|
|
452
|
+
if (rule.count === void 0 && window.start > firstDay) {
|
|
453
|
+
const behind = periodsTo(rule, firstPeriod, window.start) - 1;
|
|
454
|
+
k = Math.max(0, Math.floor(behind / rule.interval) * rule.interval);
|
|
455
|
+
}
|
|
456
|
+
let lastYear = first[0];
|
|
457
|
+
for (; ; k += rule.interval) {
|
|
458
|
+
const period = periodAt(rule, firstPeriod, k);
|
|
459
|
+
if (period.length > 10 || period >= window.end) break;
|
|
460
|
+
const periodYear = Number(period.slice(0, 4));
|
|
461
|
+
if (periodYear - lastYear > 400) break;
|
|
462
|
+
const days = periodCandidates(rule, period, first).filter((d) => d > firstDay);
|
|
463
|
+
if (days.length) lastYear = periodYear;
|
|
464
|
+
for (const day of days) {
|
|
465
|
+
if (pastUntil(day)) return done();
|
|
466
|
+
if (day >= window.end && rule.count === void 0) return done();
|
|
467
|
+
if (take(day)) return done();
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return done();
|
|
471
|
+
}
|
|
472
|
+
var STORED = /^(\d{4}-\d{2}-\d{2})(?:[ T](\d{2}:\d{2}(?::\d{2})?)(\.\d+)?)?\s*(Z|[+-]\d{2}(?::?\d{2})?)?$/;
|
|
473
|
+
function readEventTime(value, options = {}) {
|
|
474
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value;
|
|
475
|
+
if (typeof value !== "string") return null;
|
|
476
|
+
const m = STORED.exec(value.trim());
|
|
477
|
+
if (!m || !isDay(m[1])) return null;
|
|
478
|
+
if (options.dateOnly || !m[2]) return m[1];
|
|
479
|
+
const time = m[2].length === 5 ? `${m[2]}:00` : m[2];
|
|
480
|
+
if (!m[4]) {
|
|
481
|
+
const zone2 = options.timeZone && isTimeZone(options.timeZone) ? options.timeZone : deviceTimeZone();
|
|
482
|
+
const [h, mi, sec] = time.split(":").map(Number);
|
|
483
|
+
if (!WALL_TIME.test(time) || h > 23 || mi > 59 || sec > 59) return null;
|
|
484
|
+
const at = instantIn(m[1], time, zone2);
|
|
485
|
+
return m[3] ? new Date(at.getTime() + Math.round(Number(`0${m[3]}`) * 1e3)) : at;
|
|
486
|
+
}
|
|
487
|
+
let zone = m[4];
|
|
488
|
+
if (/^[+-]\d{2}$/.test(zone)) zone += ":00";
|
|
489
|
+
else if (/^[+-]\d{4}$/.test(zone)) zone = `${zone.slice(0, 3)}:${zone.slice(3)}`;
|
|
490
|
+
const ms = m[3] ? m[3].slice(0, 4).padEnd(4, "0") : "";
|
|
491
|
+
const date = /* @__PURE__ */ new Date(`${m[1]}T${time}${ms}${zone}`);
|
|
492
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
export { addDays, addMonths, addWeeks, dayIn, dayRangeIn, daysBetween, daysInMonth, deviceTimeZone, eachDay, expandRecurrence, instantIn, isDay, isTimeZone, monthGridRange, monthRange, parseRRule, personDay, personTimeZone, quarterRange, rangeIn, readEventTime, startOfDayIn, startOfMonth, startOfQuarter, startOfWeek, wallClock, wallTimeIn, weekdayOf, weeksRange };
|
|
496
|
+
//# sourceMappingURL=chunk-BIIENNTW.js.map
|
|
497
|
+
//# sourceMappingURL=chunk-BIIENNTW.js.map
|