temporal-fmt 0.8.3 → 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/README.md CHANGED
@@ -113,6 +113,11 @@ A few things worth knowing:
113
113
  - this is an opinionated tradeoff but ensures `yy` is deterministic without an external date reference
114
114
  - **`hh`/`h` (12-hour) without an `a` token throws** — same if a format string mixes `HH`/`H` with `hh`/`h`,
115
115
  even when both agree on the same hour. `parse` won't guess which one is authoritative; pick one.
116
+ - **`HH`/`H` combined with `a` is allowed, and cross-checked** — `parse('HH:mm a', '13:05 PM')` succeeds since
117
+ 13:05 can only mean PM, but `parse('HH:mm a', '01:05 PM')` throws: the day period contradicts the hour.
118
+ This is different from mixing `HH` with `hh`/`h` above — there's only one hour token here, `a` just confirms it.
119
+ - **`a` (AM/PM) matches case-insensitively** — `pm`, `Pm`, and `PM` all parse the same way. Month and weekday
120
+ names (`MMMM`, `EEEE`, etc.) stay case-sensitive; only the day-period marker is case-folded.
116
121
  - **`MMMM`/`MMM` name matching assumes a 12-month calendar** — the vocabulary
117
122
  it matches against is generated from 12 Gregorian reference dates, so a
