neramjs 0.0.0-stage → 0.1.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.
@@ -0,0 +1,85 @@
1
+ import { type DurationInput } from '../duration.ts';
2
+ import { Neram, type NeramInput } from '../neram.ts';
3
+ /** A database-friendly occurrence: store `utc` (or `epoch`) for querying, `local` + `tz` for display. */
4
+ export interface OccurrenceRecord {
5
+ /** UTC ISO string, e.g. "2026-12-07T03:30:00.000Z" */
6
+ utc: string;
7
+ /** Wall time in the schedule's zone: "2026-12-07T09:00:00" (all-day: "2026-12-07") */
8
+ local: string;
9
+ /** IANA zone the schedule runs in */
10
+ tz: string;
11
+ /** Milliseconds since the epoch */
12
+ epoch: number;
13
+ allDay: boolean;
14
+ }
15
+ export interface OutputMap {
16
+ neram: Neram;
17
+ date: Date;
18
+ epoch: number;
19
+ unix: number;
20
+ iso: string;
21
+ zoned: string;
22
+ local: string;
23
+ record: OccurrenceRecord;
24
+ }
25
+ export type OutputFormat = keyof OutputMap;
26
+ export type Formatter<R = unknown> = (d: Neram) => R;
27
+ /** How occurrences are returned: a format name, or a function given each occurrence as a Neram. */
28
+ export type As = OutputFormat | Formatter;
29
+ export type Out<A> = A extends OutputFormat ? OutputMap[A] : A extends Formatter<infer R> ? R : never;
30
+ export interface OutputOptions<A extends As> {
31
+ as?: A;
32
+ }
33
+ export interface Instance<T> {
34
+ start: T;
35
+ end: T;
36
+ }
37
+ /** Shared query API for RRule and Cron. All queries yield occurrences in ascending order. */
38
+ export declare abstract class Schedule {
39
+ /** The zone occurrences are computed in (IANA name, "UTC" or a fixed offset). */
40
+ abstract readonly tz: string;
41
+ abstract readonly allDay: boolean;
42
+ /** Instants (ms) at or after `fromMs`, ascending. */
43
+ protected abstract iterate(fromMs: number): Generator<number>;
44
+ /** Where unbounded queries start. */
45
+ protected abstract startMs(): number;
46
+ /** True when the schedule never ends. */
47
+ abstract isInfinite(): boolean;
48
+ protected coerce(input: NeramInput): number;
49
+ protected out<A extends As>(ms: number, as: A | undefined): Out<A>;
50
+ /**
51
+ * Every occurrence. Infinite schedules need a `limit`.
52
+ * rule.all({ limit: 10, as: 'iso' })
53
+ */
54
+ all<A extends As = 'neram'>(opts?: OutputOptions<A> & {
55
+ limit?: number;
56
+ }): Out<A>[];
57
+ /** Occurrences between two dates, inclusive by default. Strings without an offset are read in the schedule's zone. */
58
+ between<A extends As = 'neram'>(from: NeramInput, to: NeramInput, opts?: OutputOptions<A> & {
59
+ inclusive?: boolean;
60
+ limit?: number;
61
+ }): Out<A>[];
62
+ /** The first occurrence after `date` (default: now). */
63
+ after<A extends As = 'neram'>(date?: NeramInput, opts?: OutputOptions<A> & {
64
+ inclusive?: boolean;
65
+ }): Out<A> | null;
66
+ /** The last occurrence before `date` (default: now). */
67
+ before<A extends As = 'neram'>(date?: NeramInput, opts?: OutputOptions<A> & {
68
+ inclusive?: boolean;
69
+ }): Out<A> | null;
70
+ /** The next `n` occurrences strictly after `from` (default: now). */
71
+ take<A extends As = 'neram'>(n: number, opts?: OutputOptions<A> & {
72
+ from?: NeramInput;
73
+ }): Out<A>[];
74
+ /** True when `date` is exactly an occurrence. */
75
+ includes(date: NeramInput): boolean;
76
+ /**
77
+ * Event instances with a start and end that overlap [from, to): what a calendar view needs.
78
+ * Includes events that started before `from` but are still running.
79
+ * rule.instances('2026-12-01', '2027-01-01', { duration: { hours: 1 }, as: 'iso' })
80
+ */
81
+ instances<A extends As = 'neram'>(from: NeramInput, to: NeramInput, opts: OutputOptions<A> & {
82
+ duration: DurationInput;
83
+ }): Instance<Out<A>>[];
84
+ [Symbol.iterator](): Generator<Neram>;
85
+ }
@@ -0,0 +1,169 @@
1
+ import { duration } from '../duration.js';
2
+ import { Neram, neram } from '../neram.js';
3
+ const MAX_SCAN = 400 * 366 * 86400000; // 400 years: every calendar pattern repeats within that
4
+ /** Shared query API for RRule and Cron. All queries yield occurrences in ascending order. */
5
+ export class Schedule {
6
+ coerce(input) {
7
+ const ms = neram(input, { zone: this.tz }).valueOf();
8
+ if (Number.isNaN(ms))
9
+ throw new RangeError(`neram: invalid date ${JSON.stringify(input)}`);
10
+ return ms;
11
+ }
12
+ out(ms, as) {
13
+ const d = neram(ms, { zone: this.tz });
14
+ if (typeof as === 'function')
15
+ return as(d);
16
+ const local = () => d.format(this.allDay ? 'YYYY-MM-DD' : 'YYYY-MM-DDTHH:mm:ss');
17
+ let v;
18
+ switch (as ?? 'neram') {
19
+ case 'neram':
20
+ v = d;
21
+ break;
22
+ case 'date':
23
+ v = d.toDate();
24
+ break;
25
+ case 'epoch':
26
+ v = ms;
27
+ break;
28
+ case 'unix':
29
+ v = Math.floor(ms / 1000);
30
+ break;
31
+ case 'iso':
32
+ v = d.toISOString();
33
+ break;
34
+ case 'zoned':
35
+ v = d.toZonedISOString();
36
+ break;
37
+ case 'local':
38
+ v = local();
39
+ break;
40
+ case 'record':
41
+ v = { utc: d.toISOString(), local: local(), tz: d.timezone(), epoch: ms, allDay: this.allDay };
42
+ break;
43
+ default: throw new RangeError(`neram: unknown output format "${String(as)}"`);
44
+ }
45
+ return v;
46
+ }
47
+ /**
48
+ * Every occurrence. Infinite schedules need a `limit`.
49
+ * rule.all({ limit: 10, as: 'iso' })
50
+ */
51
+ all(opts = {}) {
52
+ checkCount('limit', opts.limit);
53
+ if (opts.limit === undefined && this.isInfinite()) {
54
+ throw new RangeError('neram: this schedule never ends; pass { limit } or use between()');
55
+ }
56
+ const res = [];
57
+ for (const ms of this.iterate(this.startMs())) {
58
+ if (opts.limit !== undefined && res.length >= opts.limit)
59
+ break;
60
+ res.push(this.out(ms, opts.as));
61
+ }
62
+ return res;
63
+ }
64
+ /** Occurrences between two dates, inclusive by default. Strings without an offset are read in the schedule's zone. */
65
+ between(from, to, opts = {}) {
66
+ checkCount('limit', opts.limit);
67
+ const inc = opts.inclusive ?? true;
68
+ const f = this.coerce(from);
69
+ const t = this.coerce(to);
70
+ const res = [];
71
+ for (const ms of this.iterate(f)) {
72
+ if (ms > t || (!inc && ms === t))
73
+ break;
74
+ if (!inc && ms === f)
75
+ continue;
76
+ if (opts.limit !== undefined && res.length >= opts.limit)
77
+ break;
78
+ res.push(this.out(ms, opts.as));
79
+ }
80
+ return res;
81
+ }
82
+ /** The first occurrence after `date` (default: now). */
83
+ after(date, opts = {}) {
84
+ const f = date === undefined ? Date.now() : this.coerce(date);
85
+ for (const ms of this.iterate(f)) {
86
+ if (ms === f && !opts.inclusive)
87
+ continue;
88
+ return this.out(ms, opts.as);
89
+ }
90
+ return null;
91
+ }
92
+ /** The last occurrence before `date` (default: now). */
93
+ before(date, opts = {}) {
94
+ const t = date === undefined ? Date.now() : this.coerce(date);
95
+ const floor = Math.max(this.startMs(), t - MAX_SCAN);
96
+ let window = 7 * 86400000;
97
+ for (;;) {
98
+ const lo = Math.max(floor, t - window);
99
+ let found;
100
+ for (const ms of this.iterate(lo)) {
101
+ if (ms > t || (ms === t && !opts.inclusive))
102
+ break;
103
+ found = ms;
104
+ }
105
+ if (found !== undefined)
106
+ return this.out(found, opts.as);
107
+ if (lo <= floor)
108
+ return null;
109
+ window *= 8;
110
+ }
111
+ }
112
+ /** The next `n` occurrences strictly after `from` (default: now). */
113
+ take(n, opts = {}) {
114
+ checkCount('take(n)', n);
115
+ const f = opts.from === undefined ? Date.now() : this.coerce(opts.from);
116
+ const res = [];
117
+ if (n === 0)
118
+ return res;
119
+ for (const ms of this.iterate(f)) {
120
+ if (ms === f)
121
+ continue;
122
+ res.push(this.out(ms, opts.as));
123
+ if (res.length >= n)
124
+ break;
125
+ }
126
+ return res;
127
+ }
128
+ /** True when `date` is exactly an occurrence. */
129
+ includes(date) {
130
+ const t = this.coerce(date);
131
+ for (const ms of this.iterate(t))
132
+ return ms === t;
133
+ return false;
134
+ }
135
+ /**
136
+ * Event instances with a start and end that overlap [from, to): what a calendar view needs.
137
+ * Includes events that started before `from` but are still running.
138
+ * rule.instances('2026-12-01', '2027-01-01', { duration: { hours: 1 }, as: 'iso' })
139
+ */
140
+ instances(from, to, opts) {
141
+ const dur = duration(opts.duration);
142
+ if (!dur.isValid() || dur.valueOf() < 0)
143
+ throw new RangeError('neram: instances() needs a duration of zero or more');
144
+ const f = this.coerce(from);
145
+ const t = this.coerce(to);
146
+ const slack = Math.abs(dur.asMilliseconds()) + 2 * 86400000;
147
+ const res = [];
148
+ for (const ms of this.iterate(f - slack)) {
149
+ if (ms >= t)
150
+ break;
151
+ const start = neram(ms, { zone: this.tz });
152
+ const end = start.add(dur);
153
+ if (end.valueOf() <= f && ms < f)
154
+ continue;
155
+ res.push({ start: this.out(ms, opts.as), end: this.out(end.valueOf(), opts.as) });
156
+ }
157
+ return res;
158
+ }
159
+ *[Symbol.iterator]() {
160
+ for (const ms of this.iterate(this.startMs()))
161
+ yield neram(ms, { zone: this.tz });
162
+ }
163
+ }
164
+ /** Counts and limits must be whole numbers of zero or more; NaN or 1.5 would silently return the wrong amount. */
165
+ function checkCount(name, n) {
166
+ if (n !== undefined && (!Number.isInteger(n) || n < 0)) {
167
+ throw new RangeError(`neram: ${name} must be a whole number of zero or more, got ${String(n)}`);
168
+ }
169
+ }
@@ -0,0 +1,3 @@
1
+ /*! neramjs v0.1.0 | MIT | github.com/varksh05/neramjs */
2
+ function M(r,e,t,n=0,s=0,i=0,a=0){if(r>=100)return Date.UTC(r,e,t,n,s,i,a);let u=new Date(0);return u.setUTCFullYear(r,e,t),u.setUTCHours(n,s,i,a),u.getTime()}function We(r){return M(r.y,r.M,r.D,r.h,r.m,r.s,r.ms)}var Je=/^([+-])(\d{2}):?(\d{2})$/;function re(r){if(r==="Z"||r==="z")return 0;let e=Je.exec(r)??/^([+-])(\d{2})$/.exec(r);if(!e)return;let t=Number(e[2]),n=Number(e[3]??0);if(t>23||n>59)return;let s=t*60+n;return e[1]==="-"?-s:s}function K(r,e=":"){let t=r<0?"-":"+",n=Math.abs(r);return`${t}${String(Math.floor(n/60)).padStart(2,"0")}${e}${String(n%60).padStart(2,"0")}`}function Ke(r){return Je.test(r)}var Yt={"Asia/Calcutta":"Asia/Kolkata","Asia/Saigon":"Asia/Ho_Chi_Minh","Asia/Katmandu":"Asia/Kathmandu","Asia/Rangoon":"Asia/Yangon","Europe/Kiev":"Europe/Kyiv","Atlantic/Faeroe":"Atlantic/Faroe","America/Godthab":"America/Nuuk","Pacific/Enderbury":"Pacific/Kanton","Pacific/Truk":"Pacific/Chuuk","Pacific/Ponape":"Pacific/Pohnpei","Africa/Asmera":"Africa/Asmara","America/Buenos_Aires":"America/Argentina/Buenos_Aires","America/Catamarca":"America/Argentina/Catamarca","America/Cordoba":"America/Argentina/Cordoba","America/Jujuy":"America/Argentina/Jujuy","America/Mendoza":"America/Argentina/Mendoza","America/Indianapolis":"America/Indiana/Indianapolis","America/Louisville":"America/Kentucky/Louisville"};function xt(r){try{return new Intl.DateTimeFormat("en-US",{timeZone:r}),!0}catch{return!1}}function Xe(r){let e=Yt[r];return e&&xt(e)?e:r}var je=new Map;function Y(r){if(r==null||r==="local")return"local";if(typeof r!="string"||r.trim()==="")throw new RangeError(`neram: unknown time zone ${JSON.stringify(r)}`);let e=je.get(r);if(e)return e;let t,n=r.toUpperCase();if(n==="UTC"||n==="Z"||n==="GMT"||n==="ETC/UTC"||n==="ETC/GMT")t="UTC";else{let s=re(r);if(s!==void 0)t=s===0?"UTC":K(s);else try{let i=new Intl.DateTimeFormat("en-US",{timeZone:r}).resolvedOptions().timeZone;t=Xe(i.toLowerCase()===r.toLowerCase()?i:r)}catch{throw new RangeError(`neram: unknown time zone "${r}"`)}}return je.set(r,t),t}var Ve=new Map;function Et(r){let e=Ve.get(r);return e||(e=new Intl.DateTimeFormat("en-US",{timeZone:r,hourCycle:"h23",era:"short",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric"}),Ve.set(r,e)),e}function we(r,e){let t=Et(e).formatToParts(new Date(r)),n=0,s=0,i=0,a=0,u=0,o=0,l=!1;for(let d of t)switch(d.type){case"year":n=Number(d.value);break;case"month":s=Number(d.value)-1;break;case"day":i=Number(d.value);break;case"hour":a=Number(d.value)%24;break;case"minute":u=Number(d.value);break;case"second":o=Number(d.value);break;case"era":l=/^b/i.test(d.value);break}l&&(n=1-n);let m=r-(r%1e3+1e3)%1e3;return Math.round((M(n,s,i,a,u,o)-m)/6e4)}var De=864e5,Ut=5e4,Ge=-1e9,_e=new Map;function $t(r,e){let t=_e.get(e);t||(t=new Map,_e.set(e,t));let n=Math.floor(r/De),s=t.get(n);if(s!==void 0)return s===Ge?we(r,e):s;let i=we(n*De,e),a=we(n*De+De-1e3,e);return t.size>=Ut&&t.clear(),t.set(n,i===a?i:Ge),i===a?i:we(r,e)}var Ce=new Map;function B(r,e){if(e==="UTC")return 0;if(e==="local")return-new Date(r).getTimezoneOffset()||0;let t=Ce.get(e);return t===void 0&&!Ce.has(e)&&(t=re(e),Ce.set(e,t)),t!==void 0?t:$t(r,e)}function $(r,e){if(e==="local"&&r.y>=100)return new Date(r.y,r.M,r.D,r.h,r.m,r.s,r.ms).getTime();let t=We(r);if(e==="UTC")return t;let n=re(e);if(n!==void 0)return t-n*6e4;let s=B(t-864e5,e),i=B(t+864e5,e),a=new Set([B(t,e),s,i]),u=[];for(let o of a)B(t-o*6e4,e)===o&&u.push(o);return u.length?t-Math.max(...u)*6e4:t-s*6e4}function se(r){let e=Math.floor(r/864e5),t=r-e*864e5,n=Me(e),s=Math.floor(t/36e5);t-=s*36e5;let i=Math.floor(t/6e4);t-=i*6e4;let a=Math.floor(t/1e3);return{y:n.y,M:n.M,D:n.D,h:s,m:i,s:a,ms:t-a*1e3,dow:n.dow}}function Qe(r,e){return se(r+e*6e4)}function me(){return Xe(new Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC")}function ke(r){return r%4===0&&r%100!==0||r%400===0}function Me(r){let e=r+719468,t=Math.floor(e/146097),n=e-t*146097,s=Math.floor((n-Math.floor(n/1460)+Math.floor(n/36524)-Math.floor(n/146096))/365),i=n-(365*s+Math.floor(s/4)-Math.floor(s/100)),a=Math.floor((5*i+2)/153),u=i-Math.floor((153*a+2)/5)+1,o=a<10?a+2:a-10;return{y:s+t*400+(o<=1?1:0),M:o,D:u,dow:(r%7+7+4)%7}}var Ct=[31,28,31,30,31,30,31,31,30,31,30,31];function S(r,e){return e===1&&ke(r)?29:Ct[e]}function Ne(r){return ke(r)?366:365}function L(r,e,t){return Math.round((M(r,e,t)-M(r,0,1))/864e5)+1}function et(r,e,t){return new Date(M(r,e,t)).getUTCDay()}function v(r,e,t,n,s){let i=L(r,e,t),a=(et(r,e,t)-n+7)%7,u=i-a,o=(et(r,0,1)-n+7)%7,l=7-o>=s?1-o:8-o;return u<l?v(r-1,11,31,n,s):u+6-Ne(r)>=s?{week:1,year:r+1}:{week:Math.floor((u-l)/7)+1,year:r}}function Se(r,e,t){for(let n=31;n>24;n--){let s=v(r,11,n,e,t);if(s.year===r)return s.week}return 52}var Le={normalizeSpaces:!0},Wt=/[\u00a0\u2007\u2009\u202f]/g;function C(r){return Le.normalizeSpaces?r.replace(Wt," "):r}var Oe=Intl,tt=new Map;function ce(r,e="en",t="conjunction",n="long"){if(Oe.ListFormat){let i=`${e}|${t}|${n}`,a=tt.get(i);return a||(a=new Oe.ListFormat(e,{type:t,style:n}),tt.set(i,a)),C(a.format(r))}if(r.length<=1)return r.join("");if(t==="unit")return r.join(", ");let s=t==="disjunction"?"or":"and";return r.length===2?`${r[0]} ${s} ${r[1]}`:`${r.slice(0,-1).join(", ")}, ${s} ${r.at(-1)}`}var nt=new Map;function le(r,e,t,n="long"){let s=`${t}|${e}|${n}`,i=nt.get(s);if(i===void 0){try{i=new Intl.NumberFormat(t,{style:"unit",unit:e,unitDisplay:n})}catch{i=null}nt.set(s,i)}return i?C(i.format(r)):`${r} ${e}${Math.abs(r)===1?"":"s"}`}var rt=new Map;function st(r,e,t,n,s){if(Oe.RelativeTimeFormat){let u=`${t}|${n}|${s}`,o=rt.get(u);return o||(o=new Oe.RelativeTimeFormat(t,{style:n,numeric:s}),rt.set(u,o)),C(o.format(r,e))}if(s==="auto"){if(r===0)return e==="day"?"today":"now";if(e==="day"&&r===1)return"tomorrow";if(e==="day"&&r===-1)return"yesterday"}let i=Math.abs(r),a=`${i} ${e}${i===1?"":"s"}`;return r<0||Object.is(r,-0)?`${a} ago`:`in ${a}`}var Lt={...X(5,"MV"),...X(6,"AF BH DJ DZ EG IQ IR JO KW LY OM QA SD SY"),...X(0,"AG AS BD BR BS BT BW BZ CA CO DM DO ET GT GU HK HN ID IL IN IS JM JP KE KH KR LA MH MM MO MT MX MZ NI NP PA PE PH PK PR PT PY SA SG SV TH TT TW UM US VE VI WS YE ZA ZW")},zt={...X([5],"IR"),...X([0],"IN UG"),...X([4,5],"AF"),...X([5,6],"BH DZ EG IL IQ JO KW LY OM QA SA SD SY YE")},Ft=new Set("AD AN AT AX BE BG CH CZ DE DK EE ES FI FJ FO FR GB GF GG GI GP GR HU IE IM IS IT JE LI LT LU MC MQ NL NO PL RE RU SE SJ SK SM VA".split(" ")),Pt=["sun","mon","tue","wed","thu","fri","sat"];function X(r,e){return Object.fromEntries(e.split(" ").map(t=>[t,r]))}function Ht(r){try{let e=new Intl.Locale(r);return e.region??(typeof e.maximize=="function"?e.maximize().region:void 0)}catch{return/^[a-z]{2,3}[-_]([A-Z]{2})\b/i.exec(r)?.[1].toUpperCase()}}function it(r){let e=Ht(r)??"001",t=Lt[e]??1,n=/-u(?:-[a-z0-9]{2,8})*?-fw-([a-z]{3})\b/i.exec(r);if(n){let s=Pt.indexOf(n[1].toLowerCase());s>=0&&(t=s)}return{firstDay:t,minimalDays:Ft.has(e)?4:1,weekend:zt[e]??[6,0]}}var at=new Map;function Q(r){try{return Intl.getCanonicalLocales(r)[0]??"en"}catch{throw new RangeError(`neram: invalid locale "${r}"`)}}function Zt(r){return it(r)}function I(r){let e=at.get(r);if(e)return e;let t=g=>new Intl.DateTimeFormat(r,{...g,timeZone:"UTC"}),n=g=>{let k=t(g);return{format:T=>C(k.format(T)),formatToParts:T=>k.formatToParts(T).map(R=>({...R,value:C(R.value)}))}},s=n({month:"long"}),i=n({month:"short"}),a=n({month:"long",day:"numeric"}),u=[],o=[];for(let g=0;g<12;g++){let k=Date.UTC(2021,g,15),T=a.formatToParts(k).find(R=>R.type==="month")?.value;u.push(T??s.format(k)),o.push(i.format(k).replace(/\.$/,""))}let l=n({weekday:"long"}),m=n({weekday:"short"}),d=n({weekday:"narrow"}),c=r.toLowerCase().startsWith("en"),f=[],h=[],y=[];for(let g=0;g<7;g++){let k=Date.UTC(2021,0,3+g);f.push(l.format(k));let T=m.format(k).replace(/\.$/,"");h.push(T),y.push(c?T.slice(0,2):d.format(k))}let b=n({hour:"numeric",hour12:!0}),p=g=>b.formatToParts(g).find(k=>k.type==="dayPeriod")?.value,w=[p(Date.UTC(2021,0,1,9))??"AM",p(Date.UTC(2021,0,1,15))??"PM"];return e={months:u,monthsShort:o,weekdays:f,weekdaysShort:h,weekdaysMin:y,meridiem:w,week:Zt(r)},at.set(r,e),e}var ot=new Map,qt={one:"st",two:"nd",few:"rd",other:"th"};function x(r,e){if(!e.toLowerCase().startsWith("en"))return`${r}.`;let t=ot.get(e);return t||(t=new Intl.PluralRules(e,{type:"ordinal"}),ot.set(e,t)),`${r}${qt[t.select(r)]??"th"}`}var ut=new Map;function ze(r){let e=ut.get(r);if(e)return e;let t=I(r),n=(a,u)=>o=>o===void 0?a.slice():a[u(o)],s=a=>a.month(),i=a=>a.day();return e=Object.freeze({name:r,firstDayOfWeek:()=>t.week.firstDay,months:n(t.months,s),monthsShort:n(t.monthsShort,s),weekdays:n(t.weekdays,i),weekdaysShort:n(t.weekdaysShort,i),weekdaysMin:n(t.weekdaysMin,i),meridiem:(a,u,o)=>{let l=t.meridiem[a<12?0:1];return o?l.toLocaleLowerCase(r):l},ordinal:a=>x(a,r),week:()=>({...t.week,weekend:t.week.weekend.slice()})}),ut.set(r,e),e}var mt={ms:"millisecond",s:"second",m:"minute",h:"hour",d:"day",D:"date",w:"week",W:"isoWeek",M:"month",Q:"quarter",y:"year"},ct=new Set(["millisecond","second","minute","hour","day","date","week","isoWeek","month","quarter","year"]);function E(r){if(r==null)return;if(mt[r])return mt[r];if(ct.has(r))return r;let e=r.toLowerCase().replace(/s$/,"");if(e==="isoweek")return"isoWeek";if(ct.has(e))return e;throw new RangeError(`neram: unknown unit "${r}"`)}var z=1e3,F=60*z,P=60*F,U=24*P,de=7*U,Fe=365.2425*U,fe=Fe/12,Ie={millisecond:1,second:z,minute:F,hour:P};function Te(r,e){let t=Math.abs(r),n=r<0?-1:1,s=a=>n*Math.round(a);if(t<45*z)return{value:s(t/z),unit:"second"};if(t<45*F)return{value:s(t/F),unit:"minute"};if(t<22*P)return{value:s(t/P),unit:"hour"};if(t<26*U)return{value:s(t/U),unit:"day"};let i=e!==void 0?Math.abs(e):t/fe;return i<10.5?{value:s(Math.max(1,i)),unit:"month"}:{value:s(Math.max(1,i/12)),unit:"year"}}function he(r,e,t,n={}){let s=n.style??"long";return n.withoutSuffix?le(Math.abs(r),e,t,s):st(r,e,t,s,n.numeric??"auto")}var j=["years","months","weeks","days","hours","minutes","seconds","milliseconds"],Re="Invalid Duration",lt={years:Fe,months:fe,weeks:de,days:U,hours:P,minutes:F,seconds:z,milliseconds:1},Bt=/^([+-])?P(?:(-?[\d.,]+)Y)?(?:(-?[\d.,]+)M)?(?:(-?[\d.,]+)W)?(?:(-?[\d.,]+)D)?(?:T(?:(-?[\d.,]+)H)?(?:(-?[\d.,]+)M)?(?:(-?[\d.,]+)S)?)?$/i;function ve(r){if(j.includes(r))return r;switch(E(r)){case"year":return"years";case"quarter":throw new RangeError("neram: use months for quarter durations");case"month":return"months";case"week":case"isoWeek":return"weeks";case"day":case"date":return"days";case"hour":return"hours";case"minute":return"minutes";case"second":return"seconds";default:return"milliseconds"}}var ie=class r{#e;constructor(e,t="milliseconds"){let n={years:0,months:0,weeks:0,days:0,hours:0,minutes:0,seconds:0,milliseconds:0};if(e instanceof r)Object.assign(n,e.toObject());else if(typeof e=="number")n[ve(t)]=e;else if(typeof e=="string"){let s=Bt.exec(e.trim());if(!s||e.trim().toUpperCase()==="P"||/T$/i.test(e.trim()))throw new RangeError(`neram: invalid ISO 8601 duration "${e}"`);let i=s[1]==="-"?-1:1;j.forEach((u,o)=>{if(u==="milliseconds")return;let l=s[o+2];l&&(n[u]=i*Number(l.replace(",",".")))});let a=Math.trunc(n.seconds);n.milliseconds=Math.round((n.seconds-a)*1e3),n.seconds=a}else if(e)for(let[s,i]of Object.entries(e))i!=null&&(n[ve(s)]+=i);this.#e=n}isValid(){return j.every(e=>Number.isFinite(this.#e[e]))}get years(){return this.#e.years}get months(){return this.#e.months}get weeks(){return this.#e.weeks}get days(){return this.#e.days}get hours(){return this.#e.hours}get minutes(){return this.#e.minutes}get seconds(){return this.#e.seconds}get milliseconds(){return this.#e.milliseconds}get(e){return this.#e[ve(e)]}as(e){return this.valueOf()/lt[ve(e)]}asMilliseconds(){return this.as("milliseconds")}asSeconds(){return this.as("seconds")}asMinutes(){return this.as("minutes")}asHours(){return this.as("hours")}asDays(){return this.as("days")}asWeeks(){return this.as("weeks")}asMonths(){return this.as("months")}asYears(){return this.as("years")}valueOf(){if(!this.isValid())return NaN;let e=0;for(let t of j)e+=this.#e[t]*lt[t];return e}add(e,t){let n=e instanceof r?e:new r(e,t),s={};for(let i of j)s[i]=this.#e[i]+n.get(i);return new r(s)}subtract(e,t){let n=e instanceof r?e:new r(e,t);return this.add(n.negate())}negate(){let e={};for(let t of j)e[t]=-this.#e[t]||0;return new r(e)}abs(){return this.valueOf()<0?this.negate():this}sign(){let e=this.valueOf();return e===0?0:e<0?-1:1}isZero(){return j.every(e=>this.#e[e]===0)}normalize(){if(!this.isValid())return this;let e=this.#e,t=e.weeks*de+e.days*U+e.hours*P+e.minutes*F+e.seconds*z+e.milliseconds,n=e.years*12+e.months,s=t<0?-1:1,i=Math.abs(t),a=c=>{let f=Math.floor(i/c);return i-=f*c,s*f||0},u=a(U),o=a(P),l=a(F),m=a(z),d=s*Math.round(i)||0;return new r({years:Math.trunc(n/12)||0,months:n%12||0,days:u,hours:o,minutes:l,seconds:m,milliseconds:d})}humanize(e=!1,t="en"){if(!this.isValid())return Re;let n=typeof e=="object"?e:{withoutSuffix:!e},s=this.#e.years*12+this.#e.months,i=this.valueOf()-s*fe,{value:a,unit:u}=Te(this.valueOf(),i===0&&s!==0?s:void 0);return he(a,u,n.locale??t,{numeric:"always",...n})}toLocaleString(e="en",t="long"){if(!this.isValid())return Re;let n=Intl.DurationFormat;if(n)return C(new n(e,{style:t}).format(this.toObject()));let s=t==="digital"?"narrow":t,i=j.filter(a=>this.#e[a]!==0).map(a=>le(this.#e[a],a.slice(0,-1),e,s));return i.length?ce(i,e,"unit",s):le(0,"second",e,s)}format(e="HH:mm:ss"){if(!this.isValid())return Re;let t=this.abs().normalize(),n=(i,a=2)=>String(i).padStart(a,"0"),s=e.replace(/\[([^\]]*)\]|YYYY|Y|MM|M|DD|D|HH|H|mm|m|ss|s|SSS/g,(i,a)=>{if(a!==void 0)return a;switch(i){case"Y":return String(t.years);case"YYYY":return n(t.years,4);case"M":return String(t.months);case"MM":return n(t.months);case"D":return String(t.days);case"DD":return n(t.days);case"H":return String(t.hours);case"HH":return n(t.hours);case"m":return String(t.minutes);case"mm":return n(t.minutes);case"s":return String(t.seconds);case"ss":return n(t.seconds);default:return n(t.milliseconds,3)}});return this.sign()<0?`-${s}`:s}toISOString(){if(!this.isValid())throw new RangeError("neram: invalid duration");let e={...this.#e};e.days+=e.weeks*7;let t=[e.years,e.months,e.days,e.hours,e.minutes,e.seconds+e.milliseconds/1e3],n=t.every(o=>o<=0)&&t.some(o=>o<0),s=n?-1:1,i=o=>String(Math.round(s*o*1e3)/1e3),a="";e.years&&(a+=`${i(e.years)}Y`),e.months&&(a+=`${i(e.months)}M`),e.days&&(a+=`${i(e.days)}D`);let u="";return e.hours&&(u+=`${i(e.hours)}H`),e.minutes&&(u+=`${i(e.minutes)}M`),(e.seconds||e.milliseconds)&&(u+=`${i(e.seconds+e.milliseconds/1e3)}S`),!a&&!u?"PT0S":`${n?"-":""}P${a}${u?`T${u}`:""}`}toJSON(){return this.isValid()?this.toISOString():null}toString(){return this.isValid()?this.toISOString():Re}toObject(){return{...this.#e}}};function V(r,e){return new ie(r,e)}function Ae(r){return r instanceof ie}var jt=/\[([^\]]*)\]|LTS|LT|LLLL|LLL|LL|L|llll|lll|ll|l|YYYY|YY|GGGG|gggg|MMMM|MMM|MM|M|Qo|Q|DDDD|DDD|Do|DD|D|dddd|ddd|dd|d|E|HH|H|hh|h|kk|k|mm|m|ss|s|S{1,9}|A|a|ZZ|Z|X|x|WW|W|ww|w|zzz|z/g,N=(r,e=2)=>{let t=String(Math.abs(r)).padStart(e,"0");return r<0?`-${t}`:t},dt={LT:{timeStyle:"short"},LTS:{timeStyle:"medium"},L:{year:"numeric",month:"2-digit",day:"2-digit"},LL:{dateStyle:"long"},LLL:{dateStyle:"long",timeStyle:"short"},LLLL:{dateStyle:"full",timeStyle:"short"},l:{year:"numeric",month:"numeric",day:"numeric"},ll:{dateStyle:"medium"},lll:{dateStyle:"medium",timeStyle:"short"},llll:{weekday:"short",year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}};function ft(r,e){let{wall:t,locale:n}=r,s,i=()=>s??=I(n),a=()=>v(t.y,t.M,t.D,1,4),u=()=>v(t.y,t.M,t.D,r.weekStart,i().week.minimalDays),o=t.h%12||12,l=c=>{if(dt[c])return r.intl(dt[c]);switch(c){case"YYYY":return t.y>=0&&t.y<=9999?N(t.y,4):(t.y<0?"-":"+")+N(Math.abs(t.y),6);case"YY":return N((t.y%100+100)%100);case"GGGG":return N(a().year,4);case"gggg":return N(u().year,4);case"M":return String(t.M+1);case"MM":return N(t.M+1);case"MMM":return i().monthsShort[t.M];case"MMMM":return i().months[t.M];case"Q":return String(Math.floor(t.M/3)+1);case"Qo":return x(Math.floor(t.M/3)+1,n);case"D":return String(t.D);case"DD":return N(t.D);case"Do":return x(t.D,n);case"DDD":return String(L(t.y,t.M,t.D));case"DDDD":return N(L(t.y,t.M,t.D),3);case"d":return String(t.dow);case"E":return String(t.dow||7);case"dd":return i().weekdaysMin[t.dow];case"ddd":return i().weekdaysShort[t.dow];case"dddd":return i().weekdays[t.dow];case"H":return String(t.h);case"HH":return N(t.h);case"h":return String(o);case"hh":return N(o);case"k":return String(t.h||24);case"kk":return N(t.h||24);case"m":return String(t.m);case"mm":return N(t.m);case"s":return String(t.s);case"ss":return N(t.s);case"A":return i().meridiem[t.h<12?0:1];case"a":return i().meridiem[t.h<12?0:1].toLowerCase();case"Z":return K(r.offset);case"ZZ":return K(r.offset,"");case"X":return String(Math.floor(r.ms/1e3));case"x":return String(r.ms);case"W":return String(a().week);case"WW":return N(a().week);case"w":return String(u().week);case"ww":return N(u().week);case"z":return r.intl({timeZoneName:"short"}).split(/,?\s/).pop()??"";case"zzz":return Gt(r);default:return N(t.ms,3).padEnd(c.length,"0").slice(0,c.length)}},m=Vt(e),d=m[0];for(let c=1;c<m.length;c+=2)d+=l(m[c])+m[c+1];return d}var Ye=new Map;function Vt(r){let e=Ye.get(r);if(e)return e;e=[];let t="",n=0;for(let s of r.matchAll(jt))t+=r.slice(n,s.index),n=s.index+s[0].length,s[1]!==void 0?t+=s[1]:(e.push(t,s[0]),t="");return e.push(t+r.slice(n)),Ye.size>500&&Ye.clear(),Ye.set(r,e),e}function Gt(r){let e=r.intl({year:"numeric",timeZoneName:"long"}),t=r.intl({year:"numeric"});return e.replace(t,"").replace(/^[\s,]+|[\s,]+$/g,"")}var G={kind:"epoch",ms:NaN},_t=/^([+-]\d{6}|\d{4})(?:-?(\d{2})(?:-?(\d{2}))?)?(?:[T\s](\d{2})(?::?(\d{2})(?::?(\d{2})(?:[.,](\d{1,9}))?)?)?)?\s*(Z|[+-]\d{2}(?::?\d{2})?)?(?:\[!?([^\]=]+)\])?(?:\[[^\]]*\])*$/i;function Pe(r){return r.M>=0&&r.M<=11&&r.D>=1&&r.D<=S(r.y,r.M)&&r.h>=0&&(r.h<24||r.h===24&&r.m===0&&r.s===0&&r.ms===0)&&r.m>=0&&r.m<60&&r.s>=0&&r.s<61&&r.ms>=0&&r.ms<1e3}function H(r,e){let t=r.charCodeAt(e)-48,n=r.charCodeAt(e+1)-48;return t>=0&&t<=9&&n>=0&&n<=9?t*10+n:-1}function Jt(r){let e=r.length;if(e<10||r.charCodeAt(4)!==45||r.charCodeAt(7)!==45)return;let t=H(r,0),n=H(r,2),s=H(r,5),i=H(r,8);if(t<0||n<0||s<0||i<0)return;let a=0,u=0,o=0,l=0,m,d=10;if(d<e){let f=r.charCodeAt(d);if(f!==84&&f!==116&&f!==32||e<16||r.charCodeAt(13)!==58||(a=H(r,11),u=H(r,14),a<0||u<0))return;if(d=16,r.charCodeAt(d)===58){if(o=H(r,17),o<0)return;if(d=19,r.charCodeAt(d)===46){let h=d+1,y=0,b=0;for(;h<e;h++){let p=r.charCodeAt(h)-48;if(p<0||p>9)break;b<3&&(y=y*10+p),b++}if(b===0||b>9)return;l=b===1?y*100:b===2?y*10:y,d=h}}if(d<e){let h=r.charCodeAt(d);if((h===90||h===122)&&d===e-1)m=0,d++;else if((h===43||h===45)&&e-d===6&&r.charCodeAt(d+3)===58){let y=H(r,d+1),b=H(r,d+4);if(y<0||b<0)return;if(y>23||b>59)return G;m=(h===45?-1:1)*(y*60+b),d=e}else return}}let c={y:t*100+n,M:s-1,D:i,h:a,m:u,s:o,ms:l};return Pe(c)?(c.s===60&&(c.s=59),{kind:"wall",wall:c,offset:m}):G}function Kt(r){let e=Jt(r);if(e)return e;let t=_t.exec(r.trim());if(!t)return;let n={y:Number(t[1]),M:t[2]?Number(t[2])-1:0,D:t[3]?Number(t[3]):1,h:t[4]?Number(t[4]):0,m:t[5]?Number(t[5]):0,s:t[6]?Number(t[6]):0,ms:t[7]?Math.floor(+`0.${t[7]}`*1e3):0};if(!Pe(n))return G;n.s===60&&(n.s=59);let s=t[8]?re(t[8].replace(/^([+-]\d{2})$/,"$1:00")):void 0;return t[8]&&s===void 0?G:{kind:"wall",wall:n,offset:s,zone:t[9]}}function yt(r){let e=Kt(r);if(e)return e;let t=Date.parse(r);return Number.isNaN(t)?G:{kind:"epoch",ms:t}}var Xt=/\[([^\]]*)\]|YYYY|YY|MMMM|MMM|MM|M|Do|DD|D|dddd|ddd|dd|HH|H|hh|h|kk|k|mm|m|ss|s|S{1,3}|A|a|ZZ|Z|X|x/g;function ae(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ht(r){return`(${[...r].sort((e,t)=>t.length-e.length).map(ae).join("|")})`}var ee=r=>(e,t)=>{t[r]=Number(e)};function bt(r,e,t){let n=I(t),s=[],i="",a=0;for(let c of e.matchAll(Xt)){i+=ae(e.slice(a,c.index)).replace(/\s+/g,"\\s+"),a=c.index+c[0].length;let f=c[0];if(c[1]!==void 0){i+=ae(c[1]);continue}switch(f){case"YYYY":i+="([+-]?\\d{4,6})",s.push(ee("y"));break;case"YY":i+="(\\d{2})",s.push((h,y)=>{let b=Number(h);y.y=b+(b>68?1900:2e3)});break;case"MMMM":case"MMM":{i+=ht([...n.months,...n.monthsShort]),s.push((h,y)=>{let b=h.toLowerCase(),p=n.months.findIndex(w=>w.toLowerCase()===b);p<0&&(p=n.monthsShort.findIndex(w=>w.toLowerCase()===b)),y.M=p+1});break}case"MM":case"M":i+=f==="MM"?"(\\d{2})":"(\\d{1,2})",s.push(ee("M"));break;case"Do":i+="(\\d{1,2})(?:st|nd|rd|th|\\.)?",s.push(ee("D"));break;case"DD":case"D":i+=f==="DD"?"(\\d{2})":"(\\d{1,2})",s.push(ee("D"));break;case"dddd":case"ddd":case"dd":i+=ht([...n.weekdays,...n.weekdaysShort,...n.weekdaysMin]),s.push(()=>{});break;case"HH":case"H":case"hh":case"h":case"kk":case"k":i+=f.length===2?"(\\d{2})":"(\\d{1,2})",s.push(f[0]==="k"?(h,y)=>{y.h=Number(h)%24}:ee("h"));break;case"mm":case"m":i+=f==="mm"?"(\\d{2})":"(\\d{1,2})",s.push(ee("m"));break;case"ss":case"s":i+=f==="ss"?"(\\d{2})":"(\\d{1,2})",s.push(ee("s"));break;case"A":case"a":i+=`(${ae(n.meridiem[0])}|${ae(n.meridiem[1])}|am|pm|a\\.m\\.|p\\.m\\.)`,s.push((h,y)=>{let b=h.toLowerCase();y.pm=b===n.meridiem[1].toLowerCase()||b.startsWith("p")});break;case"ZZ":case"Z":i+="(Z|[+-]\\d{2}:?\\d{2})",s.push((h,y)=>{y.offset=re(h)??NaN});break;case"X":i+="(-?\\d+(?:\\.\\d+)?)",s.push((h,y)=>{y.epoch=Number(h)*1e3});break;case"x":i+="(-?\\d+)",s.push((h,y)=>{y.epoch=Number(h)});break;default:i+=`(\\d{1,${f.length}})`,s.push((h,y)=>{y.ms=Math.round(+`0.${h}`*1e3)})}}i+=ae(e.slice(a)).replace(/\s+/g,"\\s+");let u=new RegExp(`^\\s*${i}\\s*$`,"i").exec(r);if(!u)return G;let o={};if(s.forEach((c,f)=>c(u[f+1],o)),o.epoch!==void 0)return{kind:"epoch",ms:o.epoch};let l=o.h??0;if(o.pm!==void 0){if(l<1||l>12)return G;o.pm&&l<12&&(l+=12),!o.pm&&l===12&&(l=0)}let m=new Date,d={y:o.y??m.getFullYear(),M:o.M!==void 0?o.M-1:o.y!==void 0?0:m.getMonth(),D:o.D??1,h:l,m:o.m??0,s:o.s??0,ms:o.ms??0};return Pe(d)?{kind:"wall",wall:d,offset:o.offset}:G}var O={locale:"en",zone:"local",normalizeSpaces:!0},pt=new Map,_=class r{#e;#n;#r;#o;#c;#u;constructor(e,t,n,s){this.#e=Number.isFinite(e)&&Math.abs(e)<=864e13?e:NaN,this.#n=t,this.#r=n,this.#o=s}#t(e,t=this.#n,n=this.#r,s=this.#o){return new r(e,t,n,s)}#a(){return this.#u??=this.isValid()?B(this.#e,this.#n):NaN}#s(){return this.#c||(this.#c=this.isValid()?Qe(this.#e,this.#a()):{y:NaN,M:NaN,D:NaN,h:NaN,m:NaN,s:NaN,ms:NaN,dow:NaN}),this.#c}#i(e){return this.#t($(e,this.#n))}#d(){return this.#o??O.weekStart??I(this.#r).week.firstDay}#f(e){let t=this.#s(),n=t.y*12+t.M+wt(e),s=Math.floor(n/12),i=n-s*12;return this.#i({...t,y:s,M:i,D:Math.min(t.D,S(s,i))})}#l(e){let t=this.#s();return this.#i({...t,D:t.D+wt(e)})}#h(e,t=this.#r){if(!this.isValid())return"Invalid Date";let n=Ke(this.#n),s=this.#n==="local"?void 0:n?"UTC":this.#n,i=`${t}|${s}|${JSON.stringify(e)}`,a=pt.get(i);a||(a=new Intl.DateTimeFormat(t,{...e,timeZone:s}),pt.set(i,a));let u=C(a.format(n?this.#e+this.#a()*6e4:this.#e));return n&&e.timeZoneName?u.replace(/UTC|GMT/,`GMT${K(this.#a())}`):u}isValid(){return!Number.isNaN(this.#e)}clone(){return this}get(e){let t=this.#s();switch(E(e)){case"year":return t.y;case"quarter":return Math.floor(t.M/3)+1;case"month":return t.M;case"week":return this.week();case"isoWeek":return this.isoWeek();case"date":return t.D;case"day":return t.dow;case"hour":return t.h;case"minute":return t.m;case"second":return t.s;default:return t.ms}}set(e,t){if(!this.isValid())return this;if(typeof e=="object"){let i=this,a=["year","month","date","day","hour","minute","second","millisecond"];for(let u of a){let o=e[u];o!==void 0&&(i=i.set(u,o))}return i}let n=t,s={...this.#s()};switch(E(e)){case"year":return this.#i({...s,y:n,D:Math.min(s.D,S(n,s.M))});case"quarter":return this.#f((n-(Math.floor(s.M/3)+1))*3);case"month":{let i=s.y+Math.floor(n/12),a=(n%12+12)%12;return this.#i({...s,y:i,M:a,D:Math.min(s.D,S(i,a))})}case"week":return this.#l((n-this.week())*7);case"isoWeek":return this.#l((n-this.isoWeek())*7);case"date":return this.#i({...s,D:n});case"day":return this.#l(n-s.dow);case"hour":return this.#i({...s,h:n});case"minute":return this.#i({...s,m:n});case"second":return this.#i({...s,s:n});default:return this.#i({...s,ms:n})}}year(e){return e===void 0?this.get("year"):this.set("year",e)}month(e){return e===void 0?this.get("month"):this.set("month",e)}date(e){return e===void 0?this.get("date"):this.set("date",e)}day(e){return e===void 0?this.get("day"):this.set("day",e)}hour(e){return e===void 0?this.get("hour"):this.set("hour",e)}minute(e){return e===void 0?this.get("minute"):this.set("minute",e)}second(e){return e===void 0?this.get("second"):this.set("second",e)}millisecond(e){return e===void 0?this.get("millisecond"):this.set("millisecond",e)}quarter(e){return e===void 0?this.get("quarter"):this.set("quarter",e)}dayOfYear(e){let t=this.#s(),n=L(t.y,t.M,t.D);return e===void 0?n:this.#l(e-n)}isoWeekday(e){let t=this.#s().dow||7;return e===void 0?t:this.#l(e-t)}weekday(e){let t=(this.#s().dow-this.#d()+7)%7;return e===void 0?t:this.#l(e-t)}week(){let e=this.#s();return v(e.y,e.M,e.D,this.#d(),I(this.#r).week.minimalDays).week}weekYear(){let e=this.#s();return v(e.y,e.M,e.D,this.#d(),I(this.#r).week.minimalDays).year}isoWeek(){let e=this.#s();return v(e.y,e.M,e.D,1,4).week}isoWeekYear(){let e=this.#s();return v(e.y,e.M,e.D,1,4).year}isoWeeksInYear(){return Se(this.year(),1,4)}daysInMonth(){let e=this.#s();return S(e.y,e.M)}isLeapYear(){return ke(this.year())}add(e,t){if(!this.isValid())return this;if(typeof e!="number"){let s=Ae(e)?e:V(e);if(!s.isValid())return this.#t(NaN);let i=s.toObject(),a=this;(i.years||i.months)&&(a=a.#f(i.years*12+i.months)),(i.weeks||i.days)&&(a=a.#l(i.weeks*7+i.days));let u=i.hours*36e5+i.minutes*6e4+i.seconds*1e3+i.milliseconds;return u?a.#t(a.#e+u):a}let n=E(t??"millisecond");switch(n){case"year":return this.#f(e*12);case"quarter":return this.#f(e*3);case"month":return this.#f(e);case"week":case"isoWeek":return this.#l(e*7);case"day":case"date":return this.#l(e);default:return this.#t(this.#e+e*(Ie[n]??1))}}subtract(e,t){return typeof e=="number"?this.add(-e,t):this.add((Ae(e)?e:V(e)).negate())}startOf(e){if(!this.isValid())return this;let t=E(e),n={...this.#s()},s={h:0,m:0,s:0,ms:0};switch(t){case"year":return this.#i({...n,...s,M:0,D:1});case"quarter":return this.#i({...n,...s,M:Math.floor(n.M/3)*3,D:1});case"month":return this.#i({...n,...s,D:1});case"week":return this.#i({...n,...s,D:n.D-(n.dow-this.#d()+7)%7});case"isoWeek":return this.#i({...n,...s,D:n.D-(n.dow+6)%7});case"day":case"date":return this.#i({...n,...s});case"hour":return this.#t(this.#e-(n.m*6e4+n.s*1e3+n.ms));case"minute":return this.#t(this.#e-(n.s*1e3+n.ms));case"second":return this.#t(this.#e-n.ms);default:return this}}endOf(e){let t=E(e);return t==="millisecond"?this:this.startOf(t).add(1,t==="date"?"day":t).subtract(1,"millisecond")}round(e){if(!this.isValid())return this;let t=E(e),n=this.startOf(t),s=n.add(1,t==="date"?"day":t);return this.#e-n.#e<s.#e-this.#e?n:s}clamp(e,t){let n=this.#m(e),s=this.#m(t);return this.#e<n.#e?n.tz(this.#n):this.#e>s.#e?s.tz(this.#n):this}tz(e,t=!1){let n=Y(e);return this.isValid()?t?this.#t($(this.#s(),n),n):this.#t(this.#e,n):this.#t(NaN,n)}utc(e=!1){return this.tz("UTC",e)}local(e=!1){return this.tz("local",e)}timezone(){return this.#n==="local"?me():this.#n}isUTC(){return this.#n==="UTC"}isLocal(){return this.#n==="local"}utcOffset(e,t=!1){if(e===void 0)return this.#a();let n;if(typeof e=="string"){n=Y(e)==="UTC"?0:Number.NaN;let s=/^([+-])(\d{2}):?(\d{2})$/.exec(e);s&&(n=(s[1]==="-"?-1:1)*(Number(s[2])*60+Number(s[3])))}else n=Math.abs(e)<16?e*60:e;if(Number.isNaN(n))throw new RangeError(`neram: invalid offset "${e}"`);return this.tz(n===0?"UTC":K(n),t)}isDST(){if(!this.isValid())return!1;let e=this.year(),t=B(Date.UTC(e,0,1),this.#n),n=B(Date.UTC(e,6,1),this.#n);return t!==n&&this.#a()===Math.max(t,n)}localeData(){return ze(this.#r)}locale(e){return e===void 0?this.#r:this.#t(this.#e,this.#n,Q(e))}weekStart(e){return e===void 0?this.#d():this.#t(this.#e,this.#n,this.#r,e)}format(e="YYYY-MM-DDTHH:mm:ssZ"){return this.isValid()?ft({wall:this.#s(),ms:this.#e,offset:this.#a(),locale:this.#r,weekStart:this.#d(),intl:t=>this.#h(t)},e):"Invalid Date"}toLocaleString(e={dateStyle:"medium",timeStyle:"medium"},t){return this.#h(e,t?Q(t):this.#r)}from(e,t={}){if(!this.isValid())return"Invalid Date";let n=this.#m(e);if(!n.isValid())return"Invalid Date";let s=this.#e-n.#e,{value:i,unit:a}=Te(s,this.diff(n,"month",!0));return he(i,a,t.locale??this.#r,t)}fromNow(e={}){return this.from(this.#t(Date.now()),e)}to(e,t={}){return this.isValid()?this.#m(e).locale(this.#r).from(this,t):"Invalid Date"}toNow(e={}){return this.to(this.#t(Date.now()),e)}calendar(e,t={}){if(!this.isValid())return"Invalid Date";let n=(e===void 0?this.#t(Date.now()):this.#m(e)).tz(this.#n),s=this.startOf("day").diff(n.startOf("day"),"day"),i=this.#r.toLowerCase().startsWith("en"),a=i?" at ":" ",u=this.format("LT"),o=m=>m.charAt(0).toLocaleUpperCase(this.#r)+m.slice(1);if(Math.abs(s)<=1)return o(he(s,"day",this.#r))+a+u;let l=I(this.#r).weekdays[this.day()];return s>1&&s<7?o(l)+a+u:s<-1&&s>-7?(i?`Last ${l}`:o(l))+a+u:this.format(t.sameElse??"L")}#m(e){return e instanceof r?e:D(e,{zone:this.#n,locale:this.#r})}diff(e,t="millisecond",n=!1){let s=this.#m(e);if(!this.isValid()||!s.isValid())return NaN;let i=E(t),a=this.#e+this.#a()*6e4-(s.#e+s.#a()*6e4),u;switch(i){case"year":u=ye(this,s)/12;break;case"quarter":u=ye(this,s)/3;break;case"month":u=ye(this,s);break;case"week":case"isoWeek":u=a/de;break;case"day":case"date":u=a/U;break;default:u=(this.#e-s.#e)/(Ie[i]??1)}return n?u:Math.trunc(u)||0}durationTo(e){let t=this.#m(e);if(!this.isValid()||!t.isValid())return V(NaN);let n=t.#e<this.#e?-1:1,[s,i]=n>0?[this,t]:[t,this],a=Math.trunc(ye(i,s));s=s.add(a,"month");let u=Math.trunc(i.diff(s,"day"));s=s.add(u,"day");let o=i.#e-s.#e;return V({months:n*a,days:n*u,milliseconds:n*o}).normalize()}isBefore(e,t){let n=this.#m(e);return t?this.endOf(t).#e<n.#e:this.#e<n.#e}isAfter(e,t){let n=this.#m(e);return t?this.startOf(t).#e>n.#e:this.#e>n.#e}isSame(e,t){let n=this.#m(e);return t?this.startOf(t).#e<=n.#e&&n.#e<=this.endOf(t).#e:this.#e===n.#e}isSameOrBefore(e,t){return this.isSame(e,t)||this.isBefore(e,t)}isSameOrAfter(e,t){return this.isSame(e,t)||this.isAfter(e,t)}isBetween(e,t,n,s="()"){let[i,a]=[this.#m(e),this.#m(t)].sort((l,m)=>l.#e-m.#e),u=s[0]==="["?this.isSameOrAfter(i,n):this.isAfter(i,n),o=s[1]==="]"?this.isSameOrBefore(a,n):this.isBefore(a,n);return u&&o}isToday(){return this.isSame(this.#t(Date.now()),"day")}isTomorrow(){return this.isSame(this.#t(Date.now()).add(1,"day"),"day")}isYesterday(){return this.isSame(this.#t(Date.now()).subtract(1,"day"),"day")}isPast(){return this.#e<Date.now()}isFuture(){return this.#e>Date.now()}isWeekend(e){return(e===void 0?I(this.#r).week.weekend:He(e)).includes(this.day())}isBusinessDay(e={}){return this.isWeekend(e.weekend)?!1:e.holidays?.length?!this.#y(e).has(this.format("YYYY-MM-DD")):!0}addBusinessDays(e,t={}){if(!Number.isInteger(e))throw new RangeError(`neram: business days must be a whole number, got ${e}`);t.weekend!==void 0&&He(t.weekend);let n=this.#y(t);if(!this.isValid())return this;let s=e<0?-1:1,i=Math.abs(e),a=this;for(;i>0;)a=a.#l(s),!a.isWeekend(t.weekend)&&!n.has(a.format("YYYY-MM-DD"))&&i--;return a}subtractBusinessDays(e,t={}){return this.addBusinessDays(-e,t)}businessDaysUntil(e,t={}){t.weekend!==void 0&&He(t.weekend);let n=this.#m(e);if(!this.isValid()||!n.isValid())return NaN;let s=n.tz(this.#n).startOf("day"),i=this.startOf("day"),a=s.#e<i.#e?-1:1,u=this.#y(t),o=0;for(;a>0?i.#e<s.#e:i.#e>s.#e;)i=i.#l(a),!i.isWeekend(t.weekend)&&!u.has(i.format("YYYY-MM-DD"))&&(o+=a);return o}#y(e){return new Set((e.holidays??[]).map(t=>{let n=this.#m(t);if(!n.isValid())throw new RangeError(`neram: invalid holiday ${JSON.stringify(t)}`);return n.tz(this.#n).format("YYYY-MM-DD")}))}valueOf(){return this.#e}unix(){return Math.floor(this.#e/1e3)}toDate(){return new Date(this.#e)}toISOString(){return new Date(this.#e).toISOString()}toZonedISOString(){if(!this.isValid())return"Invalid Date";let e=this.#s().ms?".SSS":"";return`${this.format(`YYYY-MM-DDTHH:mm:ss${e}Z`)}[${this.timezone()}]`}toTemporal(){let e=globalThis.Temporal;if(!e)throw new Error("neram: Temporal is not available in this runtime");return e.ZonedDateTime.from(this.toZonedISOString())}toJSON(){return this.isValid()?this.toISOString():null}toString(){return this.isValid()?new Date(this.#e).toUTCString():"Invalid Date"}toObject(){let e=this.#s();return{year:e.y,month:e.M,date:e.D,hour:e.h,minute:e.m,second:e.s,millisecond:e.ms}}toArray(){let e=this.#s();return[e.y,e.M,e.D,e.h,e.m,e.s,e.ms]}[Symbol.toPrimitive](e){return e==="number"?this.#e:this.toString()}get[Symbol.toStringTag](){return"Neram"}};function ye(r,e){if(r.date()<e.date())return-ye(e,r);let t=(e.year()-r.year())*12+(e.month()-r.month()),n=r.add(t,"month").valueOf(),s=e.valueOf()-n<0,i=r.add(t+(s?-1:1),"month").valueOf();return-(t+(e.valueOf()-n)/(s?n-i:i-n))||0}function gt(r,e,t){if(r.kind==="epoch")return{ms:r.ms,zone:e};let n=e;return r.zone&&!t&&(n=Y(r.zone)),r.offset!==void 0?{ms:We(r.wall)-r.offset*6e4,zone:n}:{ms:$(r.wall,n),zone:n}}function Qt(r){return typeof r=="object"&&r!==null&&typeof r.epochMilliseconds=="number"}function Z(r,e,t,n){let s={};typeof e=="string"||Array.isArray(e)?s.format=e:e&&(s={...e}),typeof t=="boolean"?s.strict=t:typeof t=="string"&&(s.locale=t),typeof n=="boolean"&&(s.strict=n);let i=s.locale?Q(s.locale):O.locale,a=s.utc===!0||s.zone!==void 0,u=Y(s.utc?"UTC":s.zone??O.zone),o=s.weekStart;if(r instanceof _){let m=r;return a&&(m=m.tz(u)),s.locale&&(m=m.locale(i)),o!==void 0&&(m=m.weekStart(o)),m}let l;if(r===void 0)l=Date.now();else if(r===null)l=NaN;else if(r instanceof Date)l=r.getTime();else if(typeof r=="number")l=r;else if(typeof r=="string"){let m=s.format===void 0?void 0:Array.isArray(s.format)?s.format:[s.format];if(!m)({ms:l,zone:u}=gt(yt(r),u,a));else{l=NaN;for(let d of m){let c=gt(bt(r,d,i),u,a);if(!Number.isNaN(c.ms)&&!(s.strict&&new _(c.ms,c.zone,i,o).format(d)!==r.trim())){({ms:l,zone:u}=c);break}}}}else if(Array.isArray(r)){let[m=new Date().getFullYear(),d=0,c=1,f=0,h=0,y=0,b=0]=r,p={y:m,M:d,D:c,h:f,m:h,s:y,ms:b};l=r.length>=1&&r.length<=7&&Dt(p)?$(p,u):NaN}else if(Qt(r))l=r.epochMilliseconds,r.timeZoneId&&!a&&(u=Y(r.timeZoneId));else if(typeof r=="object"){let m=tn(r),d=m&&{y:m.year??new Date().getFullYear(),M:m.month??0,D:m.date??1,h:m.hour??0,m:m.minute??0,s:m.second??0,ms:m.millisecond??0};l=d&&Dt(d)?$(d,u):NaN}else l=NaN;return new _(l,u,i,o)}function wt(r){return r<0?-Math.round(-r):Math.round(r)}function He(r){if(!Array.isArray(r)||r.some(e=>!Number.isInteger(e)||e<0||e>6))throw new RangeError(`neram: weekend must list weekday numbers 0-6 (0 = Sunday), got ${JSON.stringify(r)}`);if(new Set(r).size===7)throw new RangeError("neram: weekend cannot include every day of the week");return r}var en={year:"year",years:"year",y:"year",month:"month",months:"month",M:"month",date:"date",dates:"date",D:"date",d:"date",day:"date",days:"date",hour:"hour",hours:"hour",h:"hour",minute:"minute",minutes:"minute",m:"minute",second:"second",seconds:"second",s:"second",millisecond:"millisecond",milliseconds:"millisecond",ms:"millisecond"};function tn(r){let e={},t=!1;for(let[n,s]of Object.entries(r)){if(s===void 0)continue;let i=en[n];if(!i||typeof s!="number"||e[i]!==void 0)return;e[i]=s,t=!0}return t?e:void 0}function Dt(r){return[r.y,r.M,r.D,r.h,r.m,r.s,r.ms].every(Number.isInteger)?r.M>=0&&r.M<=11&&r.D>=1&&r.D<=S(r.y,r.M)&&r.h>=0&&r.h<=23&&r.m>=0&&r.m<=59&&r.s>=0&&r.s<=59&&r.ms>=0&&r.ms<=999:!1}var Mt=new Set;function kt(r){return(r.length===1&&Array.isArray(r[0])&&typeof r[0][0]!="number"?r[0]:r).map(e=>Z(e)).filter(e=>e.isValid())}var D=Object.assign(Z,{utc(r,e,t){return Z(r,{format:e,strict:t,utc:!0})},tz(r,e,t){return Z(r,{format:t,zone:e})},unix(r){return Z(r*1e3)},now(){return Z()},duration:V,isDuration:Ae,Duration:ie,Neram:_,isNeram(r){return r instanceof _},min(...r){let e=kt(r);return e.length?e.reduce((t,n)=>n.valueOf()<t.valueOf()?n:t):null},max(...r){let e=kt(r);return e.length?e.reduce((t,n)=>n.valueOf()>t.valueOf()?n:t):null},sort(r){return r.map(e=>Z(e)).sort((e,t)=>e.valueOf()-t.valueOf())},range(r,e,t={}){let n=E(t.unit??"day"),s=t.step??1;if(typeof s!="number"||!Number.isFinite(s)||s<=0)throw new RangeError(`neram: range step must be a positive number, got ${String(s)}`);if(!(n in Ie)&&!Number.isInteger(s))throw new RangeError(`neram: range step must be a whole number of ${n}s, got ${s}`);let i=t.limit??1e5;if(!Number.isInteger(i)||i<0)throw new RangeError(`neram: range limit must be a whole number, got ${i}`);let a=Z(r),u=Z(e);if(!a.isValid()||!u.isValid())return[];let o=s*(u.valueOf()<a.valueOf()?-1:1),l=[];for(let m=0;;m++){let d=a.add(o*m,n);if((o>0?d.valueOf()>u.valueOf():d.valueOf()<u.valueOf())||t.exclusive&&d.valueOf()===u.valueOf())break;if(l.length===i)throw new RangeError(`neram: range has more than ${i} dates; use a larger step or pass { limit }`);l.push(d)}return l},locale(r){return r!==void 0&&(O.locale=Q(r)),O.locale},localeData(r){return ze(r?Q(r):O.locale)},environment(){let r=globalThis.process?.versions??{},e=Intl,t=!0;try{new Intl.NumberFormat("en",{style:"unit",unit:"hour"})}catch{t=!1}return{zone:me(),defaultZone:O.zone==="local"?me():O.zone,locale:O.locale,runtimeLocale:new Intl.DateTimeFormat().resolvedOptions().locale,icu:r.icu,cldr:r.cldr,tzdata:r.tz,features:{relativeTimeFormat:typeof e.RelativeTimeFormat=="function",listFormat:typeof e.ListFormat=="function",durationFormat:typeof e.DurationFormat=="function",supportedValuesOf:typeof e.supportedValuesOf=="function",unitFormat:t}}},guess(){return me()},zones(){let r=Intl.supportedValuesOf;return r?r("timeZone"):[]},config(r={}){return r.locale!==void 0&&(O.locale=Q(r.locale)),r.zone!==void 0&&(O.zone=Y(r.zone)),"weekStart"in r&&(O.weekStart=r.weekStart),r.normalizeSpaces!==void 0&&(Le.normalizeSpaces=O.normalizeSpaces=r.normalizeSpaces),{...O}},extend(r,e){return Mt.has(r)||(r(e,_,D),Mt.add(r)),D}});var nn=400*366*864e5,te=class{coerce(e){let t=D(e,{zone:this.tz}).valueOf();if(Number.isNaN(t))throw new RangeError(`neram: invalid date ${JSON.stringify(e)}`);return t}out(e,t){let n=D(e,{zone:this.tz});if(typeof t=="function")return t(n);let s=()=>n.format(this.allDay?"YYYY-MM-DD":"YYYY-MM-DDTHH:mm:ss"),i;switch(t??"neram"){case"neram":i=n;break;case"date":i=n.toDate();break;case"epoch":i=e;break;case"unix":i=Math.floor(e/1e3);break;case"iso":i=n.toISOString();break;case"zoned":i=n.toZonedISOString();break;case"local":i=s();break;case"record":i={utc:n.toISOString(),local:s(),tz:n.timezone(),epoch:e,allDay:this.allDay};break;default:throw new RangeError(`neram: unknown output format "${String(t)}"`)}return i}all(e={}){if(Ze("limit",e.limit),e.limit===void 0&&this.isInfinite())throw new RangeError("neram: this schedule never ends; pass { limit } or use between()");let t=[];for(let n of this.iterate(this.startMs())){if(e.limit!==void 0&&t.length>=e.limit)break;t.push(this.out(n,e.as))}return t}between(e,t,n={}){Ze("limit",n.limit);let s=n.inclusive??!0,i=this.coerce(e),a=this.coerce(t),u=[];for(let o of this.iterate(i)){if(o>a||!s&&o===a)break;if(!(!s&&o===i)){if(n.limit!==void 0&&u.length>=n.limit)break;u.push(this.out(o,n.as))}}return u}after(e,t={}){let n=e===void 0?Date.now():this.coerce(e);for(let s of this.iterate(n))if(!(s===n&&!t.inclusive))return this.out(s,t.as);return null}before(e,t={}){let n=e===void 0?Date.now():this.coerce(e),s=Math.max(this.startMs(),n-nn),i=7*864e5;for(;;){let a=Math.max(s,n-i),u;for(let o of this.iterate(a)){if(o>n||o===n&&!t.inclusive)break;u=o}if(u!==void 0)return this.out(u,t.as);if(a<=s)return null;i*=8}}take(e,t={}){Ze("take(n)",e);let n=t.from===void 0?Date.now():this.coerce(t.from),s=[];if(e===0)return s;for(let i of this.iterate(n))if(i!==n&&(s.push(this.out(i,t.as)),s.length>=e))break;return s}includes(e){let t=this.coerce(e);for(let n of this.iterate(t))return n===t;return!1}instances(e,t,n){let s=V(n.duration);if(!s.isValid()||s.valueOf()<0)throw new RangeError("neram: instances() needs a duration of zero or more");let i=this.coerce(e),a=this.coerce(t),u=Math.abs(s.asMilliseconds())+2*864e5,o=[];for(let l of this.iterate(i-u)){if(l>=a)break;let d=D(l,{zone:this.tz}).add(s);d.valueOf()<=i&&l<i||o.push({start:this.out(l,n.as),end:this.out(d.valueOf(),n.as)})}return o}*[Symbol.iterator](){for(let e of this.iterate(this.startMs()))yield D(e,{zone:this.tz})}};function Ze(r,e){if(e!==void 0&&(!Number.isInteger(e)||e<0))throw new RangeError(`neram: ${r} must be a whole number of zero or more, got ${String(e)}`)}var xe=["yearly","monthly","weekly","daily","hourly","minutely","secondly"],Nt=new Set(["freq","dtstart","tz","allDay","interval","count","until","wkst","byMonth","byWeekNo","byYearDay","byMonthDay","byDay","byHour","byMinute","bySecond","bySetPos","rdate","exdate"]),W=0,oe=1,Ee=2,qe=3,be=4,St=5,Ot=6,ne=["SU","MO","TU","WE","TH","FR","SA"],pe=864e5,It=[0,0,0,0,36e5,6e4,1e3],J=(r,e,t,n,s=!0)=>{if(r===void 0)return;let i=(Array.isArray(r)?r:[r]).map(Number);for(let a of i)if(!Number.isInteger(a)||Math.abs(a)>n||t>=0&&a<t||!s&&a===0||t<0&&a<t)throw new RangeError(`neram: ${e} value ${a} is out of range`);return i.length?[...new Set(i)].sort((a,u)=>a-u):void 0};function rn(r){if(typeof r=="object"){let n=ne.indexOf(r.day.toUpperCase());if(n<0)throw new RangeError(`neram: invalid weekday "${r.day}"`);return{w:n,n:r.n??0}}let e=/^([+-]?\d{1,2})?(MO|TU|WE|TH|FR|SA|SU)$/i.exec(r.trim());if(!e)throw new RangeError(`neram: invalid BYDAY "${r}"`);let t=e[1]?Number(e[1]):0;if(Math.abs(t)>53)throw new RangeError(`neram: invalid BYDAY "${r}"`);return{w:ne.indexOf(e[2].toUpperCase()),n:t}}var A=(r,e,t)=>Math.floor(M(r,e,t)/pe),Ue=Me;function Tt(r){let e=se(r);return{y:e.y,M:e.M,D:e.D,h:e.h,m:e.m,s:e.s,ms:0}}var sn=r=>typeof r=="string"&&/^\d{4}-?\d{2}-?\d{2}$/.test(r.trim()),ge=class r extends te{tz;allDay;#e;#n;#r;#o;#c;#u;#t;constructor(e){super();for(let p of Object.keys(e))if(!Nt.has(p)){let w=[...Nt].find(g=>g.toLowerCase()===p.toLowerCase());throw new RangeError(`neram: unknown rrule option "${p}"${w?`; did you mean "${w}"?`:""}`)}let t=xe.indexOf(String(e.freq).toLowerCase());if(t<0)throw new RangeError(`neram: invalid freq "${e.freq}"`);if(e.dtstart===void 0||e.dtstart===null)throw new RangeError("neram: dtstart is required");let n=e.tz?D(e.dtstart,{zone:e.tz}):D(e.dtstart);if(!n.isValid())throw new RangeError(`neram: invalid dtstart ${JSON.stringify(e.dtstart)}`);this.tz=Y(e.tz??n.timezone()),this.allDay=e.allDay??!1,n=n.tz(this.tz).millisecond(0),this.allDay&&(n=n.startOf("day"));let[s,i,a,u,o,l]=n.toArray();this.#c={y:s,M:i,D:a,h:u,m:o,s:l,dow:n.day()},this.#r=M(s,i,a,u,o,l),this.#o=n.valueOf();let m=e.interval??1;if(!Number.isInteger(m)||m<1)throw new RangeError("neram: interval must be a positive integer");if(e.count!==void 0&&(!Number.isInteger(e.count)||e.count<1))throw new RangeError("neram: count must be a positive integer");if(e.count!==void 0&&e.until!==void 0&&e.until!==null)throw new RangeError("neram: use count or until, not both (RFC 5545)");let d=1;if(e.wkst&&(d=ne.indexOf(e.wkst.toUpperCase()),d<0))throw new RangeError(`neram: invalid wkst "${e.wkst}"`);let c;if(e.until!==void 0&&e.until!==null){let p=D(e.until,{zone:this.tz});if(!p.isValid())throw new RangeError(`neram: invalid until ${JSON.stringify(e.until)}`);c=(this.allDay||sn(e.until)?p.endOf("day"):p).valueOf()}let f=e.byDay===void 0?void 0:(Array.isArray(e.byDay)?e.byDay:[e.byDay]).map(rn);if(f?.some(p=>p.n!==0)){if(t!==oe&&t!==W)throw new RangeError(`neram: byDay with a number ("1MO", "-1FR") needs freq 'monthly' or 'yearly'`);if(t===W&&e.byWeekNo!==void 0)throw new RangeError("neram: byDay with a number cannot be combined with byWeekNo (RFC 5545)")}this.#e={freq:t,interval:m,count:e.count,untilMs:c,wkst:d,wkstGiven:e.wkst!==void 0,byMonth:J(e.byMonth,"byMonth",1,12),byWeekNo:J(e.byWeekNo,"byWeekNo",-53,53,!1),byYearDay:J(e.byYearDay,"byYearDay",-366,366,!1),byMonthDay:J(e.byMonthDay,"byMonthDay",-31,31,!1),byDay:f?.length?f:void 0,byHour:J(e.byHour,"byHour",0,23),byMinute:J(e.byMinute,"byMinute",0,59),bySecond:J(e.bySecond,"bySecond",0,60),bySetPos:J(e.bySetPos,"bySetPos",-366,366,!1)};let h={...this.#e},y=!h.byWeekNo&&!h.byYearDay&&!h.byMonthDay&&!h.byDay;t===W&&y?(h.byMonth??=[i+1],h.byMonthDay=[a]):t===oe&&y?h.byMonthDay=[a]:t===Ee&&!h.byDay&&!h.byMonthDay&&!h.byYearDay&&(h.byDay=[{w:this.#c.dow,n:0}]),this.allDay?(h.byHour=[0],h.byMinute=[0],h.bySecond=[0]):(t<be&&(h.byHour??=[u]),t<St&&(h.byMinute??=[o]),t<Ot&&(h.bySecond??=[l])),this.#n=h;let b=p=>{let w=D(p,{zone:this.tz});if(!w.isValid())throw new RangeError(`neram: invalid date ${JSON.stringify(p)}`);return(this.allDay?w.startOf("day"):w.millisecond(0)).valueOf()};this.#u=new Set((e.exdate??[]).map(b)),this.#t=[...new Set((e.rdate??[]).map(b))].sort((p,w)=>p-w)}isInfinite(){return this.#e.count===void 0&&this.#e.untilMs===void 0}startMs(){return Math.min(this.#o,this.#t[0]??1/0)}get freq(){return xe[this.#e.freq]}get dtstart(){return D(this.#o,{zone:this.tz})}#a(e,t){let n=this.#n,{y:s,M:i,D:a,dow:u}=Ue(e);if(n.byMonth&&!n.byMonth.includes(i+1))return!1;if(n.byWeekNo){let o=v(s,i,a,n.wkst,4);if(n.freq===W&&o.year!==t)return!1;let l=Se(o.year,n.wkst,4);if(!n.byWeekNo.some(m=>(m>0?m:l+m+1)===o.week))return!1}if(n.byYearDay){let o=L(s,i,a),l=Ne(s);if(!n.byYearDay.some(m=>(m>0?m:l+m+1)===o))return!1}if(n.byMonthDay){let o=S(s,i);if(!n.byMonthDay.some(l=>(l>0?l:o+l+1)===a))return!1}if(n.byDay){let o=n.freq===oe||n.freq===W&&!!n.byMonth,l=n.freq===W&&!n.byMonth,m=!1;for(let d of n.byDay){if(d.w!==u)continue;if(d.n===0||!o&&!l){m=!0;break}let c,f;if(o)c=Math.floor((a-1)/7)+1,f=-(Math.floor((S(s,i)-a)/7)+1);else{let h=L(s,i,a);c=Math.floor((h-1)/7)+1,f=-(Math.floor((Ne(s)-h)/7)+1)}if(d.n===c||d.n===f){m=!0;break}}if(!m)return!1}return!0}#s(){let e=this.#n,t=[];for(let n of e.byHour)for(let s of e.byMinute)for(let i of e.bySecond)t.push(n*36e5+s*6e4+i*1e3);return t.sort((n,s)=>n-s)}#i(e,t){let n=this.#n,s=this.#c,i=n.interval,a,u,o;if(n.freq>=be){let m=It[n.freq],d=this.#r-(this.#r%m+m)%m,c=d+e*i*m,f=Math.floor(c/pe);o=Ue(f).y;let h=p=>Math.ceil((p-d)/(i*m));if(!this.#a(f,o))return{year:o,walls:[],skipTo:h((f+1)*pe)};let y=Tt(c);if(n.byHour&&!n.byHour.includes(y.h))return n.freq===be?{year:o,walls:[]}:{year:o,walls:[],skipTo:h((Math.floor(c/36e5)+1)*36e5)};if(n.freq===Ot&&n.byMinute&&!n.byMinute.includes(y.m))return{year:o,walls:[],skipTo:h((Math.floor(c/6e4)+1)*6e4)};let b=[];if(n.freq===be)for(let p of n.byMinute??[s.m])for(let w of n.bySecond??[s.s])b.push(c+p*6e4+w*1e3);else if(n.freq===St){if(n.byMinute&&!n.byMinute.includes(y.m))return{year:o,walls:[]};for(let p of n.bySecond??[s.s])b.push(c+p*1e3)}else(!n.bySecond||n.bySecond.includes(y.s))&&b.push(c);return{year:o,walls:b.sort((p,w)=>p-w)}}switch(n.freq){case W:o=s.y+e*i,a=n.byWeekNo?A(o-1,11,25):A(o,0,1),u=n.byWeekNo?A(o+1,0,7):A(o,11,31);break;case oe:{let m=s.y*12+s.M+e*i;o=Math.floor(m/12);let d=m-o*12;a=A(o,d,1),u=A(o,d,S(o,d));break}case Ee:{a=A(s.y,s.M,s.D)-(s.dow-n.wkst+7)%7+e*i*7,u=a+6,o=Ue(a).y;break}default:a=u=A(s.y,s.M,s.D)+e*i,o=Ue(a).y}let l=[];for(let m=a;m<=u;m++)if(this.#a(m,o))for(let d of t)l.push(m*pe+d);return{year:o,walls:l}}#d(e){let t=this.#n,n=this.#c,s=D(e-2*pe,{zone:this.tz}),[i,a,u,o,l,m]=s.toArray(),d=t.interval,c;switch(t.freq){case W:c=Math.floor((i-n.y)/d)-1;break;case oe:c=Math.floor((i*12+a-(n.y*12+n.M))/d)-1;break;case Ee:{let f=A(n.y,n.M,n.D)-(n.dow-t.wkst+7)%7;c=Math.floor((A(i,a,u)-f)/(7*d))-1;break}case qe:c=Math.floor((A(i,a,u)-A(n.y,n.M,n.D))/d)-1;break;default:{let f=It[t.freq],h=this.#r-(this.#r%f+f)%f;c=Math.floor((M(i,a,u,o,l,m)-h)/(d*f))-1}}return Math.max(0,c)}*#f(e){let t=this.#n,n=t.freq<be?this.#s():[],s=t.count===void 0&&Number.isFinite(e)&&e>this.#o,i=s?this.#d(e):0,a=s?D(e,{zone:this.tz}).year():this.#c.y,u=0,o=-1/0;for(;;i++){let l=this.#i(i,n);if(l.year>9999||l.year>a+400)return;if(l.skipTo!==void 0){i=l.skipTo-1;continue}let m=l.walls;if(t.bySetPos&&m.length){let d=m.length;m=[...new Set(t.bySetPos.map(c=>m[c>0?c-1:d+c]).filter(c=>c!==void 0))].sort((c,f)=>c-f)}for(let d of m){if(d<this.#r)continue;let c=$(Tt(d),this.tz);if(t.untilMs!==void 0&&c>t.untilMs)return;if(!(c<=o)&&(o=c,a=l.year,u++,c>=e&&(yield c),t.count!==void 0&&u>=t.count))return}}}*iterate(e){let t=this.#t.filter(a=>a>=e),n=0,s=-1/0,i=a=>a===s||this.#u.has(a)?!1:(s=a,!0);for(let a of this.#f(e)){for(;n<t.length&&t[n]<=a;)i(t[n])&&(yield t[n]),n++;i(a)&&(yield a)}for(;n<t.length;n++)i(t[n])&&(yield t[n])}#l(e){let t=D(e,{zone:this.tz});return this.allDay?t.format("YYYYMMDD"):this.tz==="UTC"?t.format("YYYYMMDD[T]HHmmss[Z]"):t.format("YYYYMMDD[T]HHmmss")}#h(e,t){let n=this.allDay?";VALUE=DATE":this.tz==="UTC"?"":`;TZID=${this.tz}`;return`${e}${n}:${t.map(s=>this.#l(s)).join(",")}`}rruleString(){let e=this.#e,t=[`FREQ=${xe[e.freq].toUpperCase()}`];if(e.interval!==1&&t.push(`INTERVAL=${e.interval}`),e.count!==void 0&&t.push(`COUNT=${e.count}`),e.untilMs!==void 0){let s=D(e.untilMs,{zone:this.allDay?this.tz:"UTC"});t.push(`UNTIL=${this.allDay?s.format("YYYYMMDD"):s.format("YYYYMMDD[T]HHmmss[Z]")}`)}e.wkstGiven&&t.push(`WKST=${ne[e.wkst]}`);let n=(s,i)=>i&&t.push(`${s}=${i.join(",")}`);return n("BYMONTH",e.byMonth),n("BYWEEKNO",e.byWeekNo),n("BYYEARDAY",e.byYearDay),n("BYMONTHDAY",e.byMonthDay),n("BYDAY",e.byDay?.map(s=>`${s.n||""}${ne[s.w]}`)),n("BYHOUR",e.byHour),n("BYMINUTE",e.byMinute),n("BYSECOND",e.bySecond),n("BYSETPOS",e.bySetPos),t.join(";")}toString(){let e=[this.#h("DTSTART",[this.#o]),`RRULE:${this.rruleString()}`];return this.#t.length&&e.push(this.#h("RDATE",this.#t)),this.#u.size&&e.push(this.#h("EXDATE",[...this.#u].sort((t,n)=>t-n))),e.join(`
3
+ `)}toJSON(){let e=this.#e,t=s=>{let i=D(s,{zone:this.tz});return this.allDay?i.format("YYYY-MM-DD"):i.toZonedISOString()},n={freq:xe[e.freq],dtstart:t(this.#o),tz:this.tz};this.allDay&&(n.allDay=!0),e.interval!==1&&(n.interval=e.interval),e.count!==void 0&&(n.count=e.count),e.untilMs!==void 0&&(n.until=t(e.untilMs)),e.wkstGiven&&(n.wkst=ne[e.wkst]);for(let s of["byMonth","byWeekNo","byYearDay","byMonthDay","byHour","byMinute","bySecond","bySetPos"])e[s]&&(n[s]=[...e[s]]);return e.byDay&&(n.byDay=e.byDay.map(s=>`${s.n||""}${ne[s.w]}`)),this.#t.length&&(n.rdate=this.#t.map(t)),this.#u.size&&(n.exdate=[...this.#u].sort((s,i)=>s-i).map(t)),n}with(e){let t=this.toJSON();return"until"in e&&delete t.count,"count"in e&&delete t.until,new r({...t,...e})}toText(e="en"){let t=this.#e,n=I(e),s=c=>ce(c,"en"),i=["year","month","week","day","hour","minute","second"][t.freq],a={1:"first",2:"second",3:"third",4:"fourth",5:"fifth",[-1]:"last",[-2]:"second-to-last"},u=t.interval===1?`every ${i}`:`every ${t.interval} ${i}s`;t.freq===qe&&t.byDay&&t.byDay.every(c=>!c.n)&&t.byDay.map(f=>f.w).sort().join()==="1,2,3,4,5"&&t.interval===1&&(u="every weekday"),t.byMonth&&(u+=` in ${s(t.byMonth.map(c=>n.months[c-1]))}`);let o=!t.byWeekNo&&!t.byYearDay&&!t.byMonthDay&&!t.byDay,l=this.#c;o&&t.freq===W&&!t.byMonth?u+=` on ${n.months[l.M]} ${l.D}`:o&&t.freq===W?u+=` on the ${x(l.D,"en")}`:o&&t.freq===oe?u+=` on the ${x(l.D,"en")}`:t.freq===Ee&&!t.byDay&&!t.byMonthDay&&!t.byYearDay&&(u+=` on ${n.weekdays[l.dow]}`),t.byWeekNo&&(u+=` in week ${s(t.byWeekNo.map(String))}`),t.byYearDay&&(u+=` on day ${s(t.byYearDay.map(String))} of the year`),t.byMonthDay&&(u+=` on the ${s(t.byMonthDay.map(c=>c===-1?"last day":c<0?`${x(-c,"en")}-to-last day`:x(c,"en")))}`);let m=t.byDay&&t.byDay.every(c=>!c.n),d=m&&t.byDay.map(c=>c.w).sort().join()==="1,2,3,4,5";if(t.bySetPos&&m&&!t.byMonthDay){let c=d?"weekday":ce(t.byDay.map(f=>n.weekdays[f.w]),"en","disjunction");u+=` on the ${s(t.bySetPos.map(f=>a[f]??x(f,"en")))} ${c}`}else{if(t.byDay&&u!=="every weekday"){let c=t.byDay.map(f=>(f.n?`${a[f.n]??x(Math.abs(f.n),"en")+(f.n<0?" last":"")} `:"")+n.weekdays[f.w]);u+=`${t.byMonthDay?" if it is":" on"} ${t.byDay.some(f=>f.n)?"the ":""}${s(c)}`}t.bySetPos&&(u+=` (occurrence ${s(t.bySetPos.map(String))} of each ${i})`)}if(!this.allDay&&t.freq<=qe){let c=this.#n,f=this.#s().slice(0,6).map(h=>{let y=M(2e3,0,1)+h;return D(y,{zone:"UTC",locale:e}).format(c.bySecond.some(b=>b)?"LTS":"LT")});u+=` at ${s(f)}`}return t.untilMs!==void 0&&(u+=` until ${D(t.untilMs,{zone:this.tz,locale:e}).format("LL")}`),t.count!==void 0&&(u+=`, ${t.count} time${t.count===1?"":"s"}`),u}},an=/^(\d{4})(\d{2})(\d{2})(?:T(\d{2})(\d{2})(\d{2})(Z)?)?$/i;function Be(r,e){let t=an.exec(r.trim());if(!t)throw new RangeError(`neram: invalid iCalendar date "${r}"`);let n=!t[4],s=n?`${t[1]}-${t[2]}-${t[3]}`:`${t[1]}-${t[2]}-${t[3]}T${t[4]}:${t[5]}:${t[6]}`,i=!!t[7];return{value:i?D(`${s}Z`,{zone:e??"UTC"}):D(s,{zone:e??"UTC"}),dateOnly:n,utc:i}}function Rt(r,e={}){let t=r.replace(/\r?\n[ \t]/g,"").split(/\r?\n|\\n/).map(m=>m.trim()).filter(Boolean),n={},s=e.tz,i=!1,a=[],u=[],o=[];for(let m of t){let d=m.indexOf(":"),c=d<0||/^FREQ=/i.test(m),f=c?"RRULE":m.slice(0,d),h=c?m:m.slice(d+1),[y,...b]=f.split(";"),p={};for(let g of b){let k=g.indexOf("=");p[g.slice(0,k).toUpperCase()]=g.slice(k+1).replace(/^"|"$/g,"")}let w=y.toUpperCase();if(w==="RRULE"){if(i)throw new RangeError("neram: only one RRULE per rule is supported; use several rules for more");i=!0;for(let g of h.split(";").filter(Boolean)){let k=g.indexOf("=");if(k<1)throw new RangeError(`neram: invalid RRULE part "${g}"`);let T=g.slice(0,k).toUpperCase(),R=g.slice(k+1),q=()=>R.split(",").map(Number);switch(T){case"FREQ":n.freq=R.toLowerCase();break;case"INTERVAL":n.interval=Number(R);break;case"COUNT":n.count=Number(R);break;case"UNTIL":n.until=R;break;case"WKST":n.wkst=R.toUpperCase();break;case"BYMONTH":n.byMonth=q();break;case"BYWEEKNO":n.byWeekNo=q();break;case"BYYEARDAY":n.byYearDay=q();break;case"BYMONTHDAY":n.byMonthDay=q();break;case"BYDAY":n.byDay=R.split(",");break;case"BYHOUR":n.byHour=q();break;case"BYMINUTE":n.byMinute=q();break;case"BYSECOND":n.bySecond=q();break;case"BYSETPOS":n.bySetPos=q();break;default:if(T.startsWith("X-"))break;throw new RangeError(`neram: unsupported RRULE part "${T}"`)}}}else(w==="DTSTART"||w==="RDATE"||w==="EXDATE")&&o.push({name:w,params:p,values:h.split(",")})}for(let m of o){if(m.name!=="DTSTART")continue;m.params.TZID&&(s??=m.params.TZID);let d=Be(m.values[0],s);d.utc&&!s&&(s="UTC"),n.dtstart=d.value,(d.dateOnly||m.params.VALUE?.toUpperCase()==="DATE")&&(n.allDay=!0)}for(let m of o){if(m.name==="DTSTART")continue;let d=m.params.TZID??s;for(let c of m.values)(m.name==="RDATE"?a:u).push(Be(c,d).value)}if(typeof n.until=="string"){let m=Be(n.until,s);n.until=m.dateOnly?m.value.format("YYYY-MM-DD"):m.value}if(!i&&!e.freq)throw new RangeError("neram: no RRULE found");if(i&&n.freq===void 0&&!e.freq)throw new RangeError("neram: RRULE has no FREQ");let l={...n,...e};if(s&&(l.tz=s),(a.length||e.rdate)&&(l.rdate=[...a,...e.rdate??[]]),(u.length||e.exdate)&&(l.exdate=[...u,...e.exdate??[]]),l.dtstart===void 0)throw new RangeError("neram: no DTSTART; pass { dtstart } as the second argument");return l}function on(r,e={}){return typeof r=="string"?new ge(Rt(r,e)):new ge({...r,...e})}var un={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * 0","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"},At=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"],vt=["SUN","MON","TUE","WED","THU","FRI","SAT"];function ue(r,e,t,n,s){let i=new Set,a=r.startsWith("*")||r==="?",u=o=>{let l=o.toUpperCase(),m=s?s.indexOf(l):-1,d=m>=0?m+(s===At?1:0):Number(o);if(!/^\d+$/.test(o)&&m<0)throw new RangeError(`neram: invalid cron ${e} "${o}"`);return d};for(let o of r.split(",")){if(!o)throw new RangeError(`neram: empty item in cron ${e}`);let[l,m]=o.split("/"),d=m===void 0?1:Number(m);if(!Number.isInteger(d)||d<1)throw new RangeError(`neram: invalid cron step "${o}"`);let c,f;if(l==="*"||l==="?")c=t,f=n;else if(l.includes("-")){let[y,b]=l.split("-");c=u(y),f=u(b)}else c=u(l),f=m===void 0?c:n;let h=y=>{if(y<t||y>n)throw new RangeError(`neram: cron ${e} value ${y} is out of range ${t}-${n}`)};if(h(c),h(f),c<=f)for(let y=c;y<=f;y+=d)i.add(y);else{let y=n-t+1,b=(f-c+y)%y;for(let p=0;p<=b;p+=d)i.add(t+(c-t+p)%y)}}return{values:i,any:a}}var $e=class extends te{tz;allDay=!1;expression;hasSeconds;#e;#n;#r;#o;#c;#u;#t={last:[],nearestWeekday:[],lastWeekday:!1};#a={nth:[],last:[]};#s;#i;constructor(e,t={}){super(),this.expression=e.trim(),this.tz=Y(t.tz??D().timezone());let s=(un[this.expression.toLowerCase()]??this.expression).split(/\s+/);if(s.length!==5&&s.length!==6)throw new RangeError(`neram: cron needs 5 or 6 fields, got ${s.length} in "${e}"`);this.hasSeconds=s.length===6;let[i,a,u,o,l,m]=this.hasSeconds?s:["0",...s];this.#e=ue(i,"second",0,59),this.#n=ue(a,"minute",0,59),this.#r=ue(u,"hour",0,23),this.#c=ue(l,"month",1,12,At);let d=[];for(let f of o.split(",")){let h=f.toUpperCase(),y;if(h==="L")this.#t.last.push(0);else if(y=/^L-(\d+)$/.exec(h)){if(Number(y[1])>30)throw new RangeError(`neram: invalid cron day of month "${f}" (L-n needs n from 0 to 30)`);this.#t.last.push(Number(y[1]))}else if(h==="LW")this.#t.lastWeekday=!0;else if(y=/^(\d+)W$/.exec(h)){let b=Number(y[1]);if(b<1||b>31)throw new RangeError(`neram: invalid cron day of month "${f}" (nW needs n from 1 to 31)`);this.#t.nearestWeekday.push(b)}else d.push(f)}this.#o=d.length?ue(d.join(","),"day of month",1,31):{values:new Set,any:!1},d.length!==o.split(",").length&&(this.#o.any=!1);let c=[];for(let f of m.split(",")){let h=f.toUpperCase(),y=p=>{let w=vt.indexOf(p),g=w>=0?w:Number(p);if(!Number.isInteger(g)||g<0||g>7)throw new RangeError(`neram: invalid cron weekday "${p}"`);return g%7},b;(b=/^(\w+)#([1-5])$/.exec(h))?this.#a.nth.push([y(b[1]),Number(b[2])]):(b=/^(\w+)L$/.exec(h))?this.#a.last.push(y(b[1])):c.push(f)}this.#u=c.length?ue(c.join(","),"day of week",0,7,vt):{values:new Set,any:!1},c.length!==m.split(",").length&&(this.#u.any=!1),this.#u.values.delete(7)&&this.#u.values.add(0),this.#s=t.start===void 0?void 0:this.coerce(t.start),this.#i=t.end===void 0?void 0:this.coerce(t.end)}isInfinite(){return this.#i===void 0}startMs(){return this.#s??Date.now()}#d(e,t,n){let s=(Math.floor(M(e,t,n)/864e5)%7+11)%7,i=S(e,t),a=()=>{if(this.#o.values.has(n)||this.#t.last.some(l=>n===i-l))return!0;let o=l=>{let m=Math.min(l,i),d=new Date(M(e,t,m)).getUTCDay();return d===6?m=m===1?3:m-1:d===0&&(m=m===i?m-2:m+1),m};if(this.#t.nearestWeekday.some(l=>n===o(l)))return!0;if(this.#t.lastWeekday){let l=i;for(;[0,6].includes(new Date(M(e,t,l)).getUTCDay());)l--;if(n===l)return!0}return!1},u=()=>this.#u.values.has(s)||this.#a.nth.some(([o,l])=>o===s&&Math.floor((n-1)/7)+1===l)||this.#a.last.some(o=>o===s&&n+7>i);return this.#o.any||this.#u.any?a()&&u():a()||u()}#f(e){let t=new Date(e).getUTCFullYear()+400;for(;;){let{y:n,M:s,D:i,h:a,m:u,s:o}=se(e);if(n>t||n>9999)return null;if(!this.#c.values.has(s+1)){e=M(n,s+1,1);continue}if(!this.#d(n,s,i)){e=M(n,s,i+1);continue}if(!this.#r.values.has(a)){e=M(n,s,i,a+1);continue}if(!this.#n.values.has(u)){e=M(n,s,i,a,u+1);continue}if(!this.#e.values.has(o)){e=M(n,s,i,a,u,o+1);continue}return e}}*iterate(e){let t=e;this.#s!==void 0&&(t=Math.max(t,this.#s)),Number.isFinite(t)||(t=Date.now());let n=this.hasSeconds?1e3:6e4,s=D(t,{zone:this.tz}),[i,a,u,o,l,m,d]=s.toArray(),c=M(i,a,u,o,l,this.hasSeconds?m:0);(d>0||!this.hasSeconds&&(m>0||d>0))&&(c+=n);let f=-1/0;for(;;){let h=this.#f(c);if(h===null)return;let y=$(se(h),this.tz);if(c=h+n,!(y<t||y<=f)){if(this.#i!==void 0&&y>this.#i)return;f=y,yield y}}}toString(){return this.expression}toJSON(){return{expression:this.expression,tz:this.tz}}};function mn(r,e={}){return new $e(r,e)}export{$e as Cron,ge as RRule,te as Schedule,mn as cron,Rt as parseRRule,on as rrule};
@@ -0,0 +1,17 @@
1
+ export interface RelativeTimeOptions {
2
+ /** 'long' → "in 3 hours", 'short' → "in 3 hr.", 'narrow' → "in 3h" */
3
+ style?: Intl.RelativeTimeFormatStyle;
4
+ /** 'auto' → "yesterday" / "now"; 'always' → "1 day ago" / "in 0 seconds". Default 'auto'. */
5
+ numeric?: Intl.RelativeTimeFormatNumeric;
6
+ /** Override the instance locale. */
7
+ locale?: string;
8
+ /** Leave out the "in" / "ago" — "3 hours". */
9
+ withoutSuffix?: boolean;
10
+ }
11
+ export type RelUnit = 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year';
12
+ /** Day.js-style thresholds: pick the unit a human would say. */
13
+ export declare function pickUnit(ms: number, months?: number): {
14
+ value: number;
15
+ unit: RelUnit;
16
+ };
17
+ export declare function formatRelative(value: number, unit: RelUnit, locale: string, opts?: RelativeTimeOptions): string;
@@ -0,0 +1,26 @@
1
+ import { formatRelativeTime, formatUnit } from './intl.js';
2
+ import { MS_DAY, MS_HOUR, MS_MINUTE, MS_MONTH, MS_SECOND } from './units.js';
3
+ /** Day.js-style thresholds: pick the unit a human would say. */
4
+ export function pickUnit(ms, months) {
5
+ const abs = Math.abs(ms);
6
+ const sign = ms < 0 ? -1 : 1;
7
+ const r = (n) => sign * Math.round(n);
8
+ if (abs < 45 * MS_SECOND)
9
+ return { value: r(abs / MS_SECOND), unit: 'second' };
10
+ if (abs < 45 * MS_MINUTE)
11
+ return { value: r(abs / MS_MINUTE), unit: 'minute' };
12
+ if (abs < 22 * MS_HOUR)
13
+ return { value: r(abs / MS_HOUR), unit: 'hour' };
14
+ if (abs < 26 * MS_DAY)
15
+ return { value: r(abs / MS_DAY), unit: 'day' };
16
+ const m = months !== undefined ? Math.abs(months) : abs / MS_MONTH;
17
+ if (m < 10.5)
18
+ return { value: r(Math.max(1, m)), unit: 'month' };
19
+ return { value: r(Math.max(1, m / 12)), unit: 'year' };
20
+ }
21
+ export function formatRelative(value, unit, locale, opts = {}) {
22
+ const style = opts.style ?? 'long';
23
+ if (opts.withoutSuffix)
24
+ return formatUnit(Math.abs(value), unit, locale, style);
25
+ return formatRelativeTime(value, unit, locale, style, opts.numeric ?? 'auto');
26
+ }
@@ -0,0 +1,13 @@
1
+ export type Unit = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'date' | 'week' | 'isoWeek' | 'month' | 'quarter' | 'year';
2
+ /** Every spelling accepted wherever a unit is expected (Day.js compatible). */
3
+ export type UnitInput = Unit | `${Exclude<Unit, 'isoWeek'>}s` | 'ms' | 's' | 'm' | 'h' | 'd' | 'D' | 'w' | 'W' | 'M' | 'Q' | 'y';
4
+ export declare function normalizeUnit(u: string | undefined): Unit | undefined;
5
+ export declare const MS_SECOND = 1000;
6
+ export declare const MS_MINUTE: number;
7
+ export declare const MS_HOUR: number;
8
+ export declare const MS_DAY: number;
9
+ export declare const MS_WEEK: number;
10
+ /** Average Gregorian year (365.2425 days) and month — used only for approximate conversions. */
11
+ export declare const MS_YEAR: number;
12
+ export declare const MS_MONTH: number;
13
+ export declare const FIXED_MS: Partial<Record<Unit, number>>;
package/dist/units.js ADDED
@@ -0,0 +1,44 @@
1
+ const SHORT = {
2
+ ms: 'millisecond',
3
+ s: 'second',
4
+ m: 'minute',
5
+ h: 'hour',
6
+ d: 'day',
7
+ D: 'date',
8
+ w: 'week',
9
+ W: 'isoWeek',
10
+ M: 'month',
11
+ Q: 'quarter',
12
+ y: 'year',
13
+ };
14
+ const LONG = new Set([
15
+ 'millisecond', 'second', 'minute', 'hour', 'day', 'date', 'week', 'isoWeek', 'month', 'quarter', 'year',
16
+ ]);
17
+ export function normalizeUnit(u) {
18
+ if (u == null)
19
+ return undefined;
20
+ if (SHORT[u])
21
+ return SHORT[u];
22
+ if (LONG.has(u))
23
+ return u;
24
+ const lower = u.toLowerCase().replace(/s$/, '');
25
+ if (lower === 'isoweek')
26
+ return 'isoWeek';
27
+ if (LONG.has(lower))
28
+ return lower;
29
+ throw new RangeError(`neram: unknown unit "${u}"`);
30
+ }
31
+ export const MS_SECOND = 1000;
32
+ export const MS_MINUTE = 60 * MS_SECOND;
33
+ export const MS_HOUR = 60 * MS_MINUTE;
34
+ export const MS_DAY = 24 * MS_HOUR;
35
+ export const MS_WEEK = 7 * MS_DAY;
36
+ /** Average Gregorian year (365.2425 days) and month — used only for approximate conversions. */
37
+ export const MS_YEAR = 365.2425 * MS_DAY;
38
+ export const MS_MONTH = MS_YEAR / 12;
39
+ export const FIXED_MS = {
40
+ millisecond: 1,
41
+ second: MS_SECOND,
42
+ minute: MS_MINUTE,
43
+ hour: MS_HOUR,
44
+ };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Week rules per region, from Unicode CLDR 48 (supplemental weekData).
3
+ *
4
+ * Shipped as data rather than read from Intl.Locale#getWeekInfo, because that API is missing in
5
+ * some runtimes. With the table, a server and a browser always agree on the first day of the
6
+ * week, the weekend, and week numbers. Regions not listed use the CLDR defaults:
7
+ * week starts Monday, weekend Saturday–Sunday, first week needs 1 day.
8
+ */
9
+ export interface WeekRules {
10
+ /** 0 = Sunday … 6 = Saturday */
11
+ firstDay: number;
12
+ minimalDays: number;
13
+ /** Weekend weekday numbers (0-6) */
14
+ weekend: number[];
15
+ }
16
+ /** The region a locale implies: "en" → "US", "ta" → "IN", "de-AT" → "AT". */
17
+ export declare function regionOf(locale: string): string | undefined;
18
+ /**
19
+ * Week rules for a locale, identical on every runtime.
20
+ * Honors the Unicode "-u-fw-" extension, e.g. "en-US-u-fw-mon".
21
+ */
22
+ export declare function weekRules(locale: string): WeekRules;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Week rules per region, from Unicode CLDR 48 (supplemental weekData).
3
+ *
4
+ * Shipped as data rather than read from Intl.Locale#getWeekInfo, because that API is missing in
5
+ * some runtimes. With the table, a server and a browser always agree on the first day of the
6
+ * week, the weekend, and week numbers. Regions not listed use the CLDR defaults:
7
+ * week starts Monday, weekend Saturday–Sunday, first week needs 1 day.
8
+ */
9
+ // prettier-ignore
10
+ const FIRST_DAY = {
11
+ ...regions(5, 'MV'),
12
+ ...regions(6, 'AF BH DJ DZ EG IQ IR JO KW LY OM QA SD SY'),
13
+ ...regions(0, 'AG AS BD BR BS BT BW BZ CA CO DM DO ET GT GU HK HN ID IL IN IS JM JP KE KH KR LA MH MM MO MT MX MZ NI NP PA PE PH PK PR PT PY SA SG SV TH TT TW UM US VE VI WS YE ZA ZW'),
14
+ };
15
+ // prettier-ignore
16
+ const WEEKEND = {
17
+ ...regions([5], 'IR'),
18
+ ...regions([0], 'IN UG'),
19
+ ...regions([4, 5], 'AF'),
20
+ ...regions([5, 6], 'BH DZ EG IL IQ JO KW LY OM QA SA SD SY YE'),
21
+ };
22
+ /** Regions where week 1 is the first week with at least 4 days (ISO-style). */
23
+ // prettier-ignore
24
+ const MIN_DAYS_4 = new Set('AD AN AT AX BE BG CH CZ DE DK EE ES FI FJ FO FR GB GF GG GI GP GR HU IE IM IS IT JE LI LT LU MC MQ NL NO PL RE RU SE SJ SK SM VA'.split(' '));
25
+ const DAY_CODES = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
26
+ function regions(value, list) {
27
+ return Object.fromEntries(list.split(' ').map((r) => [r, value]));
28
+ }
29
+ /** The region a locale implies: "en" → "US", "ta" → "IN", "de-AT" → "AT". */
30
+ export function regionOf(locale) {
31
+ try {
32
+ const l = new Intl.Locale(locale);
33
+ return l.region ?? (typeof l.maximize === 'function' ? l.maximize().region : undefined);
34
+ }
35
+ catch {
36
+ const m = /^[a-z]{2,3}[-_]([A-Z]{2})\b/i.exec(locale);
37
+ return m?.[1].toUpperCase();
38
+ }
39
+ }
40
+ /**
41
+ * Week rules for a locale, identical on every runtime.
42
+ * Honors the Unicode "-u-fw-" extension, e.g. "en-US-u-fw-mon".
43
+ */
44
+ export function weekRules(locale) {
45
+ const region = regionOf(locale) ?? '001';
46
+ let firstDay = FIRST_DAY[region] ?? 1;
47
+ const fw = /-u(?:-[a-z0-9]{2,8})*?-fw-([a-z]{3})\b/i.exec(locale);
48
+ if (fw) {
49
+ const i = DAY_CODES.indexOf(fw[1].toLowerCase());
50
+ if (i >= 0)
51
+ firstDay = i;
52
+ }
53
+ return {
54
+ firstDay,
55
+ minimalDays: MIN_DAYS_4.has(region) ? 4 : 1,
56
+ weekend: WEEKEND[region] ?? [6, 0],
57
+ };
58
+ }