@gentiq/core 1.0.0-alpha.11 → 1.0.0-alpha.12

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.
@@ -0,0 +1,104 @@
1
+ import { weekStart as m } from "./calendars.es.js";
2
+ import { createDateFormatter as f } from "./datetime.es.js";
3
+ function T() {
4
+ try {
5
+ const n = Intl.DateTimeFormat().resolvedOptions().timeZone;
6
+ return n && n.trim() ? n : "UTC";
7
+ } catch {
8
+ return "UTC";
9
+ }
10
+ }
11
+ function d(n) {
12
+ const t = /* @__PURE__ */ new Set();
13
+ for (const r of n) {
14
+ const e = Math.floor(r);
15
+ e === 7 ? t.add(0) : e >= 0 && e <= 6 && t.add(e);
16
+ }
17
+ return Array.from(t).sort((r, e) => r - e);
18
+ }
19
+ function D(n) {
20
+ const t = Math.max(0, Math.min(59, Math.floor(n.minute))), r = Math.max(0, Math.min(23, Math.floor(n.hour)));
21
+ if (n.frequency === "daily") return `${t} ${r} * * *`;
22
+ const e = d(n.daysOfWeek);
23
+ return e.length === 0 ? `${t} ${r} * * 1` : e.length === 7 ? `${t} ${r} * * *` : `${t} ${r} * * ${e.join(",")}`;
24
+ }
25
+ function l(n) {
26
+ const t = /* @__PURE__ */ new Set();
27
+ for (const r of n.split(",")) {
28
+ const e = r.trim();
29
+ if (/^[0-7]$/.test(e)) {
30
+ t.add(Number(e) === 7 ? 0 : Number(e));
31
+ continue;
32
+ }
33
+ const o = /^([0-7])-([0-7])$/.exec(e);
34
+ if (!o) return null;
35
+ const c = Number(o[1]), u = Number(o[2]);
36
+ if (c > u) return null;
37
+ for (let s = c; s <= u; s += 1)
38
+ t.add(s === 7 ? 0 : s);
39
+ }
40
+ return t.size > 0 ? Array.from(t).sort((r, e) => r - e) : null;
41
+ }
42
+ function y(n) {
43
+ if (!n) return null;
44
+ const t = n.trim().split(/\s+/);
45
+ if (t.length !== 5) return null;
46
+ const [r, e, o, c, u] = t;
47
+ if (o !== "*" || c !== "*" || !/^\d+$/.test(r) || !/^\d+$/.test(e)) return null;
48
+ const s = Number(r), i = Number(e);
49
+ if (s < 0 || s > 59 || i < 0 || i > 23) return null;
50
+ if (u === "*") return { frequency: "daily", hour: i, minute: s };
51
+ const a = l(u);
52
+ return a ? a.length === 7 ? { frequency: "daily", hour: i, minute: s } : { frequency: "weekly", hour: i, minute: s, daysOfWeek: a } : null;
53
+ }
54
+ function h(n, t, r) {
55
+ const e = new Date(Date.UTC(2026, 0, 1, n, t));
56
+ return f(r, {
57
+ hour: "2-digit",
58
+ minute: "2-digit",
59
+ timeZone: "UTC"
60
+ }).format(e);
61
+ }
62
+ function $(n, t, r) {
63
+ const e = m(r), o = [...n].sort((s, i) => (s - e + 7) % 7 - (i - e + 7) % 7), c = f(r, { weekday: "short", timeZone: "UTC" });
64
+ return o.map((s) => {
65
+ try {
66
+ return c.format(new Date(Date.UTC(2024, 0, 7 + s)));
67
+ } catch {
68
+ return t(`schedules:days.${s}`);
69
+ }
70
+ }).join(", ");
71
+ }
72
+ function p(n, t, r) {
73
+ if (n.kind === "once") {
74
+ if (!n.run_at) return t("schedules:cadence.once");
75
+ const o = f(r, {
76
+ dateStyle: "medium",
77
+ timeStyle: "short",
78
+ timeZone: n.timezone || "UTC"
79
+ }).format(new Date(n.run_at));
80
+ return t("schedules:cadence.once_at", { datetime: o });
81
+ }
82
+ if (n.kind === "interval") {
83
+ const o = n.interval_minutes ?? 60;
84
+ return o % 60 === 0 ? t("schedules:cadence.every_hours", { hours: o / 60 }) : t("schedules:cadence.every_minutes", { minutes: o });
85
+ }
86
+ const e = y(n.cron);
87
+ if (e) {
88
+ const o = h(e.hour, e.minute, r);
89
+ return e.frequency === "daily" ? t("schedules:cadence.daily", { time: o }) : e.daysOfWeek.length === 1 ? t("schedules:cadence.weekly", {
90
+ day: t(`schedules:days.${e.daysOfWeek[0]}`),
91
+ time: o
92
+ }) : t("schedules:cadence.weekly", {
93
+ day: $(e.daysOfWeek, t, r),
94
+ time: o
95
+ });
96
+ }
97
+ return n.cron ? t("schedules:cadence.custom", { cron: n.cron }) : t("schedules:cadence.custom_empty");
98
+ }
99
+ export {
100
+ y as cronToPreset,
101
+ p as describeSchedule,
102
+ T as detectLocalTimezone,
103
+ D as presetToCron
104
+ };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "provenance": false
12
12
  },
13
13
  "description": "Framework-free core of the Gentiq SDK: the API client, the chat protocol and the thread controller.",
14
- "version": "1.0.0-alpha.11",
14
+ "version": "1.0.0-alpha.12",
15
15
  "type": "module",
16
16
  "files": [
17
17
  "dist"