temporal-fmt 0.8.2 → 0.8.4
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/LICENSE +1 -0
- package/README.md +168 -1
- package/dist/formatDistance.d.cts +33 -0
- package/dist/formatDistance.d.ts +33 -0
- package/dist/formatDuration.d.cts +27 -0
- package/dist/formatDuration.d.ts +27 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/isoWeek.d.cts +7 -0
- package/dist/isoWeek.d.ts +7 -0
- package/dist/localeVocab.d.cts +27 -0
- package/dist/localeVocab.d.ts +27 -0
- package/dist/parseRelative.d.cts +25 -0
- package/dist/parseRelative.d.ts +25 -0
- package/dist/temporalProvider.d.cts +1 -0
- package/dist/temporalProvider.d.ts +1 -0
- package/dist/tokens.d.cts +7 -0
- package/dist/tokens.d.ts +7 -0
- package/package.json +8 -5
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
export { format } from './format.cjs';
|
|
2
2
|
export { parse } from './parse.cjs';
|
|
3
3
|
export { setTemporal } from './temporalProvider.cjs';
|
|
4
|
+
export { formatDuration } from './formatDuration.cjs';
|
|
5
|
+
export { formatDistance } from './formatDistance.cjs';
|
|
6
|
+
export { parseRelative } from './parseRelative.cjs';
|
|
7
|
+
export { registerLocaleVocab } from './localeVocab.cjs';
|
|
8
|
+
export type { LocaleVocab } from './localeVocab.cjs';
|
|
4
9
|
export type { TemporalLike, FormatOptions } from './tokens.cjs';
|
|
10
|
+
export type { DurationFormatOptions } from './formatDuration.cjs';
|
|
11
|
+
export type { FormatDistanceOptions } from './formatDistance.cjs';
|
|
12
|
+
export type { ParseRelativeOptions } from './parseRelative.cjs';
|
|
5
13
|
export type { TemporalNamespace } from './temporalProvider.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
export { format } from './format.js';
|
|
2
2
|
export { parse } from './parse.js';
|
|
3
3
|
export { setTemporal } from './temporalProvider.js';
|
|
4
|
+
export { formatDuration } from './formatDuration.js';
|
|
5
|
+
export { formatDistance } from './formatDistance.js';
|
|
6
|
+
export { parseRelative } from './parseRelative.js';
|
|
7
|
+
export { registerLocaleVocab } from './localeVocab.js';
|
|
8
|
+
export type { LocaleVocab } from './localeVocab.js';
|
|
4
9
|
export type { TemporalLike, FormatOptions } from './tokens.js';
|
|
10
|
+
export type { DurationFormatOptions } from './formatDuration.js';
|
|
11
|
+
export type { FormatDistanceOptions } from './formatDistance.js';
|
|
12
|
+
export type { ParseRelativeOptions } from './parseRelative.js';
|
|
5
13
|
export type { TemporalNamespace } from './temporalProvider.js';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var G,W=[];function J(e){W.push(e)}function ae(e){G=e;for(let n of W)n()}function ie(){return G??globalThis.Temporal}function A(){let e=ie();if(!e)throw new Error("temporal-fmt: parse() needs a Temporal implementation to construct its result. Call setTemporal(Temporal) once at startup, or assign one to globalThis.Temporal (native on Node 26+, or a polyfill like temporal-polyfill).");return e}function F(e){try{return new Intl.Locale(e.replace(/_/g,"-")).toString().toLowerCase()}catch{return e}}var P=new Map,se=500;function v(e,n,t){let r=e.formatToParts(n),o=r.findIndex(p=>p.type===t);if(o===-1)throw new Error(`temporal-fmt: locale produced no "${t}" part while building match vocabulary.`);let a=r[o].value,i=r[o-1],s=r[o+1];return i?.type==="literal"&&!/\s/.test(i.value)&&(a=i.value+a),s?.type==="literal"&&!/\s/.test(s.value)&&(a=a+s.value),a}function _(e,n,t){let r=new Map;for(let o=0;o<e.length;o++){let a=r.get(e[o]);if(a!==void 0)throw new Error(`temporal-fmt: locale "${t}" renders ${n} index ${a} and ${o} identically ("${e[o]}"). parse() can't reliably tell these apart for this locale/token, so this combination isn't supported.`);r.set(e[o],o)}}function M(e){let n=F(e),t=P.get(n);if(t)return t;let r=new Intl.DateTimeFormat(e,{month:"long",timeZone:"UTC"}),o=new Intl.DateTimeFormat(e,{month:"short",timeZone:"UTC"}),a=[],i=[];for(let u=0;u<12;u++){let k=new Date(Date.UTC(2020,u,1));a.push(v(r,k,"month")),i.push(v(o,k,"month"))}_(a,"MMMM month",e),_(i,"MMM month",e);let s=new Intl.DateTimeFormat(e,{weekday:"long",timeZone:"UTC"}),p=new Intl.DateTimeFormat(e,{weekday:"short",timeZone:"UTC"}),c=[],m=[];for(let u=0;u<7;u++){let k=new Date(Date.UTC(2024,0,1+u));c.push(v(s,k,"weekday")),m.push(v(p,k,"weekday"))}_(c,"EEEE weekday",e),_(m,"EEE weekday",e);let d=new Intl.DateTimeFormat(e,{hour:"numeric",hour12:!0,timeZone:"UTC"}),f=v(d,new Date(Date.UTC(2020,0,1,1)),"dayPeriod"),w=v(d,new Date(Date.UTC(2020,0,1,13)),"dayPeriod"),h=[...new Set([f,w])],g={monthLong:a,monthShort:i,weekdayLong:c,weekdayShort:m,dayPeriod:h};if(P.size>=se){let u=P.keys().next().value;u!==void 0&&P.delete(u)}return P.set(n,g),g}function T(e,n){let t=e<0,r=String(Math.abs(e)).padStart(n,"0");return t?"-"+r:r}var Z="en-US",N=new Map,me=500;function q(e,n){let t=JSON.stringify([F(e),n]),r=N.get(t);if(r)return r;if(N.size>=me){let o=N.keys().next().value;o!==void 0&&N.delete(o)}return r=new Intl.DateTimeFormat(e,n),N.set(t,r),r}var S;J(()=>{S=void 0});function de(){if(S===void 0){S=!1;try{let e=A();new Intl.DateTimeFormat("en-US",{day:"numeric"}).formatToParts(e.PlainDate.from({year:1970,month:1,day:1})),S=!0}catch{}}return S}function R(e,n,t,r){let o=e?.calendarId,a={...t,calendar:o&&o!=="iso8601"?o:"gregory"};if(!de())return e.toLocaleString(n,a);let{toInstant:i,timeZoneId:s}=e,p=typeof i=="function"&&typeof s=="string",c=p?e.toInstant():e,m={...a,...p?{timeZone:s}:{}},f=q(n,m).formatToParts(c),w=f.findIndex(k=>k.type===r);if(w===-1)throw new Error(`temporal-fmt: locale "${n}" produced no "${r}" part for this token. This usually means the Temporal object is missing the field the token needs.`);let h=f[w].value,g=f[w-1],u=f[w+1];return g?.type==="literal"&&!/\s/.test(g.value)&&(h=g.value+h),u?.type==="literal"&&!/\s/.test(u.value)&&(h=h+u.value),h}function ue(e,n){let t=new Date(Date.UTC(1970,0,1,e)),o=q(n,{hour:"numeric",hour12:!0,timeZone:"UTC"}).formatToParts(t).find(a=>a.type==="dayPeriod");if(!o)throw new Error(`temporal-fmt: locale "${n}" produced no "dayPeriod" part for token "a".`);return o.value}var H=[["yyyy",e=>T(e.year,4),"year"],["yy",e=>{if(e.year<0)throw new Error(`temporal-fmt: token "yy" doesn't support negative years (got ${e.year}), since truncating to 2 digits would make it indistinguishable from a positive year. Use "yyyy" instead.`);return T(e.year%100,2)},"year"],["MMMM",(e,n)=>R(e,n,{month:"long"},"month"),"month"],["MMM",(e,n)=>R(e,n,{month:"short"},"month"),"month"],["MM",e=>T(e.month,2),"month"],["M",e=>String(e.month),"month"],["dd",e=>T(e.day,2),"day"],["d",e=>String(e.day),"day"],["EEEE",(e,n)=>R(e,n,{weekday:"long"},"weekday"),"dayOfWeek"],["EEE",(e,n)=>R(e,n,{weekday:"short"},"weekday"),"dayOfWeek"],["HH",e=>T(e.hour,2),"hour"],["H",e=>String(e.hour),"hour"],["hh",e=>T(e.hour%12||12,2),"hour"],["h",e=>String(e.hour%12||12),"hour"],["mm",e=>T(e.minute,2),"minute"],["m",e=>String(e.minute),"minute"],["ss",e=>T(e.second,2),"second"],["s",e=>String(e.second),"second"],["SSS",e=>T(e.millisecond,3),"millisecond"],["a",(e,n)=>ue(e.hour,n),"hour"],["zzz",e=>e.timeZoneId,"timeZoneId"]];var ce=H.map(([e])=>e).sort((e,n)=>n.length-e.length);function U(e){let n=[],t=0;for(;t<e.length;){let r=e[t];if(r==="'"){if(e[t+1]==="'"){j(n,"'"),t+=2;continue}let a=t+1,i="",s=!1;for(;a<e.length;){if(e[a]==="'"){if(e[a+1]==="'"){i+="'",a+=2;continue}s=!0,a+=1;break}i+=e[a],a+=1}if(!s)throw new Error(`temporal-fmt: unterminated quote in format string "${e}"`);j(n,i),t=a;continue}let o=ce.find(a=>e.startsWith(a,t));if(o){n.push({kind:"token",value:o}),t+=o.length;continue}j(n,r),t+=1}return n}function j(e,n){let t=e[e.length-1];t&&t.kind==="literal"?t.value+=n:e.push({kind:"literal",value:n})}var le=new Map(H.map(([e,n,t])=>[e,{fn:n,field:t}]));function pe(e,n,t={}){if(n.length>1e3)throw new Error(`temporal-fmt: format string exceeds maximum length of ${1e3} characters (got ${n.length}).`);let r=t.locale??Z,o=U(n),a="";for(let i of o){if(i.kind==="literal"){a+=i.value;continue}let s=le.get(i.value);if(!s)throw new Error(`temporal-fmt: unknown token "${i.value}"`);if(e[s.field]===void 0)throw new Error(`temporal-fmt: token "${i.value}" requires "${s.field}", which this Temporal object doesn't have. (e.g. PlainDate has no time fields, PlainTime has no date fields)`);a+=s.fn(e,r)}return a}function ge(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function $(e){return`(?:${e.map(ge).join("|")})`}var fe="(?:UTC|[+-]\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d{1,9})?)?|[A-Za-z_]+(?:[+-]\\d{1,2})?(?:\\/[A-Za-z0-9_+-]+)*)";function he(){return fe}var z;function ye(){return z||(z=new Set(Intl.supportedValuesOf("timeZone")),z.add("UTC")),z}var we=/^[+-]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?$/;function B(e){return we.test(e)||ye().has(e)}var ke={yy:"\\d{2}",MM:"(?:0[1-9]|1[0-2])",M:"(?:1[0-2]|[1-9])",dd:"(?:0[1-9]|[12]\\d|3[01])",d:"(?:[12]\\d|3[01]|[1-9])",HH:"(?:[01]\\d|2[0-3])",H:"(?:1\\d|2[0-3]|[0-9])",hh:"(?:0[1-9]|1[0-2])",h:"(?:1[0-2]|[1-9])",mm:"(?:[0-5]\\d)",m:"(?:[1-5]\\d|[0-9])",ss:"(?:[0-5]\\d)",s:"(?:[1-5]\\d|[0-9])",SSS:"\\d{3}"},Te="-?\\d{4}",Ee="-?\\d{4,}",be=new Set(["yyyy","yy","MM","M","dd","d","HH","H","hh","h","mm","m","ss","s","SSS"]);function Q(e,n,t){if(e==="yyyy")return t!==void 0&&be.has(t)?Te:Ee;let r=ke[e];if(r)return r;let o=M(n);switch(e){case"MMMM":return $(o.monthLong);case"MMM":return $(o.monthShort);case"EEEE":return $(o.weekdayLong);case"EEE":return $(o.weekdayShort);case"a":return $(o.dayPeriod);case"zzz":return he();default:throw new Error(`temporal-fmt: unknown token "${e}"`)}}var ee=new Set(["M","d","H","h","m","s"]),xe={M:[{digits:1,min:1,max:9},{digits:2,min:10,max:12}],d:[{digits:1,min:1,max:9},{digits:2,min:10,max:31}],H:[{digits:1,min:0,max:9},{digits:2,min:10,max:23}],h:[{digits:1,min:1,max:9},{digits:2,min:10,max:12}],m:[{digits:1,min:0,max:9},{digits:2,min:10,max:59}],s:[{digits:1,min:0,max:9},{digits:2,min:10,max:59}]};function te(e,n){let t=new Map;function r(o,a){let i=`${o}:${a}`,s=t.get(i);if(s)return s;if(o===n.length){let d=a===e.length?[[]]:[];return t.set(i,d),d}let p=n[o],c=xe[p];if(!c)throw new Error(`temporal-fmt: internal error \u2014 "${p}" is not an unpadded numeric token`);let m=[];for(let{digits:d,min:f,max:w}of c){if(a+d>e.length)continue;let h=e.slice(a,a+d);if(d===2&&h[0]==="0")continue;let g=Number(h);if(!(g<f||g>w)){for(let u of r(o+1,a+d))if(m.push([g,...u]),m.length===2)break;if(m.length===2)break}}return t.set(i,m),m}return r(0,0)}function ve(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ne(e,n){let t=[],r=[],o="",a=0,i={groupNames:[],tokens:[]},s=()=>{i.tokens.length>=2&&r.push(i),i={groupNames:[],tokens:[]}};for(let[p,c]of e.entries()){if(c.kind==="literal"){o+=ve(c.value),s();continue}let m=`g${a++}`;t.push({name:m,token:c.value});let d=e[p+1],f=d?.kind==="token"?d.value:void 0;o+=`(?<${m}>${Q(c.value,n,f)})`,ee.has(c.value)?(i.groupNames.push(m),i.tokens.push(c.value)):s()}return s(),{regex:new RegExp(`^(?:${o})$`,"u"),groups:t,ambiguousRuns:r}}var C=new Map,De=500;function Pe(e,n){let t=JSON.stringify([F(n),e]),r=C.get(t);if(r)return r;if(C.size>=De){let o=C.keys().next().value;o!==void 0&&C.delete(o)}return r=ne(U(e),n),C.set(t,r),r}var D=new Map,Fe=500;function Ne(e){let n=new Intl.Locale(e).toString().toLowerCase();if(D.has(n))return D.get(n);if(D.size>=Fe){let i=D.keys().next().value;i!==void 0&&D.delete(i)}let t,r=n.split("-"),o=r.indexOf("u"),a=o===-1?-1:r.indexOf("ca",o+1);if(a!==-1&&a+1<r.length){let i=new Intl.DateTimeFormat(n).resolvedOptions().calendar;t=i==="gregory"?void 0:i}return D.set(n,t),t}function l(e,n,t){e[n]=t}function Se(e,n,t,r,o){let a=M(r);switch(n){case"yyyy":l(e,"year",Number(t));break;case"yy":l(e,"twoDigitYear",Number(t));break;case"MM":case"M":l(e,"month",Number(t));break;case"MMMM":l(e,"month",a.monthLong.indexOf(t)+1);break;case"MMM":l(e,"month",a.monthShort.indexOf(t)+1);break;case"dd":case"d":l(e,"day",Number(t));break;case"EEEE":l(e,"weekdayRaw",t),l(e,"weekdayExpected",a.weekdayLong.indexOf(t)+1);break;case"EEE":l(e,"weekdayRaw",t),l(e,"weekdayExpected",a.weekdayShort.indexOf(t)+1);break;case"HH":case"H":l(e,"hour",Number(t));break;case"hh":case"h":l(e,"hour12",Number(t));break;case"mm":case"m":l(e,"minute",Number(t));break;case"ss":case"s":l(e,"second",Number(t));break;case"SSS":l(e,"millisecond",Number(t));break;case"a":{let i=a.dayPeriod.indexOf(t);if(i<0)throw new Error(`temporal-fmt: unknown day period "${t}" for locale "${r}".`);l(e,"dayPeriodRaw",t),l(e,"isPM",i===1);break}case"zzz":l(e,"timeZoneId",t);break}}function $e(e){if(e.year!==void 0&&e.twoDigitYear!==void 0)throw new Error('temporal-fmt: format string mixes "yyyy" and "yy" year representations.');if(e.year!==void 0)return e.year;if(e.twoDigitYear!==void 0)return e.twoDigitYear<=68?2e3+e.twoDigitYear:1900+e.twoDigitYear}function Ce(e,n,t){if(e.hour!==void 0&&e.hour12!==void 0)throw new Error(`temporal-fmt: format string "${n}" mixes a 24-hour token ("HH"/"H") with a 12-hour token ("hh"/"h").`);if(e.hour!==void 0){if(e.dayPeriodRaw!==void 0){let r=M(t),o=e.hour<12?r.dayPeriod[0]:r.dayPeriod[1];if(e.dayPeriodRaw!==o)throw new Error(`temporal-fmt: format string "${n}" contains a day period that contradicts the 24-hour value.`)}return e.hour}if(e.hour12!==void 0){if(e.isPM===void 0)throw new Error(`temporal-fmt: format string "${n}" uses a 12-hour token ("hh"/"h") without an "a" token, so parse() can't tell AM from PM.`);return e.hour12%12+(e.isPM?12:0)}}function Ie(e,n,t={}){if(e.length>1e3)throw new Error(`temporal-fmt: format string exceeds maximum length of ${1e3} characters (got ${e.length}).`);if(n.length>1e5)throw new Error(`temporal-fmt: input exceeds maximum length of ${1e5} characters (got ${n.length}).`);let r=t.locale??Z,o=Ne(r),a=Pe(e,r),i=a.regex.exec(n);if(!i)throw new Error("temporal-fmt: no valid pattern matches the format string and input shape");if(a.groups.length===0)throw new Error(`temporal-fmt: format string "${e}" has no tokens \u2014 nothing to parse into a value.`);for(let{name:y,token:E}of a.groups)if(E==="zzz"&&!B(i.groups[y]))throw new Error("temporal-fmt: no valid pattern matches the format string and input shape");for(let y of a.ambiguousRuns){let E=y.groupNames.map(oe=>i.groups[oe]).join(""),O=te(E,y.tokens);if(O.length>1)throw new Error(`temporal-fmt: "${E}" in format string "${e}" is ambiguous \u2014 ${O.length} different ways to read tokens "${y.tokens.join("")}" (with no separator between them) are all individually valid (e.g. ${JSON.stringify(O[0])} vs ${JSON.stringify(O[1])}). parse() won't guess; add a separator between these tokens, or use their padded form (e.g. "MM" instead of "M") so each one has a fixed width.`)}let s={};for(let{name:y,token:E}of a.groups)Se(s,E,i.groups[y],r,e);let p=$e(s),c=Ce(s,e,r),{month:m,day:d,minute:f,second:w,millisecond:h,timeZoneId:g,weekdayExpected:u,weekdayRaw:k}=s,re=p!==void 0||m!==void 0||d!==void 0,b=p!==void 0&&m!==void 0&&d!==void 0;if(re&&!b)throw new Error(`temporal-fmt: format string "${e}" has an incomplete date \u2014 year, month, and day tokens must all be present together.`);let K=c!==void 0||f!==void 0||w!==void 0||h!==void 0;if(g!==void 0&&!(b&&K))throw new Error(`temporal-fmt: format string "${e}" has a "zzz" token but needs a full date and time to build a ZonedDateTime.`);if(u!==void 0&&!b)throw new Error(`temporal-fmt: format string "${e}" has a weekday token ("EEEE"/"EEE") but needs a full date to validate it against.`);if(!b&&!K)throw new Error(`temporal-fmt: format string "${e}" has no date or time tokens to parse.`);let I=A(),Y={hour:c??0,minute:f??0,second:w??0,millisecond:h??0},V=o?{calendar:o}:{},L={overflow:"reject"},x;try{g!==void 0?x=I.ZonedDateTime.from({year:p,month:m,day:d,...Y,...V,timeZone:g},L):b&&K?x=I.PlainDateTime.from({year:p,month:m,day:d,...Y,...V},L):b?x=I.PlainDate.from({year:p,month:m,day:d,...V},L):x=I.PlainTime.from(Y,L)}catch(y){throw new Error(`temporal-fmt: "${n}" doesn't describe a valid date/time for format "${e}": ${y.message}`)}if(u!==void 0){let y=x.dayOfWeek;if(y!==u){let E=M(r);throw new Error(`temporal-fmt: "${k}" doesn't match the actual weekday (${E.weekdayLong[y-1]}) for the parsed date.`)}}return x}export{pe as format,Ie as parse,ae as setTemporal};
|
|
1
|
+
var ye,we=[];function be(e){we.push(e)}function Le(e){ye=e;for(let t of we)t()}function Oe(){return ye??globalThis.Temporal}function $(){let e=Oe();if(!e)throw new Error("temporal-fmt: parse() needs a Temporal implementation to construct its result. Call setTemporal(Temporal) once at startup, or assign one to globalThis.Temporal (native on Node 26+, or a polyfill like temporal-polyfill).");return e}var ie=new Map;function Ne(e,t){let n=[{key:"monthLong",length:12,label:"long month names"},{key:"monthShort",length:12,label:"short month names"},{key:"weekdayLong",length:7,label:"long weekday names"},{key:"weekdayShort",length:7,label:"short weekday names"},{key:"dayPeriod",length:2,label:"day period markers (AM/PM-equivalent)"}];for(let{key:r,length:o,label:a}of n){let i=e[r];if(i===void 0)throw new Error(`temporal-fmt: registerLocaleVocab for locale "${t}" is missing required field "${r}" (${a}).`);if(!Array.isArray(i))throw new Error(`temporal-fmt: registerLocaleVocab for locale "${t}": "${r}" must be an array, got ${typeof i}.`);if(i.length!==o)throw new Error(`temporal-fmt: registerLocaleVocab for locale "${t}": "${r}" must have exactly ${o} entries (got ${i.length}) \u2014 ${a}.`);i.forEach((s,m)=>{if(typeof s!="string"||s.length===0)throw new Error(`temporal-fmt: registerLocaleVocab for locale "${t}": "${r}[${m}]" must be a non-empty string, got ${String(s)}.`)})}if(M(e.monthLong,"MMMM month",t),M(e.monthShort,"MMM month",t),M(e.weekdayLong,"EEEE weekday",t),M(e.weekdayShort,"EEE weekday",t),e.dayPeriod[0]===e.dayPeriod[1])throw new Error(`temporal-fmt: registerLocaleVocab for locale "${t}": dayPeriod entries must differ (both are "${e.dayPeriod[0]}"); otherwise parse() can't tell AM from PM.`)}function Re(e,t){if(typeof e!="string"||e.length===0)throw new Error(`temporal-fmt: registerLocaleVocab requires a non-empty locale string, got ${String(e)}.`);Ne(t,e);let n=P(e);ie.set(n,{monthLong:[...t.monthLong],monthShort:[...t.monthShort],weekdayLong:[...t.weekdayLong],weekdayShort:[...t.weekdayShort],dayPeriod:[...t.dayPeriod]}),L.delete(n)}function P(e){try{return new Intl.Locale(e.replace(/_/g,"-")).toString().toLowerCase()}catch{return e}}var L=new Map,Ae=500;function F(e,t,n){let r=e.formatToParts(t),o=r.findIndex(m=>m.type===n);if(o===-1)throw new Error(`temporal-fmt: locale produced no "${n}" part while building match vocabulary.`);let a=r[o].value,i=r[o-1],s=r[o+1];return i?.type==="literal"&&!/\s/.test(i.value)&&(a=i.value+a),s?.type==="literal"&&!/\s/.test(s.value)&&(a=a+s.value),a}function M(e,t,n){let r=new Map;for(let o=0;o<e.length;o++){let a=r.get(e[o]);if(a!==void 0)throw new Error(`temporal-fmt: locale "${n}" renders ${t} index ${a} and ${o} identically ("${e[o]}"). parse() can't reliably tell these apart for this locale/token, so this combination isn't supported.`);r.set(e[o],o)}}function O(e){let t=P(e);return ie.get(t)}function N(e){let t=P(e),n=ie.get(t);if(n)return n;let r=L.get(t);if(r)return r;let o=new Intl.DateTimeFormat(e,{month:"long",timeZone:"UTC"}),a=new Intl.DateTimeFormat(e,{month:"short",timeZone:"UTC"}),i=[],s=[];for(let y=0;y<12;y++){let T=new Date(Date.UTC(2020,y,1));i.push(F(o,T,"month")),s.push(F(a,T,"month"))}M(i,"MMMM month",e),M(s,"MMM month",e);let m=new Intl.DateTimeFormat(e,{weekday:"long",timeZone:"UTC"}),c=new Intl.DateTimeFormat(e,{weekday:"short",timeZone:"UTC"}),u=[],l=[];for(let y=0;y<7;y++){let T=new Date(Date.UTC(2024,0,1+y));u.push(F(m,T,"weekday")),l.push(F(c,T,"weekday"))}M(u,"EEEE weekday",e),M(l,"EEE weekday",e);let d=new Intl.DateTimeFormat(e,{hour:"numeric",hour12:!0,timeZone:"UTC"}),f=F(d,new Date(Date.UTC(2020,0,1,1)),"dayPeriod"),p=F(d,new Date(Date.UTC(2020,0,1,13)),"dayPeriod"),w=[...new Set([f,p])],b={monthLong:i,monthShort:s,weekdayLong:u,weekdayShort:l,dayPeriod:w};if(L.size>=Ae){let y=L.keys().next().value;y!==void 0&&L.delete(y)}return L.set(t,b),b}var Ce=[0,31,59,90,120,151,181,212,243,273,304,334];function I(e){return e%4===0&&e%100!==0||e%400===0}function C(e){return I(e)?366:365}function me(e,t,n){let r=Ce[t-1]+n;return t>2&&I(e)&&(r+=1),r}var se=2e3;function Ie(e){let t=0;if(e>=se)for(let r=se;r<e;r++)t+=C(r);else for(let r=e;r<se;r++)t-=C(r);return((5+t)%7+7)%7+1}function ue(e,t,n,r){let a=me(e,t,n)+(4-r),i,s;a<1?(i=e-1,s=a+C(i)):a>C(e)?(i=e+1,s=a-C(e)):(i=e,s=a);let c=1+(4-Ie(i)+7)%7,u=1+Math.floor((s-c)/7);return{isoYear:i,week:u}}function k(e,t){let n=e<0,r=String(Math.abs(e)).padStart(t,"0");return n?"-"+r:r}var R="en-US",_=new Map,_e=500;function ke(e,t){let n=JSON.stringify([P(e),t]),r=_.get(n);if(r)return r;if(_.size>=_e){let o=_.keys().next().value;o!==void 0&&_.delete(o)}return r=new Intl.DateTimeFormat(e,t),_.set(n,r),r}var U;be(()=>{U=void 0});function Ue(){if(U===void 0){U=!1;try{let e=$();new Intl.DateTimeFormat("en-US",{day:"numeric"}).formatToParts(e.PlainDate.from({year:1970,month:1,day:1})),U=!0}catch{}}return U}function Ve(e,t,n,r){let o=e?.calendarId,a={...n,calendar:o&&o!=="iso8601"?o:"gregory"};if(!Ue())return e.toLocaleString(t,a);let{toInstant:i,timeZoneId:s}=e,m=typeof i=="function"&&typeof s=="string",c=m?e.toInstant():e,u={...a,...m?{timeZone:s}:{}},d=ke(t,u).formatToParts(c),f=d.findIndex(y=>y.type===r);if(f===-1)throw new Error(`temporal-fmt: locale "${t}" produced no "${r}" part for this token. This usually means the Temporal object is missing the field the token needs.`);let p=d[f].value,w=d[f-1],b=d[f+1];return w?.type==="literal"&&!/\s/.test(w.value)&&(p=w.value+p),b?.type==="literal"&&!/\s/.test(b.value)&&(p=p+b.value),p}function Ye(e,t){let n=O(t);if(n)return e<12?n.dayPeriod[0]:n.dayPeriod[1];let r=new Date(Date.UTC(1970,0,1,e)),a=ke(t,{hour:"numeric",hour12:!0,timeZone:"UTC"}).formatToParts(r).find(i=>i.type==="dayPeriod");if(!a)throw new Error(`temporal-fmt: locale "${t}" produced no "dayPeriod" part for token "a".`);return a.value}function K(e,t,n,r,o,a){return o&&a!==void 0&&a>=0&&a<o.length?o[a]:Ve(e,t,n,r)}var W=[["yyyy",e=>k(e.year,4),"year"],["yy",e=>{if(e.year<0)throw new Error(`temporal-fmt: token "yy" doesn't support negative years (got ${e.year}), since truncating to 2 digits would make it indistinguishable from a positive year. Use "yyyy" instead.`);return k(e.year%100,2)},"year"],["MMMM",(e,t)=>{let n=O(t);return K(e,t,{month:"long"},"month",n?.monthLong,e.month-1)},"month"],["MMM",(e,t)=>{let n=O(t);return K(e,t,{month:"short"},"month",n?.monthShort,e.month-1)},"month"],["MM",e=>k(e.month,2),"month"],["M",e=>String(e.month),"month"],["dd",e=>k(e.day,2),"day"],["d",e=>String(e.day),"day"],["EEEE",(e,t)=>{let n=O(t);return K(e,t,{weekday:"long"},"weekday",n?.weekdayLong,e.dayOfWeek-1)},"dayOfWeek"],["EEE",(e,t)=>{let n=O(t);return K(e,t,{weekday:"short"},"weekday",n?.weekdayShort,e.dayOfWeek-1)},"dayOfWeek"],["HH",e=>k(e.hour,2),"hour"],["H",e=>String(e.hour),"hour"],["hh",e=>k(e.hour%12||12,2),"hour"],["h",e=>String(e.hour%12||12),"hour"],["mm",e=>k(e.minute,2),"minute"],["m",e=>String(e.minute),"minute"],["ss",e=>k(e.second,2),"second"],["s",e=>String(e.second),"second"],["SSS",e=>k(e.millisecond,3),"millisecond"],["a",(e,t)=>Ye(e.hour,t),"hour"],["zzz",e=>e.timeZoneId,"timeZoneId"],["do",e=>{let t=e.day,n=t%10,r=t%100;return r>=11&&r<=13?t+"th":n===1?t+"st":n===2?t+"nd":n===3?t+"rd":t+"th"},"day"],["Q",e=>String(Math.ceil(e.month/3)),"month"],["QQQ",e=>"Q"+Math.ceil(e.month/3),"month"],["ww",e=>{let{week:t}=ue(e.year,e.month,e.day,e.dayOfWeek);return k(t,2)},"dayOfWeek"],["RRRR",e=>{let{isoYear:t}=ue(e.year,e.month,e.day,e.dayOfWeek);return k(t,4)},"dayOfWeek"]];var Ze=W.map(([e])=>e).sort((e,t)=>t.length-e.length);function Q(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r==="'"){if(e[n+1]==="'"){de(t,"'"),n+=2;continue}let a=n+1,i="",s=!1;for(;a<e.length;){if(e[a]==="'"){if(e[a+1]==="'"){i+="'",a+=2;continue}s=!0,a+=1;break}i+=e[a],a+=1}if(!s)throw new Error(`temporal-fmt: unterminated quote in format string "${e}"`);de(t,i),n=a;continue}let o=Ze.find(a=>e.startsWith(a,n));if(o){t.push({kind:"token",value:o}),n+=o.length;continue}de(t,r),n+=1}return t}function de(e,t){let n=e[e.length-1];n&&n.kind==="literal"?n.value+=t:e.push({kind:"literal",value:t})}var He=new Map(W.map(([e,t,n])=>[e,{fn:t,field:n}]));function je(e,t,n={}){if(t.length>1e3)throw new Error(`temporal-fmt: format string exceeds maximum length of ${1e3} characters (got ${t.length}).`);let r=n.locale??R,o=Q(t),a="";for(let i of o){if(i.kind==="literal"){a+=i.value;continue}let s=He.get(i.value);if(!s)throw new Error(`temporal-fmt: unknown token "${i.value}"`);if(e[s.field]===void 0)throw new Error(`temporal-fmt: token "${i.value}" requires "${s.field}", which this Temporal object doesn't have. (e.g. PlainDate has no time fields, PlainTime has no date fields)`);a+=s.fn(e,r)}return a}function ze(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Y(e,t=!1){let n=e.map(ze);return t?`(?:${n.map(Ke).join("|")})`:`(?:${n.join("|")})`}function Ke(e){return e.replace(/[a-zA-Z]/g,t=>`[${t.toLowerCase()}${t.toUpperCase()}]`)}var We="(?:UTC|[+-]\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d{1,9})?)?|[A-Za-z_]+(?:[+-]\\d{1,2})?(?:\\/[A-Za-z0-9_+-]+)*)";function Qe(){return We}var q;function qe(){return q||(q=new Set(Intl.supportedValuesOf("timeZone")),q.add("UTC")),q}var Ge=/^[+-]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?$/;function Ee(e){return Ge.test(e)||qe().has(e)}var Xe={yy:"\\d{2}",MM:"(?:0[1-9]|1[0-2])",M:"(?:1[0-2]|[1-9])",dd:"(?:0[1-9]|[12]\\d|3[01])",d:"(?:[12]\\d|3[01]|[1-9])",HH:"(?:[01]\\d|2[0-3])",H:"(?:1\\d|2[0-3]|[0-9])",hh:"(?:0[1-9]|1[0-2])",h:"(?:1[0-2]|[1-9])",mm:"(?:[0-5]\\d)",m:"(?:[1-5]\\d|[0-9])",ss:"(?:[0-5]\\d)",s:"(?:[1-5]\\d|[0-9])",SSS:"\\d{3}",Q:"[1-4]"},Be="Q[1-4]",Je=new Set(["do","ww","RRRR"]),et="-?\\d{4}",tt="-?\\d{4,}",nt=new Set(["yyyy","yy","MM","M","dd","d","HH","H","hh","h","mm","m","ss","s","SSS"]);function Te(e,t,n){if(e==="yyyy")return n!==void 0&&nt.has(n)?et:tt;let r=Xe[e];if(r)return r;if(e==="QQQ")return Be;if(Je.has(e))throw new Error(`temporal-fmt: token "${e}" is format-only \u2014 it can't be parsed back into a value. Use a different token in the parse format string (e.g. "d" for "do", "MM" for "ww").`);let o=N(t);switch(e){case"MMMM":return Y(o.monthLong);case"MMM":return Y(o.monthShort);case"EEEE":return Y(o.weekdayLong);case"EEE":return Y(o.weekdayShort);case"a":return Y(o.dayPeriod,!0);case"zzz":return Qe();default:throw new Error(`temporal-fmt: unknown token "${e}"`)}}var De=new Set(["M","d","H","h","m","s"]),rt={M:[{digits:1,min:1,max:9},{digits:2,min:10,max:12}],d:[{digits:1,min:1,max:9},{digits:2,min:10,max:31}],H:[{digits:1,min:0,max:9},{digits:2,min:10,max:23}],h:[{digits:1,min:1,max:9},{digits:2,min:10,max:12}],m:[{digits:1,min:0,max:9},{digits:2,min:10,max:59}],s:[{digits:1,min:0,max:9},{digits:2,min:10,max:59}]};function xe(e,t){let n=new Map;function r(o,a){let i=`${o}:${a}`,s=n.get(i);if(s)return s;if(o===t.length){let l=a===e.length?[[]]:[];return n.set(i,l),l}let m=t[o],c=rt[m];if(!c)throw new Error(`temporal-fmt: internal error \u2014 "${m}" is not an unpadded numeric token`);let u=[];for(let{digits:l,min:d,max:f}of c){if(a+l>e.length)continue;let p=e.slice(a,a+l);if(l===2&&p[0]==="0")continue;let w=Number(p);if(!(w<d||w>f)){for(let b of r(o+1,a+l))if(u.push([w,...b]),u.length===2)break;if(u.length===2)break}}return n.set(i,u),u}return r(0,0)}function ot(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Me(e,t){let n=[],r=[],o="",a=0,i={groupNames:[],tokens:[]},s=()=>{i.tokens.length>=2&&r.push(i),i={groupNames:[],tokens:[]}};for(let[m,c]of e.entries()){if(c.kind==="literal"){o+=ot(c.value),s();continue}let u=`g${a++}`;n.push({name:u,token:c.value});let l=e[m+1],d=l?.kind==="token"?l.value:void 0;o+=`(?<${u}>${Te(c.value,t,d)})`,De.has(c.value)?(i.groupNames.push(u),i.tokens.push(c.value)):s()}return s(),{regex:new RegExp(`^(?:${o})$`,"u"),groups:n,ambiguousRuns:r}}var Z=new Map,it=500;function st(e,t){let n=JSON.stringify([P(t),e]),r=Z.get(n);if(r)return r;if(Z.size>=it){let o=Z.keys().next().value;o!==void 0&&Z.delete(o)}return r=Me(Q(e),t),Z.set(n,r),r}var A=new Map,mt=500;function ut(e){let t=new Intl.Locale(e).toString().toLowerCase();if(A.has(t))return A.get(t);if(A.size>=mt){let i=A.keys().next().value;i!==void 0&&A.delete(i)}let n,r=t.split("-"),o=r.indexOf("u"),a=o===-1?-1:r.indexOf("ca",o+1);if(a!==-1&&a+1<r.length){let i=new Intl.DateTimeFormat(t).resolvedOptions().calendar;n=i==="gregory"?void 0:i}return A.set(t,n),n}function g(e,t,n){e[t]=n}function dt(e,t,n,r,o){let a=N(r);switch(t){case"yyyy":g(e,"year",Number(n));break;case"yy":g(e,"twoDigitYear",Number(n));break;case"MM":case"M":g(e,"month",Number(n));break;case"MMMM":g(e,"month",a.monthLong.indexOf(n)+1);break;case"MMM":g(e,"month",a.monthShort.indexOf(n)+1);break;case"dd":case"d":g(e,"day",Number(n));break;case"EEEE":g(e,"weekdayRaw",n),g(e,"weekdayExpected",a.weekdayLong.indexOf(n)+1);break;case"EEE":g(e,"weekdayRaw",n),g(e,"weekdayExpected",a.weekdayShort.indexOf(n)+1);break;case"HH":case"H":g(e,"hour",Number(n));break;case"hh":case"h":g(e,"hour12",Number(n));break;case"mm":case"m":g(e,"minute",Number(n));break;case"ss":case"s":g(e,"second",Number(n));break;case"SSS":g(e,"millisecond",Number(n));break;case"a":{let i=a.dayPeriod.findIndex(s=>s.toLowerCase()===n.toLowerCase());if(i<0)throw new Error(`temporal-fmt: unknown day period "${n}" for locale "${r}".`);g(e,"dayPeriodRaw",n),g(e,"isPM",i===1);break}case"zzz":g(e,"timeZoneId",n);break;case"Q":g(e,"quarter",Number(n));break;case"QQQ":g(e,"quarter",Number(n.slice(1)));break}}function lt(e,t){let n=t.indexOf("d");if(n!==-1){let r=e.filter(o=>o[n]<=12);if(r.length>0)return r[0]}return e[0]}function ct(e){if(e.year!==void 0&&e.twoDigitYear!==void 0)throw new Error('temporal-fmt: format string mixes "yyyy" and "yy" year representations.');if(e.year!==void 0)return e.year;if(e.twoDigitYear!==void 0)return e.twoDigitYear<=68?2e3+e.twoDigitYear:1900+e.twoDigitYear}function ft(e,t,n){if(e.hour!==void 0&&e.hour12!==void 0)throw new Error(`temporal-fmt: format string "${t}" mixes a 24-hour token ("HH"/"H") with a 12-hour token ("hh"/"h").`);if(e.hour!==void 0){if(e.dayPeriodRaw!==void 0){let r=N(n),o=e.hour<12?r.dayPeriod[0]:r.dayPeriod[1];if(e.dayPeriodRaw.toLowerCase()!==o?.toLowerCase())throw new Error(`temporal-fmt: format string "${t}" contains a day period that contradicts the 24-hour value.`)}return e.hour}if(e.hour12!==void 0){if(e.isPM===void 0)throw new Error(`temporal-fmt: format string "${t}" uses a 12-hour token ("hh"/"h") without an "a" token, so parse() can't tell AM from PM.`);return e.hour12%12+(e.isPM?12:0)}}function ht(e,t,n={}){if(e.length>1e3)throw new Error(`temporal-fmt: format string exceeds maximum length of ${1e3} characters (got ${e.length}).`);if(t.length>1e5)throw new Error(`temporal-fmt: input exceeds maximum length of ${1e5} characters (got ${t.length}).`);let r=n.locale??R,o=ut(r),a=st(e,r),i=a.regex.exec(t);if(!i)throw new Error("temporal-fmt: no valid pattern matches the format string and input shape");if(a.groups.length===0)throw new Error(`temporal-fmt: format string "${e}" has no tokens \u2014 nothing to parse into a value.`);for(let{name:h,token:E}of a.groups)if(E==="zzz"&&!Ee(i.groups[h]))throw new Error("temporal-fmt: no valid pattern matches the format string and input shape");let s=[];for(let h of a.ambiguousRuns){let E=h.groupNames.map(ae=>i.groups[ae]).join(""),D=xe(E,h.tokens);if(D.length>1){if(!n.lenient)throw new Error(`temporal-fmt: "${E}" in format string "${e}" is ambiguous \u2014 ${D.length} different ways to read tokens "${h.tokens.join("")}" (with no separator between them) are all individually valid (e.g. ${JSON.stringify(D[0])} vs ${JSON.stringify(D[1])}). parse() won't guess; add a separator between these tokens, or use their padded form (e.g. "MM" instead of "M") so each one has a fixed width. Pass { lenient: true } to opt into a documented heuristic that picks one.`);s.push({groupNames:h.groupNames,values:lt(D,h.tokens)})}}let m={},c=new Map;for(let{groupNames:h,values:E}of s)h.forEach((D,ae)=>c.set(D,String(E[ae])));for(let{name:h,token:E}of a.groups){let D=c.get(h)??i.groups[h];dt(m,E,D,r,e)}let u=ct(m),l=ft(m,e,r),{month:d,day:f,minute:p,second:w,millisecond:b,timeZoneId:y,weekdayExpected:T,weekdayRaw:$e,quarter:te}=m,Fe=u!==void 0||d!==void 0||f!==void 0,v=u!==void 0&&d!==void 0&&f!==void 0;if(Fe&&!v)throw new Error(`temporal-fmt: format string "${e}" has an incomplete date \u2014 year, month, and day tokens must all be present together.`);let ne=l!==void 0||p!==void 0||w!==void 0||b!==void 0;if(y!==void 0&&!(v&&ne))throw new Error(`temporal-fmt: format string "${e}" has a "zzz" token but needs a full date and time to build a ZonedDateTime.`);if(T!==void 0&&!v)throw new Error(`temporal-fmt: format string "${e}" has a weekday token ("EEEE"/"EEE") but needs a full date to validate it against.`);if(!v&&!ne)throw new Error(`temporal-fmt: format string "${e}" has no date or time tokens to parse.`);let j=$(),re={hour:l??0,minute:p??0,second:w??0,millisecond:b??0},oe=o?{calendar:o}:{},z={overflow:"reject"},S;try{y!==void 0?S=j.ZonedDateTime.from({year:u,month:d,day:f,...re,...oe,timeZone:y},z):v&&ne?S=j.PlainDateTime.from({year:u,month:d,day:f,...re,...oe},z):v?S=j.PlainDate.from({year:u,month:d,day:f,...oe},z):S=j.PlainTime.from(re,z)}catch(h){throw new Error(`temporal-fmt: "${t}" doesn't describe a valid date/time for format "${e}": ${h.message}`)}if(T!==void 0){let h=S.dayOfWeek;if(h!==T){let E=N(r);throw new Error(`temporal-fmt: "${$e}" doesn't match the actual weekday (${E.weekdayLong[h-1]}) for the parsed date.`)}}if(te!==void 0&&d!==void 0){let h=Math.ceil(d/3);if(te!==h)throw new Error(`temporal-fmt: format string "${e}" contains a quarter token (Q/QQQ) whose value (Q${te}) disagrees with the parsed month's actual quarter \u2014 month ${d} is in Q${h}.`)}return S}var Pe={y:{longSingular:"year",longPlural:"years",shortSingular:"yr",shortPlural:"yrs",field:"years"},o:{longSingular:"month",longPlural:"months",shortSingular:"mo",shortPlural:"mos",field:"months"},w:{longSingular:"week",longPlural:"weeks",shortSingular:"wk",shortPlural:"wks",field:"weeks"},d:{longSingular:"day",longPlural:"days",shortSingular:"d",shortPlural:"d",field:"days"},h:{longSingular:"hour",longPlural:"hours",shortSingular:"h",shortPlural:"h",field:"hours"},m:{longSingular:"minute",longPlural:"minutes",shortSingular:"m",shortPlural:"m",field:"minutes"},s:{longSingular:"second",longPlural:"seconds",shortSingular:"s",shortPlural:"s",field:"seconds"},S:{longSingular:"millisecond",longPlural:"milliseconds",shortSingular:"ms",shortPlural:"ms",field:"milliseconds"}},gt=Object.keys(Pe).flatMap(e=>[e+e+e,e+e,e]).sort((e,t)=>t.length-e.length);function pt(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r==="'"){if(e[n+1]==="'"){le(t,"'"),n+=2;continue}let a=n+1,i="",s=!1;for(;a<e.length;){if(e[a]==="'"){if(e[a+1]==="'"){i+="'",a+=2;continue}s=!0,a+=1;break}i+=e[a],a+=1}if(!s)throw new Error(`temporal-fmt: unterminated quote in duration format string "${e}"`);le(t,i),n=a;continue}let o=gt.find(a=>e.startsWith(a,n));if(o){let a=o[0],i=o.length===1?"numeric":o.length===2?"short":"long";t.push({kind:"token",value:o,unit:a,form:i}),n+=o.length;continue}le(t,r),n+=1}return t}function le(e,t){let n=e[e.length-1];n&&n.kind==="literal"?n.value+=t:e.push({kind:"literal",value:t})}function yt(e,t){let n=e[t];if(n==null)return 0;if(typeof n=="number"&&Number.isFinite(n))return n;let r=Number(n);if(!Number.isFinite(r))throw new Error(`temporal-fmt: duration field "${t}" is not a finite number (got ${String(n)}).`);return r}function wt(e,t,n={}){if(t.length>1e3)throw new Error(`temporal-fmt: duration format string exceeds maximum length of ${1e3} characters (got ${t.length}).`);n.locale;let r=n.showZeroValues===!0,o=pt(t),a="";for(let i of o){if(i.kind==="literal"){a+=i.value;continue}let s=Pe[i.unit];if(!s)throw new Error(`temporal-fmt: unknown duration token "${i.value}"`);let m=yt(e,s.field);m===0&&!r||(i.form==="numeric"?a+=String(m):i.form==="short"?a+=m+(m===1||m===-1?s.shortSingular:s.shortPlural):a+=m+" "+(m===1||m===-1?s.longSingular:s.longPlural))}return a}function ve(e,t){if(e===null||typeof e!="object")throw new Error(`temporal-fmt: formatDistance expects Temporal values, got ${t} = ${String(e)}.`);let n=e,r=typeof n.year=="number",o=typeof n.month=="number",a=typeof n.day=="number";if(r!==o||o!==a)throw new Error(`temporal-fmt: formatDistance got a ${t} with a partial date (some of year/month/day missing). Pass a full Temporal.PlainDate / PlainDateTime / ZonedDateTime.`);return{year:r?n.year:void 0,month:o?n.month:void 0,day:a?n.day:void 0,hour:typeof n.hour=="number"?n.hour:void 0,minute:typeof n.minute=="number"?n.minute:void 0,second:typeof n.second=="number"?n.second:void 0,millisecond:typeof n.millisecond=="number"?n.millisecond:void 0}}var ce=2e3,fe=1e3,G=60*fe,X=60*G,x=24*X;function bt(e,t,n){let r=0;if(e>=ce)for(let o=ce;o<e;o++)r+=I(o)?366:365;else for(let o=e;o<ce;o++)r-=I(o)?366:365;return r+=me(e,t,n)-1,r}function Se(e){if(e.year===void 0||e.month===void 0||e.day===void 0)throw new Error("temporal-fmt: formatDistance needs a Temporal value with year/month/day fields (PlainDate, PlainDateTime, or ZonedDateTime). A PlainTime or other shape has no anchor date to diff against.");let t=bt(e.year,e.month,e.day),n=e.hour??0,r=e.minute??0,o=e.second??0,a=e.millisecond??0;return t*x+n*X+r*G+o*fe+a}var kt=[{maxMs:G,unit:"second"},{maxMs:X,unit:"minute"},{maxMs:x,unit:"hour"},{maxMs:30*x,unit:"day"},{maxMs:365*x,unit:"month"}],H=new Map,Et=100;function Tt(e,t){let n=`${Dt(e)}|${t}`,r=H.get(n);if(r)return r;if(H.size>=Et){let o=H.keys().next().value;o!==void 0&&H.delete(o)}return r=new Intl.RelativeTimeFormat(e,{numeric:t}),H.set(n,r),r}function Dt(e){try{return new Intl.Locale(e.replace(/_/g,"-")).toString().toLowerCase()}catch{return e}}function xt(e,t,n={}){let r=ve(e,"date1"),o=ve(t,"date2"),a=Se(r)-Se(o),i=Math.abs(a),s="year";for(let{maxMs:f,unit:p}of kt)if(i<f){s=p;break}let m=Mt(s),c=Math.round(a/m),u=n.numeric??"auto",l=n.locale??R;return Tt(l,u).format(c,s)}function Mt(e){switch(e){case"second":return fe;case"minute":return G;case"hour":return X;case"day":return x;case"week":return 7*x;case"month":return 30*x;case"quarter":return 91*x;case"year":return 365*x;default:throw new Error(`temporal-fmt: formatDistance hit unhandled unit "${String(e)}".`)}}var ge=["January","February","March","April","May","June","July","August","September","October","November","December"],Pt=ge.flatMap((e,t)=>[[e,t+1],[e.slice(0,3),t+1]]),vt=Pt.map(([e])=>e).join("|"),pe=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],St=pe.join("|");function $t(e){let t=e.toLowerCase(),n=pe.find(r=>r.toLowerCase()===t);return pe.indexOf(n??e)+1}function Ft(e){let t=e.toLowerCase(),n=ge.findIndex(o=>o.toLowerCase()===t);return n>=0?n+1:ge.findIndex(o=>o.slice(0,3).toLowerCase()===t)+1}function Lt(e){let t=e.dayOfWeek;if(typeof t!="number")throw new Error("temporal-fmt: parseRelative needs a reference date exposing dayOfWeek (a Temporal.PlainDate / PlainDateTime / ZonedDateTime).");return t}function B(e){if(typeof e.year!="number")throw new Error("temporal-fmt: parseRelative reference date is missing year.");return e.year}function J(e){if(typeof e.month!="number")throw new Error("temporal-fmt: parseRelative reference date is missing month.");return e.month}function ee(e){if(typeof e.day!="number")throw new Error("temporal-fmt: parseRelative reference date is missing day.");return e.day}function Ot(e,t,n={}){n.locale;let r=t,o=$(),a=(e??"").trim().replace(/\s+/g," ");if(a.length===0)throw new Error("temporal-fmt: parseRelative got an empty input string.");let i=a.toLowerCase();if(i==="today")return Rt(o,B(r),J(r),ee(r));if(i==="tomorrow")return he(o,r,1);if(i==="yesterday")return he(o,r,-1);let s=a.match(new RegExp(`^(next|last|this)\\s+(${St})$`,"i"));if(s){let u=s[1].toLowerCase(),l=s[2],d=Lt(r),f=$t(l),p=Nt(u,d,f);return he(o,r,p)}let m=a.match(/^(in\s+)?(\d+)\s+(day|week|month|year)s?(?:\s+ago)?$/i);if(m){let u=m[1],l=m[2],d=m[3].toLowerCase(),f=!!u,p=/\bago\b/i.test(a);if(!f&&!p)throw new Error(`temporal-fmt: parseRelative can't tell whether "${a}" is past or future \u2014 use "in ${l} ${d}s" or "${l} ${d}s ago".`);return At(o,r,(f?1:-1)*Number(l),d)}let c=a.match(new RegExp(`^(${vt})\\s+(\\d{1,2})(?:st|nd|rd|th)?(?:,?\\s*(\\d{4}))?$`,"i"));if(c){let u=c[1],l=c[2],d=Ft(u),f=Number(l);return Ct(o,r,d,f)}throw new Error(`temporal-fmt: parseRelative doesn't recognize "${a}". Supported: weekday refs ("next Tuesday"), day offsets ("today"/"tomorrow"/"yesterday"), unit offsets ("in 3 days", "2 weeks ago"), and month-day ("March 5th").`)}function Nt(e,t,n){if(e==="next"){let r=n-t;return r<=0&&(r+=7),r}if(e==="last"){let r=n-t;return r>=0&&(r-=7),r}return n-t}function Rt(e,t,n,r){return e.PlainDate.from({year:t,month:n,day:r},{overflow:"reject"})}function he(e,t,n){return e.PlainDate.from({year:B(t),month:J(t),day:ee(t)}).add({days:n})}function At(e,t,n,r){let o=e.PlainDate.from({year:B(t),month:J(t),day:ee(t)}),a={};return r==="day"&&(a.days=n),r==="week"&&(a.weeks=n),r==="month"&&(a.months=n),r==="year"&&(a.years=n),o.add(a)}function Ct(e,t,n,r){let o=B(t),a=e.PlainDate.from({year:o,month:J(t),day:ee(t)});try{let i=e.PlainDate.from({year:o,month:n,day:r},{overflow:"reject"});if(!e.PlainDate.compare)throw new Error("temporal-fmt: parseRelative needs Temporal.PlainDate.compare to resolve month-day phrases; the active implementation does not expose it.");return e.PlainDate.compare(i,a)>=0?i:e.PlainDate.from({year:o+1,month:n,day:r},{overflow:"reject"})}catch(i){try{return e.PlainDate.from({year:o+1,month:n,day:r},{overflow:"reject"})}catch{throw new Error(`temporal-fmt: parseRelative can't resolve month ${n} day ${r} \u2014 it isn't a valid date in either ${o} or ${o+1}. Original error: ${i.message}`)}}}export{je as format,xt as formatDistance,wt as formatDuration,ht as parse,Ot as parseRelative,Re as registerLocaleVocab,Le as setTemporal};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|