118
123
  calendar with a leap month (e.g. Hebrew's 13-month leap years) isn't fully
@@ -179,7 +184,7 @@ yourself.
179
184
  | ss | 2-digit second | 30 |
180
185
  | s | second | 30 |
181
186
  | SSS | milliseconds | 000 |
182
- | a | AM/PM | PM |
187
+ | a | AM/PM (case-insensitive on parse) | PM |
183
188
  | Q | numeric quarter (1-4) | 3 |
184
189
  | QQQ | quarter with "Q" prefix (Q1, Q2, Q3, Q4) | Q3 |
185
190
  | ww | ISO 8601 week (01-53), format-only | 32 |
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var Ye=Object.prototype.hasOwnProperty;var Ze=(e,t)=>{for(var n in t)ie(e,n,{get:t[n],enumerable:!0})},He=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ve(t))!Ye.call(e,o)&&o!==n&&ie(e,o,{get:()=>t[o],enumerable:!(r=Ue(t,o))||r.enumerable});return e};var je=e=>He(ie({},"__esModule",{value:!0}),e);var Ht={};Ze(Ht,{format:()=>xe,formatDistance:()=>Ae,formatDuration:()=>Le,parse:()=>$e,parseRelative:()=>_e,registerLocaleVocab:()=>Te,setTemporal:()=>Ee});module.exports=je(Ht);var we,be=[];function ke(e){be.push(e)}function Ee(e){we=e;for(let t of be)t()}function ze(){return we??globalThis.Temporal}function F(){let e=ze();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 se=new Map;function Ke(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 Te(e,t){if(typeof e!="string"||e.length===0)throw new Error(`temporal-fmt: registerLocaleVocab requires a non-empty locale string, got ${String(e)}.`);Ke(t,e);let n=P(e);se.set(n,{monthLong:[...t.monthLong],monthShort:[...t.monthShort],weekdayLong:[...t.weekdayLong],weekdayShort:[...t.weekdayShort],dayPeriod:[...t.dayPeriod]}),O.delete(n)}function P(e){try{return new Intl.Locale(e.replace(/_/g,"-")).toString().toLowerCase()}catch{return e}}var O=new Map,We=500;function $(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 L(e){let t=P(e);return se.get(t)}function N(e){let t=P(e),n=se.get(t);if(n)return n;let r=O.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($(o,T,"month")),s.push($(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($(m,T,"weekday")),l.push($(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=$(d,new Date(Date.UTC(2020,0,1,1)),"dayPeriod"),p=$(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(O.size>=We){let y=O.keys().next().value;y!==void 0&&O.delete(y)}return O.set(t,b),b}var Qe=[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 _(e){return I(e)?366:365}function ue(e,t,n){let r=Qe[t-1]+n;return t>2&&I(e)&&(r+=1),r}var me=2e3;function qe(e){let t=0;if(e>=me)for(let r=me;r<e;r++)t+=_(r);else for(let r=e;r<me;r++)t-=_(r);return((5+t)%7+7)%7+1}function de(e,t,n,r){let a=ue(e,t,n)+(4-r),i,s;a<1?(i=e-1,s=a+_(i)):a>_(e)?(i=e+1,s=a-_(e)):(i=e,s=a);let c=1+(4-qe(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",C=new Map,Ge=500;function De(e,t){let n=JSON.stringify([P(e),t]),r=C.get(n);if(r)return r;if(C.size>=Ge){let o=C.keys().next().value;o!==void 0&&C.delete(o)}return r=new Intl.DateTimeFormat(e,t),C.set(n,r),r}var U;ke(()=>{U=void 0});function Xe(){if(U===void 0){U=!1;try{let e=F();new Intl.DateTimeFormat("en-US",{day:"numeric"}).formatToParts(e.PlainDate.from({year:1970,month:1,day:1})),U=!0}catch{}}return U}function Be(e,t,n,r){let o=e?.calendarId,a={...n,calendar:o&&o!=="iso8601"?o:"gregory"};if(!Xe())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=De(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 Je(e,t){let n=L(t);if(n)return e<12?n.dayPeriod[0]:n.dayPeriod[1];let r=new Date(Date.UTC(1970,0,1,e)),a=De(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]:Be(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=L(t);return K(e,t,{month:"long"},"month",n?.monthLong,e.month-1)},"month"],["MMM",(e,t)=>{let n=L(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=L(t);return K(e,t,{weekday:"long"},"weekday",n?.weekdayLong,e.dayOfWeek-1)},"dayOfWeek"],["EEE",(e,t)=>{let n=L(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)=>Je(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}=de(e.year,e.month,e.day,e.dayOfWeek);return k(t,2)},"dayOfWeek"],["RRRR",e=>{let{isoYear:t}=de(e.year,e.month,e.day,e.dayOfWeek);return k(t,4)},"dayOfWeek"]];var et=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]==="'"){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 format string "${e}"`);le(t,i),n=a;continue}let o=et.find(a=>e.startsWith(a,n));if(o){t.push({kind:"token",value:o}),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})}var tt=new Map(W.map(([e,t,n])=>[e,{fn:t,field:n}]));function xe(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=tt.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 nt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Y(e){return`(?:${e.map(nt).join("|")})`}var rt="(?:UTC|[+-]\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d{1,9})?)?|[A-Za-z_]+(?:[+-]\\d{1,2})?(?:\\/[A-Za-z0-9_+-]+)*)";function ot(){return rt}var q;function at(){return q||(q=new Set(Intl.supportedValuesOf("timeZone")),q.add("UTC")),q}var it=/^[+-]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?$/;function Me(e){return it.test(e)||at().has(e)}var st={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]"},mt="Q[1-4]",ut=new Set(["do","ww","RRRR"]),dt="-?\\d{4}",lt="-?\\d{4,}",ct=new Set(["yyyy","yy","MM","M","dd","d","HH","H","hh","h","mm","m","ss","s","SSS"]);function Pe(e,t,n){if(e==="yyyy")return n!==void 0&&ct.has(n)?dt:lt;let r=st[e];if(r)return r;if(e==="QQQ")return mt;if(ut.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);case"zzz":return ot();default:throw new Error(`temporal-fmt: unknown token "${e}"`)}}var ve=new Set(["M","d","H","h","m","s"]),ft={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 Se(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=ft[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 ht(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Fe(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+=ht(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}>${Pe(c.value,t,d)})`,ve.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,pt=500;function yt(e,t){let n=JSON.stringify([P(t),e]),r=Z.get(n);if(r)return r;if(Z.size>=pt){let o=Z.keys().next().value;o!==void 0&&Z.delete(o)}return r=Fe(Q(e),t),Z.set(n,r),r}var A=new Map,wt=500;function bt(e){let t=new Intl.Locale(e).toString().toLowerCase();if(A.has(t))return A.get(t);if(A.size>=wt){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 kt(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.indexOf(n);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 Et(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 Tt(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 Dt(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!==o)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 $e(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=bt(r),a=yt(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"&&!Me(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=Se(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:Et(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];kt(m,E,D,r,e)}let u=Tt(m),l=Dt(m,e,r),{month:d,day:f,minute:p,second:w,millisecond:b,timeZoneId:y,weekdayExpected:T,weekdayRaw:Ie,quarter:te}=m,Ce=u!==void 0||d!==void 0||f!==void 0,v=u!==void 0&&d!==void 0&&f!==void 0;if(Ce&&!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=F(),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: "${Ie}" 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 Oe={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"}},xt=Object.keys(Oe).flatMap(e=>[e+e+e,e+e,e]).sort((e,t)=>t.length-e.length);function Mt(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r==="'"){if(e[n+1]==="'"){ce(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}"`);ce(t,i),n=a;continue}let o=xt.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}ce(t,r),n+=1}return t}function ce(e,t){let n=e[e.length-1];n&&n.kind==="literal"?n.value+=t:e.push({kind:"literal",value:t})}function Pt(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 Le(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=Mt(t),a="";for(let i of o){if(i.kind==="literal"){a+=i.value;continue}let s=Oe[i.unit];if(!s)throw new Error(`temporal-fmt: unknown duration token "${i.value}"`);let m=Pt(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 Ne(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 fe=2e3,he=1e3,G=60*he,X=60*G,x=24*X;function vt(e,t,n){let r=0;if(e>=fe)for(let o=fe;o<e;o++)r+=I(o)?366:365;else for(let o=e;o<fe;o++)r-=I(o)?366:365;return r+=ue(e,t,n)-1,r}function Re(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=vt(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*he+a}var St=[{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,Ft=100;function $t(e,t){let n=`${Ot(e)}|${t}`,r=H.get(n);if(r)return r;if(H.size>=Ft){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 Ot(e){try{return new Intl.Locale(e.replace(/_/g,"-")).toString().toLowerCase()}catch{return e}}function Ae(e,t,n={}){let r=Ne(e,"date1"),o=Ne(t,"date2"),a=Re(r)-Re(o),i=Math.abs(a),s="year";for(let{maxMs:f,unit:p}of St)if(i<f){s=p;break}let m=Lt(s),c=Math.round(a/m),u=n.numeric??"auto",l=n.locale??R;return $t(l,u).format(c,s)}function Lt(e){switch(e){case"second":return he;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 pe=["January","February","March","April","May","June","July","August","September","October","November","December"],Nt=pe.flatMap((e,t)=>[[e,t+1],[e.slice(0,3),t+1]]),Rt=Nt.map(([e])=>e).join("|"),ye=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],At=ye.join("|");function _t(e){let t=e.toLowerCase(),n=ye.find(r=>r.toLowerCase()===t);return ye.indexOf(n??e)+1}function It(e){let t=e.toLowerCase(),n=pe.findIndex(o=>o.toLowerCase()===t);return n>=0?n+1:pe.findIndex(o=>o.slice(0,3).toLowerCase()===t)+1}function Ct(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 _e(e,t,n={}){n.locale;let r=t,o=F(),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 Vt(o,B(r),J(r),ee(r));if(i==="tomorrow")return ge(o,r,1);if(i==="yesterday")return ge(o,r,-1);let s=a.match(new RegExp(`^(next|last|this)\\s+(${At})$`,"i"));if(s){let u=s[1].toLowerCase(),l=s[2],d=Ct(r),f=_t(l),p=Ut(u,d,f);return ge(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 Yt(o,r,(f?1:-1)*Number(l),d)}let c=a.match(new RegExp(`^(${Rt})\\s+(\\d{1,2})(?:st|nd|rd|th)?(?:,?\\s*(\\d{4}))?$`,"i"));if(c){let u=c[1],l=c[2],d=It(u),f=Number(l);return Zt(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 Ut(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 Vt(e,t,n,r){return e.PlainDate.from({year:t,month:n,day:r},{overflow:"reject"})}function ge(e,t,n){return e.PlainDate.from({year:B(t),month:J(t),day:ee(t)}).add({days:n})}function Yt(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 Zt(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}`)}}}0&&(module.exports={format,formatDistance,formatDuration,parse,parseRelative,registerLocaleVocab,setTemporal});
1
+ "use strict";var ie=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var Ye=Object.prototype.hasOwnProperty;var Ze=(e,t)=>{for(var n in t)ie(e,n,{get:t[n],enumerable:!0})},He=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ve(t))!Ye.call(e,o)&&o!==n&&ie(e,o,{get:()=>t[o],enumerable:!(r=Ue(t,o))||r.enumerable});return e};var je=e=>He(ie({},"__esModule",{value:!0}),e);var jt={};Ze(jt,{format:()=>xe,formatDistance:()=>Ae,formatDuration:()=>Oe,parse:()=>Fe,parseRelative:()=>Ce,registerLocaleVocab:()=>Te,setTemporal:()=>Ee});module.exports=je(jt);var we,be=[];function ke(e){be.push(e)}function Ee(e){we=e;for(let t of be)t()}function ze(){return we??globalThis.Temporal}function $(){let e=ze();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 se=new Map;function Ke(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 Te(e,t){if(typeof e!="string"||e.length===0)throw new Error(`temporal-fmt: registerLocaleVocab requires a non-empty locale string, got ${String(e)}.`);Ke(t,e);let n=P(e);se.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,We=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 se.get(t)}function N(e){let t=P(e),n=se.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>=We){let y=L.keys().next().value;y!==void 0&&L.delete(y)}return L.set(t,b),b}var Qe=[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 ue(e,t,n){let r=Qe[t-1]+n;return t>2&&I(e)&&(r+=1),r}var me=2e3;function qe(e){let t=0;if(e>=me)for(let r=me;r<e;r++)t+=C(r);else for(let r=e;r<me;r++)t-=C(r);return((5+t)%7+7)%7+1}function de(e,t,n,r){let a=ue(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-qe(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,Ge=500;function De(e,t){let n=JSON.stringify([P(e),t]),r=_.get(n);if(r)return r;if(_.size>=Ge){let o=_.keys().next().value;o!==void 0&&_.delete(o)}return r=new Intl.DateTimeFormat(e,t),_.set(n,r),r}var U;ke(()=>{U=void 0});function Xe(){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 Be(e,t,n,r){let o=e?.calendarId,a={...n,calendar:o&&o!=="iso8601"?o:"gregory"};if(!Xe())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=De(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 Je(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=De(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]:Be(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)=>Je(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}=de(e.year,e.month,e.day,e.dayOfWeek);return k(t,2)},"dayOfWeek"],["RRRR",e=>{let{isoYear:t}=de(e.year,e.month,e.day,e.dayOfWeek);return k(t,4)},"dayOfWeek"]];var et=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]==="'"){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 format string "${e}"`);le(t,i),n=a;continue}let o=et.find(a=>e.startsWith(a,n));if(o){t.push({kind:"token",value:o}),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})}var tt=new Map(W.map(([e,t,n])=>[e,{fn:t,field:n}]));function xe(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=tt.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 nt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Y(e,t=!1){let n=e.map(nt);return t?`(?:${n.map(rt).join("|")})`:`(?:${n.join("|")})`}function rt(e){return e.replace(/[a-zA-Z]/g,t=>`[${t.toLowerCase()}${t.toUpperCase()}]`)}var ot="(?:UTC|[+-]\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d{1,9})?)?|[A-Za-z_]+(?:[+-]\\d{1,2})?(?:\\/[A-Za-z0-9_+-]+)*)";function at(){return ot}var q;function it(){return q||(q=new Set(Intl.supportedValuesOf("timeZone")),q.add("UTC")),q}var st=/^[+-]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?$/;function Me(e){return st.test(e)||it().has(e)}var mt={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]"},ut="Q[1-4]",dt=new Set(["do","ww","RRRR"]),lt="-?\\d{4}",ct="-?\\d{4,}",ft=new Set(["yyyy","yy","MM","M","dd","d","HH","H","hh","h","mm","m","ss","s","SSS"]);function Pe(e,t,n){if(e==="yyyy")return n!==void 0&&ft.has(n)?lt:ct;let r=mt[e];if(r)return r;if(e==="QQQ")return ut;if(dt.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 at();default:throw new Error(`temporal-fmt: unknown token "${e}"`)}}var ve=new Set(["M","d","H","h","m","s"]),ht={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 Se(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=ht[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 gt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function $e(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+=gt(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}>${Pe(c.value,t,d)})`,ve.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,yt=500;function wt(e,t){let n=JSON.stringify([P(t),e]),r=Z.get(n);if(r)return r;if(Z.size>=yt){let o=Z.keys().next().value;o!==void 0&&Z.delete(o)}return r=$e(Q(e),t),Z.set(n,r),r}var A=new Map,bt=500;function kt(e){let t=new Intl.Locale(e).toString().toLowerCase();if(A.has(t))return A.get(t);if(A.size>=bt){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 Et(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 Tt(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 Dt(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 xt(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 Fe(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=kt(r),a=wt(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"&&!Me(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=Se(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:Tt(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];Et(m,E,D,r,e)}let u=Dt(m),l=xt(m,e,r),{month:d,day:f,minute:p,second:w,millisecond:b,timeZoneId:y,weekdayExpected:T,weekdayRaw:Ie,quarter:te}=m,_e=u!==void 0||d!==void 0||f!==void 0,v=u!==void 0&&d!==void 0&&f!==void 0;if(_e&&!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: "${Ie}" 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 Le={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"}},Mt=Object.keys(Le).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]==="'"){ce(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}"`);ce(t,i),n=a;continue}let o=Mt.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}ce(t,r),n+=1}return t}function ce(e,t){let n=e[e.length-1];n&&n.kind==="literal"?n.value+=t:e.push({kind:"literal",value:t})}function vt(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 Oe(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=Le[i.unit];if(!s)throw new Error(`temporal-fmt: unknown duration token "${i.value}"`);let m=vt(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 Ne(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 fe=2e3,he=1e3,G=60*he,X=60*G,x=24*X;function St(e,t,n){let r=0;if(e>=fe)for(let o=fe;o<e;o++)r+=I(o)?366:365;else for(let o=e;o<fe;o++)r-=I(o)?366:365;return r+=ue(e,t,n)-1,r}function Re(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=St(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*he+a}var $t=[{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,Ft=100;function Lt(e,t){let n=`${Ot(e)}|${t}`,r=H.get(n);if(r)return r;if(H.size>=Ft){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 Ot(e){try{return new Intl.Locale(e.replace(/_/g,"-")).toString().toLowerCase()}catch{return e}}function Ae(e,t,n={}){let r=Ne(e,"date1"),o=Ne(t,"date2"),a=Re(r)-Re(o),i=Math.abs(a),s="year";for(let{maxMs:f,unit:p}of $t)if(i<f){s=p;break}let m=Nt(s),c=Math.round(a/m),u=n.numeric??"auto",l=n.locale??R;return Lt(l,u).format(c,s)}function Nt(e){switch(e){case"second":return he;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 pe=["January","February","March","April","May","June","July","August","September","October","November","December"],Rt=pe.flatMap((e,t)=>[[e,t+1],[e.slice(0,3),t+1]]),At=Rt.map(([e])=>e).join("|"),ye=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],Ct=ye.join("|");function It(e){let t=e.toLowerCase(),n=ye.find(r=>r.toLowerCase()===t);return ye.indexOf(n??e)+1}function _t(e){let t=e.toLowerCase(),n=pe.findIndex(o=>o.toLowerCase()===t);return n>=0?n+1:pe.findIndex(o=>o.slice(0,3).toLowerCase()===t)+1}function Ut(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 Ce(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 Yt(o,B(r),J(r),ee(r));if(i==="tomorrow")return ge(o,r,1);if(i==="yesterday")return ge(o,r,-1);let s=a.match(new RegExp(`^(next|last|this)\\s+(${Ct})$`,"i"));if(s){let u=s[1].toLowerCase(),l=s[2],d=Ut(r),f=It(l),p=Vt(u,d,f);return ge(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 Zt(o,r,(f?1:-1)*Number(l),d)}let c=a.match(new RegExp(`^(${At})\\s+(\\d{1,2})(?:st|nd|rd|th)?(?:,?\\s*(\\d{4}))?$`,"i"));if(c){let u=c[1],l=c[2],d=_t(u),f=Number(l);return Ht(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 Vt(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 Yt(e,t,n,r){return e.PlainDate.from({year:t,month:n,day:r},{overflow:"reject"})}function ge(e,t,n){return e.PlainDate.from({year:B(t),month:J(t),day:ee(t)}).add({days:n})}function Zt(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 Ht(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}`)}}}0&&(module.exports={format,formatDistance,formatDuration,parse,parseRelative,registerLocaleVocab,setTemporal});
2
2
  //# sourceMappingURL=index.cjs.map