date-and-time 4.4.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +49 -41
- package/dist/index.js +1 -1
- package/dist/plugin.d.ts +48 -0
- package/dist/plugins/day-of-week.d.ts +48 -0
- package/dist/plugins/microsecond.d.ts +48 -0
- package/dist/plugins/nanosecond.d.ts +48 -0
- package/dist/plugins/ordinal.d.ts +48 -0
- package/dist/plugins/two-digit-year.d.ts +48 -0
- package/package.json +14 -16
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/** @preserve Copyright (c) KNOWLEDGECODE - MIT License */const e=/\\\[/g,t=/\\\]/g,n=/\uE000/g,r=/\uE001/g,s=/\[(?:[^[\]]|\[[^[\]]*])*]|([A-Za-z])\1*|\.{3}|./g,o=o=>{const a=o.replace(e,"").replace(t,"").match(s)??[];return[o,...a.map(e=>e.replace(n,"[").replace(r,"]"))]},a=new Map,i=e=>a.get(e)??(()=>{const t=new Intl.DateTimeFormat("en-US",{hour12:!1,weekday:"short",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",fractionalSecondDigits:3,timeZone:e});return e&&a.set(e,t),t})(),c=e=>Date.UTC(e.year,e.month-(e.year<100?22801:1),e.day,e.hour,e.minute,e.second,e.fractionalSecond+6e4*e.timezoneOffset),u=(e,t)=>e.formatToParts(t).reduce((e,{type:t,value:n})=>{switch(t){case"weekday":e[t]="SunMonTueWedThuFriSat".indexOf(n)/3;break;case"hour":e[t]=+n%24;break;case"year":case"month":case"day":case"minute":case"second":case"fractionalSecond":e[t]=+n}return e},{weekday:4,year:1970,month:1,day:1,hour:0,minute:0,second:0,fractionalSecond:0,timezoneOffset:0}),l=e=>"string"==typeof e&&"UTC"===e.toUpperCase(),d=(e,t)=>{if(l(t))return{weekday:e.getUTCDay(),year:e.getUTCFullYear(),month:e.getUTCMonth()+1,day:e.getUTCDate(),hour:e.getUTCHours(),minute:e.getUTCMinutes(),second:e.getUTCSeconds(),fractionalSecond:e.getUTCMilliseconds(),timezoneOffset:0};const n=e.getTime(),r=u(i(t),n);return r.timezoneOffset=(n-c(r))/6e4,r};class h{constructor(e,t){this.parts=d(e,t),this.time=e.getTime()}getFullYear(){return this.parts.year}getMonth(){return this.parts.month-1}getDate(){return this.parts.day}getHours(){return this.parts.hour}getMinutes(){return this.parts.minute}getSeconds(){return this.parts.second}getMilliseconds(){return this.parts.fractionalSecond}getDay(){return this.parts.weekday}getTime(){return this.time}getTimezoneOffset(){return this.parts.timezoneOffset}}class m{}const g=(e,t)=>e.getFullYear()+("buddhist"===t?543:0);const M=new class extends m{YYYY(e,t){return`000${String(g(e,t.calendar))}`.slice(-4)}YY(e,t){return`0${String(g(e,t.calendar))}`.slice(-2)}Y(e,t){return String(g(e,t.calendar))}MMMM(e,t,n){return t.locale.getMonthList({style:"long",compiledObj:n})[e.getMonth()]??""}MMM(e,t,n){return t.locale.getMonthList({style:"short",compiledObj:n})[e.getMonth()]??""}MM(e){return`0${String(e.getMonth()+1)}`.slice(-2)}M(e){return String(e.getMonth()+1)}DD(e){return`0${String(e.getDate())}`.slice(-2)}D(e){return String(e.getDate())}HH(e,t){return`0${String(e.getHours()||("h24"===t.hour24?24:0))}`.slice(-2)}H(e,t){return String(e.getHours()||("h24"===t.hour24?24:0))}AA(e,t,n){return t.locale.getMeridiemList({style:"long",compiledObj:n,case:"uppercase"})[+(e.getHours()>11)]??""}A(e,t,n){return t.locale.getMeridiemList({style:"short",compiledObj:n,case:"uppercase"})[+(e.getHours()>11)]??""}aa(e,t,n){return t.locale.getMeridiemList({style:"long",compiledObj:n,case:"lowercase"})[+(e.getHours()>11)]??""}a(e,t,n){return t.locale.getMeridiemList({style:"short",compiledObj:n,case:"lowercase"})[+(e.getHours()>11)]??""}hh(e,t){return`0${String(e.getHours()%12||("h12"===t.hour12?12:0))}`.slice(-2)}h(e,t){return String(e.getHours()%12||("h12"===t.hour12?12:0))}mm(e){return`0${String(e.getMinutes())}`.slice(-2)}m(e){return String(e.getMinutes())}ss(e){return`0${String(e.getSeconds())}`.slice(-2)}s(e){return String(e.getSeconds())}SSS(e){return`00${String(e.getMilliseconds())}`.slice(-3)}SS(e){return`00${String(e.getMilliseconds())}`.slice(-3,-1)}S(e){return`00${String(e.getMilliseconds())}`.slice(-3,-2)}dddd(e,t,n){return t.locale.getDayOfWeekList({style:"long",compiledObj:n})[e.getDay()]??""}ddd(e,t,n){return t.locale.getDayOfWeekList({style:"short",compiledObj:n})[e.getDay()]??""}dd(e,t,n){return t.locale.getDayOfWeekList({style:"narrow",compiledObj:n})[e.getDay()]??""}Z(e){const t=e.getTimezoneOffset(),n=Math.abs(t);return`${t>0?"-":"+"}${`0${String(n/60|0)}`.slice(-2)}${`0${String(n%60)}`.slice(-2)}`}ZZ(e){const t=e.getTimezoneOffset(),n=Math.abs(t);return`${t>0?"-":"+"}${`0${String(n/60|0)}`.slice(-2)}:${`0${String(n%60)}`.slice(-2)}`}},f={MMMM:["January","February","March","April","May","June","July","August","September","October","November","December"],MMM:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dddd:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ddd:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dd:["Su","Mo","Tu","We","Th","Fr","Sa"],A:["AM","PM"],AA:["A.M.","P.M."],a:["am","pm"],aa:["a.m.","p.m."]};var p=new class{getLocale(){return"en"}getMonthList(e){return"long"===e.style?f.MMMM:f.MMM}getDayOfWeekList(e){return"long"===e.style?f.dddd:"short"===e.style?f.ddd:f.dd}getMeridiemList(e){return"long"===e.style?"lowercase"===e.case?f.aa:f.AA:"lowercase"===e.case?f.a:f.A}},y={encode:e=>e,decode:e=>e};const S=e=>!!e&&"object"==typeof e&&"zone_name"in e&&"gmt_offset"in e,D=(e,t)=>{const n=S(t)?t.zone_name:t;return new Date(e-((e,t)=>{const n=(()=>{try{return i(t)}catch{return}})(),r=new Set;if(n)for(let t=0;t<2;t++){const s=e-86400*t*1e3;let o=54822e3;do{const e=c(u(n,s-o))-s;if(0===e)return o;r.add(o),o+=e}while(!r.has(o));r.clear()}return NaN})(e,n))},T=/^\[(.*)\]$/;function b(e,t,n){const r=("string"==typeof t?o(t):t).slice(1),s=S(n?.timeZone)?n.timeZone.zone_name:n?.timeZone,a=s?new h(e,s):e,i={hour12:n?.hour12??"h12",hour24:n?.hour24??"h23",numeral:n?.numeral??y,calendar:n?.calendar??"gregory",timeZone:n?.timeZone,locale:n?.locale??p},c=[...n?.plugins??[],M],u=i.numeral.encode;return r.reduce((e,t)=>e+((e,t)=>{for(const n of c)if(n[e])return u(n[e](a,i,t));return T.test(e)?e.replace(T,"$1"):e})(t,r),"")}class w{}const C=(e,t,n)=>{const r=e.exec(t)?.[0]??"";return{value:+r,length:r.length,token:n}},O=(e,t,n,r)=>{const[s,o]=n.ignoreCase?(()=>{const r=n.locale.getLocale();return[e.map(e=>e.toLocaleLowerCase(r)),t.toLocaleLowerCase(r)]})():[e,t];return s.reduce((e,t,n)=>t.length>e.length&&!o.indexOf(t)?{value:n,length:t.length,token:r}:e,{value:-1,length:0,token:r})},Y=new Set(["Y","M","D","H","A","h","m","s","S","Z"]),x=e=>Y.has(e);const U=new class extends w{YYYY(e){return C(/^\d{4}/,e,"Y")}Y(e){return C(/^\d{1,4}/,e,"Y")}MMMM(e,t,n){const r=t.locale.getMonthList({style:"long",compiledObj:n}),s=O(r,e,t,"M");return s.value++,s}MMM(e,t,n){const r=t.locale.getMonthList({style:"short",compiledObj:n}),s=O(r,e,t,"M");return s.value++,s}MM(e){return C(/^\d\d/,e,"M")}M(e){return C(/^\d\d?/,e,"M")}DD(e){return C(/^\d\d/,e,"D")}D(e){return C(/^\d\d?/,e,"D")}HH(e){return C(/^\d\d/,e,"H")}H(e){return C(/^\d\d?/,e,"H")}AA(e,t,n){const r=t.locale.getMeridiemList({style:"long",compiledObj:n,case:"uppercase"});return O(r,e,t,"A")}A(e,t,n){const r=t.locale.getMeridiemList({style:"short",compiledObj:n,case:"uppercase"});return O(r,e,t,"A")}aa(e,t,n){const r=t.locale.getMeridiemList({style:"long",compiledObj:n,case:"lowercase"});return O(r,e,t,"A")}a(e,t,n){const r=t.locale.getMeridiemList({style:"short",compiledObj:n,case:"lowercase"});return O(r,e,t,"A")}hh(e){return C(/^\d\d/,e,"h")}h(e){return C(/^\d\d?/,e,"h")}mm(e){return C(/^\d\d/,e,"m")}m(e){return C(/^\d\d?/,e,"m")}ss(e){return C(/^\d\d/,e,"s")}s(e){return C(/^\d\d?/,e,"s")}SSS(e){return C(/^\d{1,3}/,e,"S")}SS(e){const t=C(/^\d\d?/,e,"S");return t.value*=10,t}S(e){const t=C(/^\d/,e,"S");return t.value*=100,t}Z(e){const t=C(/^[+-][01]\d[0-5]\d/,e,"Z");return t.value=-60*(t.value/100|0)-t.value%100,t}ZZ(e){const t=/^([+-][01]\d):([0-5]\d)/.exec(e)??["","",""],n=+(t[1]+t[2]);return{value:-60*(n/100|0)-n%100,length:t[0].length,token:"Z"}}},v=/^\[(.*)\]$/;function $(e,t,n){const r=("string"==typeof t?o(t):t).slice(1),s={hour12:n?.hour12??"h12",hour24:n?.hour24??"h23",numeral:n?.numeral??y,calendar:n?.calendar??"gregory",ignoreCase:n?.ignoreCase??!1,timeZone:(S(n?.timeZone)||"string"==typeof n?.timeZone)&&n.timeZone||void 0,locale:n?.locale??p},a={_index:0,_length:0,_match:0},i=[...n?.plugins??[],U],c=(e,t)=>{for(const n of i)if(n[e])return n[e](t,s,r)};e=s.numeral.decode(e);for(const t of r){const n=e.substring(a._index),r=c(t,n);if(r){if(!r.length)break;r.token&&x(r.token)&&(a[r.token]=r.value+0),a._index+=r.length,a._match++}else if(t===n[0]||" "===t)a._index++;else{if(!v.test(t)||n.indexOf(t.replace(v,"$1"))){if("..."===t){a._index=e.length;break}break}a._index+=t.length-2}}return a._length=e.length,a}const H=(e,t,n)=>Date.UTC(e,t-(e<100?22800:0),n);function A(...e){const[t,n]=1===e.length?[e[0].getFullYear(),e[0].getMonth()+1]:e;return new Date(H(t,n,0)).getUTCDate()}const Z=e=>{const t=new Date(e);return t.setUTCDate(t.getUTCDate()+(4-(t.getUTCDay()||7))),t};function L(e,t){const n=void 0===e.Y?1970:e.Y-("buddhist"===t?.calendar?543:0),[r,s]="h11"===t?.hour12?[0,11]:[1,12],[o,a]="h24"===t?.hour24?[1,24]:[0,23],i=(e,t,n)=>void 0===e||e>=t&&e<=n;return e._index>0&&e._length>0&&e._index===e._length&&e._match>0&&i(n,1,9999)&&i(e.M,1,12)&&i(e.D,1,A(n,e.M??1))&&i(e.H,o,a)&&i(e.A,0,1)&&i(e.h,r,s)&&i(e.m,0,59)&&i(e.s,0,59)&&i(e.S,0,999)&&i(e.Z,-913,956)}function k(e,t,n){const r=$(e,t,n);return L(r,n)?(r.Y=r.Y?r.Y-("buddhist"===n?.calendar?543:0):1970,r.M=(r.M??1)-(r.Y<100?22801:1),r.D??=1,r.H=(r.H??0)%24||12*(r.A??0)+(r.h??0)%12,r.m??=0,r.s??=0,r.S??=0,l(n?.timeZone)||"Z"in r?new Date(Date.UTC(r.Y,r.M,r.D,r.H,r.m+(r.Z??0),r.s,r.S)):n?.timeZone?D(Date.UTC(r.Y,r.M,r.D,r.H,r.m,r.s,r.S),n.timeZone):new Date(r.Y,r.M,r.D,r.H,r.m,r.s,r.S)):new Date(NaN)}function _(e,t,n){const r=S(n)?n.zone_name:n??void 0;if(!r||l(r)){const r=new Date(e.getTime());return l(n)?(r.setUTCMonth(r.getUTCMonth()+t),r.getUTCDate()<e.getUTCDate()?(r.setUTCDate(0),r):r):(r.setMonth(r.getMonth()+t),r.getDate()<e.getDate()?(r.setDate(0),r):r)}const s=d(e,r);s.month+=t,s.timezoneOffset=0;const o=new Date(c(s));return o.getUTCDate()<s.day&&o.setUTCDate(0),D(c({...s,year:o.getUTCFullYear(),month:o.getUTCMonth()+1,day:o.getUTCDate()}),r)}const F=/^\[(.*)\]$/,j=(e,t)=>(e.F=Math.trunc(1e6*t),e),z=(e,t)=>(e.f=Math.trunc(1e3*t),j(e,1e3*Math.abs(t)%1/1e3)),P=(e,t)=>(e.S=Math.trunc(t),z(e,Math.abs(t)%1)),W=(e,t)=>(e.s=Math.trunc(t/1e3),P(e,Math.abs(t)%1e3)),N=(e,t)=>(e.m=Math.trunc(t/6e4),W(e,Math.abs(t)%6e4)),J=(e,t)=>(e.H=Math.trunc(t/36e5),N(e,Math.abs(t)%36e5)),I=(e,t,n=y)=>{const r=o(t).slice(1);return r.reduce((t,r)=>t+(t=>{if(t[0]in e){const r=e[t[0]]??0;return n.encode(`${(e=>e<0||0===e&&1/e==-1/0?"-":"")(r)}${String(Math.abs(r)).padStart(t.length,"0")}`)}return F.test(t)?t.replace(F,"$1"):t})(r),"")};class E{constructor(e){this.time=e}toNanoseconds(){return{value:1e6*this.time,format:(e,t)=>I(j({},this.time),e,t),toParts:()=>({nanoseconds:Math.trunc(1e6*this.time)+0})}}toMicroseconds(){return{value:1e3*this.time,format:(e,t)=>I(z({},this.time),e,t),toParts:()=>({microseconds:Math.trunc(1e3*this.time)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toMilliseconds(){return{value:this.time,format:(e,t)=>I(P({},this.time),e,t),toParts:()=>({milliseconds:Math.trunc(this.time)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toSeconds(){return{value:this.time/1e3,format:(e,t)=>I(W({},this.time),e,t),toParts:()=>({seconds:Math.trunc(this.time/1e3)+0,milliseconds:Math.trunc(this.time%1e3)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toMinutes(){return{value:this.time/6e4,format:(e,t)=>I(N({},this.time),e,t),toParts:()=>({minutes:Math.trunc(this.time/6e4)+0,seconds:Math.trunc(this.time%864e5%36e5%6e4/1e3)+0,milliseconds:Math.trunc(this.time%1e3)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toHours(){return{value:this.time/36e5,format:(e,t)=>I(J({},this.time),e,t),toParts:()=>({hours:Math.trunc(this.time/36e5)+0,minutes:Math.trunc(this.time%864e5%36e5/6e4)+0,seconds:Math.trunc(this.time%864e5%36e5%6e4/1e3)+0,milliseconds:Math.trunc(this.time%1e3)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toDays(){return{value:this.time/864e5,format:(e,t)=>{return I((n={},r=this.time,n.D=Math.trunc(r/864e5),J(n,Math.abs(r)%864e5)),e,t);var n,r},toParts:()=>({days:Math.trunc(this.time/864e5)+0,hours:Math.trunc(this.time%864e5/36e5)+0,minutes:Math.trunc(this.time%864e5%36e5/6e4)+0,seconds:Math.trunc(this.time%864e5%36e5%6e4/1e3)+0,milliseconds:Math.trunc(this.time%1e3)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}}exports.Duration=E,exports.addDays=function(e,t,n){const r=S(n)?n.zone_name:n??void 0;if(!r||l(r)){const r=new Date(e.getTime());return l(n)?(r.setUTCDate(r.getUTCDate()+t),r):(r.setDate(r.getDate()+t),r)}const s=d(e,r);return s.day+=t,s.timezoneOffset=0,D(c(s),r)},exports.addHours=function(e,t){return new Date(e.getTime()+36e5*t)},exports.addMilliseconds=function(e,t){return new Date(e.getTime()+t)},exports.addMinutes=function(e,t){return new Date(e.getTime()+6e4*t)},exports.addMonths=_,exports.addSeconds=function(e,t){return new Date(e.getTime()+1e3*t)},exports.addYears=function(e,t,n){return _(e,12*t,n)},exports.compile=o,exports.format=b,exports.getDaysInMonth=A,exports.getISOWeek=function(...e){const[t,n,r]=1===e.length?[e[0].getFullYear(),e[0].getMonth()+1,e[0].getDate()]:e,s=Z(H(t,n-1,r));return Math.round((s.getTime()-Z(H(s.getUTCFullYear(),0,4)).getTime())/864e5/7)+1},exports.getISOWeekYear=function(...e){const[t,n,r]=1===e.length?[e[0].getFullYear(),e[0].getMonth()+1,e[0].getDate()]:e;return Z(H(t,n-1,r)).getUTCFullYear()},exports.isLeapYear=e=>!((e%4||!(e%100))&&e%400),exports.isSameDay=(e,t)=>e.toDateString()===t.toDateString(),exports.isValid=function(e,t,n){return L($(e,t,n),n)},exports.parse=k,exports.preparse=$,exports.subtract=(e,t)=>new E(t.getTime()-e.getTime()),exports.transform=function(e,t,n,r,s){return b(k(e,t,r),n,s)};
|
|
2
|
+
/** @preserve Copyright (c) KNOWLEDGECODE - MIT License */const e=/\\\[/g,t=/\\\]/g,n=/\uE000/g,r=/\uE001/g,s=/\[(?:[^[\]]|\[[^[\]]*])*]|([A-Za-z])\1*|\.{3}|./g,o=o=>{const a=o.replace(e,"").replace(t,"").match(s)??[];return[o,...a.map(e=>e.replace(n,"[").replace(r,"]"))]},a=new Map,i=e=>a.get(e)??(()=>{const t=new Intl.DateTimeFormat("en-US",{hour12:!1,weekday:"short",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",fractionalSecondDigits:3,timeZone:e});return e&&a.set(e,t),t})(),c=e=>Date.UTC(e.year,e.month-(e.year<100?22801:1),e.day,e.hour,e.minute,e.second,e.fractionalSecond+6e4*e.timezoneOffset),u=(e,t)=>e.formatToParts(t).reduce((e,{type:t,value:n})=>{switch(t){case"weekday":e[t]="SunMonTueWedThuFriSat".indexOf(n)/3;break;case"hour":e[t]=+n%24;break;case"year":case"month":case"day":case"minute":case"second":case"fractionalSecond":e[t]=+n}return e},{weekday:4,year:1970,month:1,day:1,hour:0,minute:0,second:0,fractionalSecond:0,timezoneOffset:0}),l=e=>"string"==typeof e&&"UTC"===e.toUpperCase(),d=(e,t)=>{if(l(t))return{weekday:e.getUTCDay(),year:e.getUTCFullYear(),month:e.getUTCMonth()+1,day:e.getUTCDate(),hour:e.getUTCHours(),minute:e.getUTCMinutes(),second:e.getUTCSeconds(),fractionalSecond:e.getUTCMilliseconds(),timezoneOffset:0};const n=e.getTime(),r=u(i(t),n);return r.timezoneOffset=(n-c(r))/6e4,r};class h{constructor(e,t){this.parts=d(e,t),this.time=e.getTime()}getFullYear(){return this.parts.year}getMonth(){return this.parts.month-1}getDate(){return this.parts.day}getHours(){return this.parts.hour}getMinutes(){return this.parts.minute}getSeconds(){return this.parts.second}getMilliseconds(){return this.parts.fractionalSecond}getDay(){return this.parts.weekday}getTime(){return this.time}getTimezoneOffset(){return this.parts.timezoneOffset}}class m{}const g=(e,t)=>e.getFullYear()+("buddhist"===t?543:0);const M=new class extends m{YYYY(e,t){return`000${String(g(e,t.calendar))}`.slice(-4)}YY(e,t){return`0${String(g(e,t.calendar))}`.slice(-2)}Y(e,t){return String(g(e,t.calendar))}MMMM(e,t,n){return t.locale.getMonthList({style:"long",compiledObj:n})[e.getMonth()]??""}MMM(e,t,n){return t.locale.getMonthList({style:"short",compiledObj:n})[e.getMonth()]??""}MM(e){return`0${String(e.getMonth()+1)}`.slice(-2)}M(e){return String(e.getMonth()+1)}DD(e){return`0${String(e.getDate())}`.slice(-2)}D(e){return String(e.getDate())}HH(e,t){return`0${String(e.getHours()||("h24"===t.hour24?24:0))}`.slice(-2)}H(e,t){return String(e.getHours()||("h24"===t.hour24?24:0))}AA(e,t,n){return t.locale.getMeridiemList({style:"long",compiledObj:n,case:"uppercase"})[+(e.getHours()>11)]??""}A(e,t,n){return t.locale.getMeridiemList({style:"short",compiledObj:n,case:"uppercase"})[+(e.getHours()>11)]??""}aa(e,t,n){return t.locale.getMeridiemList({style:"long",compiledObj:n,case:"lowercase"})[+(e.getHours()>11)]??""}a(e,t,n){return t.locale.getMeridiemList({style:"short",compiledObj:n,case:"lowercase"})[+(e.getHours()>11)]??""}hh(e,t){return`0${String(e.getHours()%12||("h12"===t.hour12?12:0))}`.slice(-2)}h(e,t){return String(e.getHours()%12||("h12"===t.hour12?12:0))}mm(e){return`0${String(e.getMinutes())}`.slice(-2)}m(e){return String(e.getMinutes())}ss(e){return`0${String(e.getSeconds())}`.slice(-2)}s(e){return String(e.getSeconds())}SSS(e){return`00${String(e.getMilliseconds())}`.slice(-3)}SS(e){return`00${String(e.getMilliseconds())}`.slice(-3,-1)}S(e){return`00${String(e.getMilliseconds())}`.slice(-3,-2)}dddd(e,t,n){return t.locale.getDayOfWeekList({style:"long",compiledObj:n})[e.getDay()]??""}ddd(e,t,n){return t.locale.getDayOfWeekList({style:"short",compiledObj:n})[e.getDay()]??""}dd(e,t,n){return t.locale.getDayOfWeekList({style:"narrow",compiledObj:n})[e.getDay()]??""}Z(e){const t=e.getTimezoneOffset(),n=Math.abs(t);return`${t>0?"-":"+"}${`0${String(n/60|0)}`.slice(-2)}${`0${String(n%60)}`.slice(-2)}`}ZZ(e){const t=e.getTimezoneOffset(),n=Math.abs(t);return`${t>0?"-":"+"}${`0${String(n/60|0)}`.slice(-2)}:${`0${String(n%60)}`.slice(-2)}`}},f={MMMM:["January","February","March","April","May","June","July","August","September","October","November","December"],MMM:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dddd:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ddd:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dd:["Su","Mo","Tu","We","Th","Fr","Sa"],A:["AM","PM"],AA:["A.M.","P.M."],a:["am","pm"],aa:["a.m.","p.m."]};var p=new class{getLocale(){return"en"}getMonthList(e){return"long"===e.style?f.MMMM:f.MMM}getDayOfWeekList(e){return"long"===e.style?f.dddd:"short"===e.style?f.ddd:f.dd}getMeridiemList(e){return"long"===e.style?"lowercase"===e.case?f.aa:f.AA:"lowercase"===e.case?f.a:f.A}},D={encode:e=>e,decode:e=>e};const y=e=>!!e&&"object"==typeof e&&"zone_name"in e&&"gmt_offset"in e,S=(e,t)=>{const n=y(t)?t.zone_name:t;return new Date(e-((e,t)=>{const n=(()=>{try{return i(t)}catch{return}})(),r=new Set;if(n)for(let t=0;t<2;t++){const s=e-86400*t*1e3;let o=54822e3;do{const e=c(u(n,s-o))-s;if(0===e)return o;r.add(o),o+=e}while(!r.has(o));r.clear()}return NaN})(e,n))},T=/^\[(.*)\]$/;function b(e,t,n){const r=("string"==typeof t?o(t):t).slice(1),s=y(n?.timeZone)?n.timeZone.zone_name:n?.timeZone,a=s?new h(e,s):e,i={hour12:n?.hour12??"h12",hour24:n?.hour24??"h23",numeral:n?.numeral??D,calendar:n?.calendar??"gregory",timeZone:n?.timeZone,locale:n?.locale??p},c=[...n?.plugins??[],M],u=i.numeral.encode;return r.reduce((e,t)=>e+((e,t)=>{for(const n of c)if(n[e])return u(n[e](a,i,t));return T.test(e)?e.replace(T,"$1"):e})(t,r),"")}class w{}const C=(e,t,n)=>{const r=e.exec(t)?.[0]??"";return{value:+r,length:r.length,token:n}},O=(e,t,n,r)=>{const[s,o]=n.ignoreCase?(()=>{const r=n.locale.getLocale();return[e.map(e=>e.toLocaleLowerCase(r)),t.toLocaleLowerCase(r)]})():[e,t];return s.reduce((e,t,n)=>t.length>e.length&&!o.indexOf(t)?{value:n,length:t.length,token:r}:e,{value:-1,length:0,token:r})},x=new Set(["Y","M","D","H","A","h","m","s","S","Z"]),U=e=>x.has(e);const Y=new class extends w{YYYY(e){return C(/^\d{4}/,e,"Y")}Y(e){return C(/^\d{1,4}/,e,"Y")}MMMM(e,t,n){const r=t.locale.getMonthList({style:"long",compiledObj:n}),s=O(r,e,t,"M");return s.value++,s}MMM(e,t,n){const r=t.locale.getMonthList({style:"short",compiledObj:n}),s=O(r,e,t,"M");return s.value++,s}MM(e){return C(/^\d\d/,e,"M")}M(e){return C(/^\d\d?/,e,"M")}DD(e){return C(/^\d\d/,e,"D")}D(e){return C(/^\d\d?/,e,"D")}HH(e){return C(/^\d\d/,e,"H")}H(e){return C(/^\d\d?/,e,"H")}AA(e,t,n){const r=t.locale.getMeridiemList({style:"long",compiledObj:n,case:"uppercase"});return O(r,e,t,"A")}A(e,t,n){const r=t.locale.getMeridiemList({style:"short",compiledObj:n,case:"uppercase"});return O(r,e,t,"A")}aa(e,t,n){const r=t.locale.getMeridiemList({style:"long",compiledObj:n,case:"lowercase"});return O(r,e,t,"A")}a(e,t,n){const r=t.locale.getMeridiemList({style:"short",compiledObj:n,case:"lowercase"});return O(r,e,t,"A")}hh(e){return C(/^\d\d/,e,"h")}h(e){return C(/^\d\d?/,e,"h")}mm(e){return C(/^\d\d/,e,"m")}m(e){return C(/^\d\d?/,e,"m")}ss(e){return C(/^\d\d/,e,"s")}s(e){return C(/^\d\d?/,e,"s")}SSS(e){return C(/^\d{1,3}/,e,"S")}SS(e){const t=C(/^\d\d?/,e,"S");return t.value*=10,t}S(e){const t=C(/^\d/,e,"S");return t.value*=100,t}Z(e){const t=C(/^[+-][01]\d[0-5]\d/,e,"Z");return t.value=-60*(t.value/100|0)-t.value%100,t}ZZ(e){const t=/^([+-][01]\d):([0-5]\d)/.exec(e)??["","",""],n=+(t[1]+t[2]);return{value:-60*(n/100|0)-n%100,length:t[0].length,token:"Z"}}},A=/^\[(.*)\]$/;function v(e,t,n){const r=("string"==typeof t?o(t):t).slice(1),s={hour12:n?.hour12??"h12",hour24:n?.hour24??"h23",numeral:n?.numeral??D,calendar:n?.calendar??"gregory",ignoreCase:n?.ignoreCase??!1,timeZone:(y(n?.timeZone)||"string"==typeof n?.timeZone)&&n.timeZone||void 0,locale:n?.locale??p,defaultDate:n?.defaultDate??{}},a={_index:0,_length:0,_match:0},i=[...n?.plugins??[],Y],c=(e,t)=>{for(const n of i)if(n[e])return n[e](t,s,r)};e=s.numeral.decode(e);for(const t of r){const n=e.substring(a._index),r=c(t,n);if(r){if(!r.length)break;r.token&&U(r.token)&&(a[r.token]=r.value+0),a._index+=r.length,a._match++}else if(t===n[0]||" "===t)a._index++;else{if(!A.test(t)||n.indexOf(t.replace(A,"$1"))){if("..."===t){a._index=e.length;break}break}a._index+=t.length-2}}return a._length=e.length,a}const $=(e,t,n)=>Date.UTC(e,t-(e<100?22800:0),n);function H(...e){const[t,n]=1===e.length?[e[0].getFullYear(),e[0].getMonth()+1]:e;return new Date($(t,n,0)).getUTCDate()}const Z=e=>{const t=new Date(e);return t.setUTCDate(t.getUTCDate()+(4-(t.getUTCDay()||7))),t};const L=(e,t)=>void 0===e?e:e-("buddhist"===t?.calendar?543:0),k=(e={})=>({Y:e.Y??1970,M:e.M??1,D:e.D??1,H:e.H,A:e.A,h:e.h,m:e.m??0,s:e.s??0,S:e.S??0,Z:e.Z});function _(e,t){const[n,r]="h11"===t?.hour12?[0,11]:[1,12],[s,o]="h24"===t?.hour24?[1,24]:[0,23],a=(e,t,n)=>void 0===e||e>=t&&e<=n,i=k(t?.defaultDate),c=L(e.Y,t)??i.Y,u=e.M??i.M;return e._index>0&&e._length>0&&e._index===e._length&&e._match>0&&a(c,1,9999)&&a(u,1,12)&&a(e.D??i.D,1,H(c,u))&&a(e.H??i.H,s,o)&&a(e.A??i.A,0,1)&&a(e.h??i.h,n,r)&&a(e.m??i.m,0,59)&&a(e.s??i.s,0,59)&&a(e.S??i.S,0,999)&&a(e.Z??i.Z,-913,956)}function F(e,t,n){const r=v(e,t,n);if(!_(r,n))return new Date(NaN);const s=k(n?.defaultDate),o=L(r.Y,n)??s.Y,a=r.Z??s.Z;return((e,t,n,r,s,o,a,i)=>{if(i){const c=Date.UTC(e,t-1,n,r,s,o,a);return l(i)?new Date(c):S(c,i)}return new Date(e,t-1,n,r,s,o,a)})(o,(r.M??s.M)-(o<100?22800:0),r.D??s.D,(r.H??s.H??0)%24||12*(r.A??s.A??0)+(r.h??s.h??0)%12,(r.m??s.m)+(a??0),r.s??s.s,r.S??s.S,"number"==typeof a?"UTC":n?.timeZone)}function j(e,t,n){const r=y(n)?n.zone_name:n??void 0;if(!r||l(r)){const r=new Date(e.getTime());return l(n)?(r.setUTCMonth(r.getUTCMonth()+t),r.getUTCDate()<e.getUTCDate()?(r.setUTCDate(0),r):r):(r.setMonth(r.getMonth()+t),r.getDate()<e.getDate()?(r.setDate(0),r):r)}const s=d(e,r);s.month+=t,s.timezoneOffset=0;const o=new Date(c(s));return o.getUTCDate()<s.day&&o.setUTCDate(0),S(c({...s,year:o.getUTCFullYear(),month:o.getUTCMonth()+1,day:o.getUTCDate()}),r)}const z=/^\[(.*)\]$/,P=(e,t)=>(e.F=Math.trunc(1e6*t),e),W=(e,t)=>(e.f=Math.trunc(1e3*t),P(e,1e3*Math.abs(t)%1/1e3)),N=(e,t)=>(e.S=Math.trunc(t),W(e,Math.abs(t)%1)),J=(e,t)=>(e.s=Math.trunc(t/1e3),N(e,Math.abs(t)%1e3)),I=(e,t)=>(e.m=Math.trunc(t/6e4),J(e,Math.abs(t)%6e4)),E=(e,t)=>(e.H=Math.trunc(t/36e5),I(e,Math.abs(t)%36e5)),V=(e,t,n=D)=>{const r=o(t).slice(1);return r.reduce((t,r)=>t+(t=>{if(t[0]in e){const r=e[t[0]]??0;return n.encode(`${(e=>e<0||0===e&&1/e==-1/0?"-":"")(r)}${String(Math.abs(r)).padStart(t.length,"0")}`)}return z.test(t)?t.replace(z,"$1"):t})(r),"")};class q{constructor(e){this.time=e}toNanoseconds(){return{value:1e6*this.time,format:(e,t)=>V(P({},this.time),e,t),toParts:()=>({nanoseconds:Math.trunc(1e6*this.time)+0})}}toMicroseconds(){return{value:1e3*this.time,format:(e,t)=>V(W({},this.time),e,t),toParts:()=>({microseconds:Math.trunc(1e3*this.time)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toMilliseconds(){return{value:this.time,format:(e,t)=>V(N({},this.time),e,t),toParts:()=>({milliseconds:Math.trunc(this.time)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toSeconds(){return{value:this.time/1e3,format:(e,t)=>V(J({},this.time),e,t),toParts:()=>({seconds:Math.trunc(this.time/1e3)+0,milliseconds:Math.trunc(this.time%1e3)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toMinutes(){return{value:this.time/6e4,format:(e,t)=>V(I({},this.time),e,t),toParts:()=>({minutes:Math.trunc(this.time/6e4)+0,seconds:Math.trunc(this.time%864e5%36e5%6e4/1e3)+0,milliseconds:Math.trunc(this.time%1e3)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toHours(){return{value:this.time/36e5,format:(e,t)=>V(E({},this.time),e,t),toParts:()=>({hours:Math.trunc(this.time/36e5)+0,minutes:Math.trunc(this.time%864e5%36e5/6e4)+0,seconds:Math.trunc(this.time%864e5%36e5%6e4/1e3)+0,milliseconds:Math.trunc(this.time%1e3)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toDays(){return{value:this.time/864e5,format:(e,t)=>{return V((n={},r=this.time,n.D=Math.trunc(r/864e5),E(n,Math.abs(r)%864e5)),e,t);var n,r},toParts:()=>({days:Math.trunc(this.time/864e5)+0,hours:Math.trunc(this.time%864e5/36e5)+0,minutes:Math.trunc(this.time%864e5%36e5/6e4)+0,seconds:Math.trunc(this.time%864e5%36e5%6e4/1e3)+0,milliseconds:Math.trunc(this.time%1e3)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}}exports.Duration=q,exports.addDays=function(e,t,n){const r=y(n)?n.zone_name:n??void 0;if(!r||l(r)){const r=new Date(e.getTime());return l(n)?(r.setUTCDate(r.getUTCDate()+t),r):(r.setDate(r.getDate()+t),r)}const s=d(e,r);return s.day+=t,s.timezoneOffset=0,S(c(s),r)},exports.addHours=function(e,t){return new Date(e.getTime()+36e5*t)},exports.addMilliseconds=function(e,t){return new Date(e.getTime()+t)},exports.addMinutes=function(e,t){return new Date(e.getTime()+6e4*t)},exports.addMonths=j,exports.addSeconds=function(e,t){return new Date(e.getTime()+1e3*t)},exports.addYears=function(e,t,n){return j(e,12*t,n)},exports.compile=o,exports.format=b,exports.getDaysInMonth=H,exports.getISOWeek=function(...e){const[t,n,r]=1===e.length?[e[0].getFullYear(),e[0].getMonth()+1,e[0].getDate()]:e,s=Z($(t,n-1,r));return Math.round((s.getTime()-Z($(s.getUTCFullYear(),0,4)).getTime())/864e5/7)+1},exports.getISOWeekYear=function(...e){const[t,n,r]=1===e.length?[e[0].getFullYear(),e[0].getMonth()+1,e[0].getDate()]:e;return Z($(t,n-1,r)).getUTCFullYear()},exports.isLeapYear=e=>!((e%4||!(e%100))&&e%400),exports.isSameDay=(e,t)=>e.toDateString()===t.toDateString(),exports.isValid=function(e,t,n){return _(v(e,t,n),n)},exports.parse=F,exports.preparse=v,exports.subtract=(e,t)=>new q(t.getTime()-e.getTime()),exports.transform=function(e,t,n,r,s){return b(F(e,t,r),n,s)};
|
package/dist/index.d.ts
CHANGED
|
@@ -125,6 +125,48 @@ interface FormatterOptions extends Partial<FormatterPluginOptions> {
|
|
|
125
125
|
declare function format(dateObj: Date, arg: string | CompiledObject, options?: FormatterOptions): string;
|
|
126
126
|
|
|
127
127
|
type ParserToken = 'Y' | 'M' | 'D' | 'H' | 'A' | 'h' | 'm' | 's' | 'S' | 'Z';
|
|
128
|
+
interface ParsedComponents {
|
|
129
|
+
/**
|
|
130
|
+
* Year component
|
|
131
|
+
*/
|
|
132
|
+
Y?: number;
|
|
133
|
+
/**
|
|
134
|
+
* Month component (1-12)
|
|
135
|
+
*/
|
|
136
|
+
M?: number;
|
|
137
|
+
/**
|
|
138
|
+
* Day component
|
|
139
|
+
*/
|
|
140
|
+
D?: number;
|
|
141
|
+
/**
|
|
142
|
+
* Hour in 24-hour format
|
|
143
|
+
*/
|
|
144
|
+
H?: number;
|
|
145
|
+
/**
|
|
146
|
+
* Meridiem indicator (0:AM / 1:PM)
|
|
147
|
+
*/
|
|
148
|
+
A?: number;
|
|
149
|
+
/**
|
|
150
|
+
* Hour in 12-hour format
|
|
151
|
+
*/
|
|
152
|
+
h?: number;
|
|
153
|
+
/**
|
|
154
|
+
* Minute component
|
|
155
|
+
*/
|
|
156
|
+
m?: number;
|
|
157
|
+
/**
|
|
158
|
+
* Second component
|
|
159
|
+
*/
|
|
160
|
+
s?: number;
|
|
161
|
+
/**
|
|
162
|
+
* Millisecond component
|
|
163
|
+
*/
|
|
164
|
+
S?: number;
|
|
165
|
+
/**
|
|
166
|
+
* Timezone offset in minutes
|
|
167
|
+
*/
|
|
168
|
+
Z?: number;
|
|
169
|
+
}
|
|
128
170
|
interface ParserPluginOptions {
|
|
129
171
|
/**
|
|
130
172
|
* The hour format to use for parsing.
|
|
@@ -165,6 +207,12 @@ interface ParserPluginOptions {
|
|
|
165
207
|
* This is an object that provides methods to get localized month names, day names, and meridiems.
|
|
166
208
|
*/
|
|
167
209
|
locale: Locale;
|
|
210
|
+
/**
|
|
211
|
+
* Default date components to use when certain components are missing from the input string.
|
|
212
|
+
* This allows the parser to fill in missing components with default values, which can be useful for parsing partial date strings.
|
|
213
|
+
* For example, if the input string only contains a month and day, the parser can use the default year from this object.
|
|
214
|
+
*/
|
|
215
|
+
defaultDate: ParsedComponents;
|
|
168
216
|
}
|
|
169
217
|
interface ParseResult {
|
|
170
218
|
value: number;
|
|
@@ -178,47 +226,7 @@ interface ParserOptions extends Partial<ParserPluginOptions> {
|
|
|
178
226
|
plugins?: ParserPlugin[];
|
|
179
227
|
}
|
|
180
228
|
|
|
181
|
-
interface PreparseResult {
|
|
182
|
-
/**
|
|
183
|
-
* Year component
|
|
184
|
-
*/
|
|
185
|
-
Y?: number;
|
|
186
|
-
/**
|
|
187
|
-
* Month component (1-12)
|
|
188
|
-
*/
|
|
189
|
-
M?: number;
|
|
190
|
-
/**
|
|
191
|
-
* Day component
|
|
192
|
-
*/
|
|
193
|
-
D?: number;
|
|
194
|
-
/**
|
|
195
|
-
* Hour in 24-hour format
|
|
196
|
-
*/
|
|
197
|
-
H?: number;
|
|
198
|
-
/**
|
|
199
|
-
* Meridiem indicator (0:AM/1:PM)
|
|
200
|
-
*/
|
|
201
|
-
A?: number;
|
|
202
|
-
/**
|
|
203
|
-
* Hour in 12-hour format
|
|
204
|
-
*/
|
|
205
|
-
h?: number;
|
|
206
|
-
/**
|
|
207
|
-
* Minute component
|
|
208
|
-
*/
|
|
209
|
-
m?: number;
|
|
210
|
-
/**
|
|
211
|
-
* Second component
|
|
212
|
-
*/
|
|
213
|
-
s?: number;
|
|
214
|
-
/**
|
|
215
|
-
* Millisecond component
|
|
216
|
-
*/
|
|
217
|
-
S?: number;
|
|
218
|
-
/**
|
|
219
|
-
* Timezone offset in minutes
|
|
220
|
-
*/
|
|
221
|
-
Z?: number;
|
|
229
|
+
interface PreparseResult extends ParsedComponents {
|
|
222
230
|
/**
|
|
223
231
|
* Current parsing position
|
|
224
232
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @preserve Copyright (c) KNOWLEDGECODE - MIT License */
|
|
2
|
-
const e=/\\\[/g,t=/\\\]/g,n=/\uE000/g,r=/\uE001/g,s=/\[(?:[^[\]]|\[[^[\]]*])*]|([A-Za-z])\1*|\.{3}|./g,o=o=>{const a=o.replace(e,"").replace(t,"").match(s)??[];return[o,...a.map(e=>e.replace(n,"[").replace(r,"]"))]},a=new Map,i=e=>a.get(e)??(()=>{const t=new Intl.DateTimeFormat("en-US",{hour12:!1,weekday:"short",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",fractionalSecondDigits:3,timeZone:e});return e&&a.set(e,t),t})(),c=e=>Date.UTC(e.year,e.month-(e.year<100?22801:1),e.day,e.hour,e.minute,e.second,e.fractionalSecond+6e4*e.timezoneOffset),u=(e,t)=>e.formatToParts(t).reduce((e,{type:t,value:n})=>{switch(t){case"weekday":e[t]="SunMonTueWedThuFriSat".indexOf(n)/3;break;case"hour":e[t]=+n%24;break;case"year":case"month":case"day":case"minute":case"second":case"fractionalSecond":e[t]=+n}return e},{weekday:4,year:1970,month:1,day:1,hour:0,minute:0,second:0,fractionalSecond:0,timezoneOffset:0}),l=e=>"string"==typeof e&&"UTC"===e.toUpperCase(),h=(e,t)=>{if(l(t))return{weekday:e.getUTCDay(),year:e.getUTCFullYear(),month:e.getUTCMonth()+1,day:e.getUTCDate(),hour:e.getUTCHours(),minute:e.getUTCMinutes(),second:e.getUTCSeconds(),fractionalSecond:e.getUTCMilliseconds(),timezoneOffset:0};const n=e.getTime(),r=u(i(t),n);return r.timezoneOffset=(n-c(r))/6e4,r};class d{constructor(e,t){this.parts=h(e,t),this.time=e.getTime()}getFullYear(){return this.parts.year}getMonth(){return this.parts.month-1}getDate(){return this.parts.day}getHours(){return this.parts.hour}getMinutes(){return this.parts.minute}getSeconds(){return this.parts.second}getMilliseconds(){return this.parts.fractionalSecond}getDay(){return this.parts.weekday}getTime(){return this.time}getTimezoneOffset(){return this.parts.timezoneOffset}}class m{}const g=(e,t)=>e.getFullYear()+("buddhist"===t?543:0);const M=new class extends m{YYYY(e,t){return`000${String(g(e,t.calendar))}`.slice(-4)}YY(e,t){return`0${String(g(e,t.calendar))}`.slice(-2)}Y(e,t){return String(g(e,t.calendar))}MMMM(e,t,n){return t.locale.getMonthList({style:"long",compiledObj:n})[e.getMonth()]??""}MMM(e,t,n){return t.locale.getMonthList({style:"short",compiledObj:n})[e.getMonth()]??""}MM(e){return`0${String(e.getMonth()+1)}`.slice(-2)}M(e){return String(e.getMonth()+1)}DD(e){return`0${String(e.getDate())}`.slice(-2)}D(e){return String(e.getDate())}HH(e,t){return`0${String(e.getHours()||("h24"===t.hour24?24:0))}`.slice(-2)}H(e,t){return String(e.getHours()||("h24"===t.hour24?24:0))}AA(e,t,n){return t.locale.getMeridiemList({style:"long",compiledObj:n,case:"uppercase"})[+(e.getHours()>11)]??""}A(e,t,n){return t.locale.getMeridiemList({style:"short",compiledObj:n,case:"uppercase"})[+(e.getHours()>11)]??""}aa(e,t,n){return t.locale.getMeridiemList({style:"long",compiledObj:n,case:"lowercase"})[+(e.getHours()>11)]??""}a(e,t,n){return t.locale.getMeridiemList({style:"short",compiledObj:n,case:"lowercase"})[+(e.getHours()>11)]??""}hh(e,t){return`0${String(e.getHours()%12||("h12"===t.hour12?12:0))}`.slice(-2)}h(e,t){return String(e.getHours()%12||("h12"===t.hour12?12:0))}mm(e){return`0${String(e.getMinutes())}`.slice(-2)}m(e){return String(e.getMinutes())}ss(e){return`0${String(e.getSeconds())}`.slice(-2)}s(e){return String(e.getSeconds())}SSS(e){return`00${String(e.getMilliseconds())}`.slice(-3)}SS(e){return`00${String(e.getMilliseconds())}`.slice(-3,-1)}S(e){return`00${String(e.getMilliseconds())}`.slice(-3,-2)}dddd(e,t,n){return t.locale.getDayOfWeekList({style:"long",compiledObj:n})[e.getDay()]??""}ddd(e,t,n){return t.locale.getDayOfWeekList({style:"short",compiledObj:n})[e.getDay()]??""}dd(e,t,n){return t.locale.getDayOfWeekList({style:"narrow",compiledObj:n})[e.getDay()]??""}Z(e){const t=e.getTimezoneOffset(),n=Math.abs(t);return`${t>0?"-":"+"}${`0${String(n/60|0)}`.slice(-2)}${`0${String(n%60)}`.slice(-2)}`}ZZ(e){const t=e.getTimezoneOffset(),n=Math.abs(t);return`${t>0?"-":"+"}${`0${String(n/60|0)}`.slice(-2)}:${`0${String(n%60)}`.slice(-2)}`}},f={MMMM:["January","February","March","April","May","June","July","August","September","October","November","December"],MMM:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dddd:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ddd:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dd:["Su","Mo","Tu","We","Th","Fr","Sa"],A:["AM","PM"],AA:["A.M.","P.M."],a:["am","pm"],aa:["a.m.","p.m."]};var y=new class{getLocale(){return"en"}getMonthList(e){return"long"===e.style?f.MMMM:f.MMM}getDayOfWeekList(e){return"long"===e.style?f.dddd:"short"===e.style?f.ddd:f.dd}getMeridiemList(e){return"long"===e.style?"lowercase"===e.case?f.aa:f.AA:"lowercase"===e.case?f.a:f.A}},S={encode:e=>e,decode:e=>e};const D=e=>!!e&&"object"==typeof e&&"zone_name"in e&&"gmt_offset"in e,p=(e,t)=>{const n=D(t)?t.zone_name:t;return new Date(e-((e,t)=>{const n=(()=>{try{return i(t)}catch{return}})(),r=new Set;if(n)for(let t=0;t<2;t++){const s=e-86400*t*1e3;let o=54822e3;do{const e=c(u(n,s-o))-s;if(0===e)return o;r.add(o),o+=e}while(!r.has(o));r.clear()}return NaN})(e,n))},T=/^\[(.*)\]$/;function b(e,t,n){const r=("string"==typeof t?o(t):t).slice(1),s=D(n?.timeZone)?n.timeZone.zone_name:n?.timeZone,a=s?new d(e,s):e,i={hour12:n?.hour12??"h12",hour24:n?.hour24??"h23",numeral:n?.numeral??S,calendar:n?.calendar??"gregory",timeZone:n?.timeZone,locale:n?.locale??y},c=[...n?.plugins??[],M],u=i.numeral.encode;return r.reduce((e,t)=>e+((e,t)=>{for(const n of c)if(n[e])return u(n[e](a,i,t));return T.test(e)?e.replace(T,"$1"):e})(t,r),"")}class w{}const C=(e,t,n)=>{const r=e.exec(t)?.[0]??"";return{value:+r,length:r.length,token:n}},O=(e,t,n,r)=>{const[s,o]=n.ignoreCase?(()=>{const r=n.locale.getLocale();return[e.map(e=>e.toLocaleLowerCase(r)),t.toLocaleLowerCase(r)]})():[e,t];return s.reduce((e,t,n)=>t.length>e.length&&!o.indexOf(t)?{value:n,length:t.length,token:r}:e,{value:-1,length:0,token:r})},U=new Set(["Y","M","D","H","A","h","m","s","S","Z"]),Y=e=>U.has(e);const v=new class extends w{YYYY(e){return C(/^\d{4}/,e,"Y")}Y(e){return C(/^\d{1,4}/,e,"Y")}MMMM(e,t,n){const r=t.locale.getMonthList({style:"long",compiledObj:n}),s=O(r,e,t,"M");return s.value++,s}MMM(e,t,n){const r=t.locale.getMonthList({style:"short",compiledObj:n}),s=O(r,e,t,"M");return s.value++,s}MM(e){return C(/^\d\d/,e,"M")}M(e){return C(/^\d\d?/,e,"M")}DD(e){return C(/^\d\d/,e,"D")}D(e){return C(/^\d\d?/,e,"D")}HH(e){return C(/^\d\d/,e,"H")}H(e){return C(/^\d\d?/,e,"H")}AA(e,t,n){const r=t.locale.getMeridiemList({style:"long",compiledObj:n,case:"uppercase"});return O(r,e,t,"A")}A(e,t,n){const r=t.locale.getMeridiemList({style:"short",compiledObj:n,case:"uppercase"});return O(r,e,t,"A")}aa(e,t,n){const r=t.locale.getMeridiemList({style:"long",compiledObj:n,case:"lowercase"});return O(r,e,t,"A")}a(e,t,n){const r=t.locale.getMeridiemList({style:"short",compiledObj:n,case:"lowercase"});return O(r,e,t,"A")}hh(e){return C(/^\d\d/,e,"h")}h(e){return C(/^\d\d?/,e,"h")}mm(e){return C(/^\d\d/,e,"m")}m(e){return C(/^\d\d?/,e,"m")}ss(e){return C(/^\d\d/,e,"s")}s(e){return C(/^\d\d?/,e,"s")}SSS(e){return C(/^\d{1,3}/,e,"S")}SS(e){const t=C(/^\d\d?/,e,"S");return t.value*=10,t}S(e){const t=C(/^\d/,e,"S");return t.value*=100,t}Z(e){const t=C(/^[+-][01]\d[0-5]\d/,e,"Z");return t.value=-60*(t.value/100|0)-t.value%100,t}ZZ(e){const t=/^([+-][01]\d):([0-5]\d)/.exec(e)??["","",""],n=+(t[1]+t[2]);return{value:-60*(n/100|0)-n%100,length:t[0].length,token:"Z"}}},$=/^\[(.*)\]$/;function H(e,t,n){const r=("string"==typeof t?o(t):t).slice(1),s={hour12:n?.hour12??"h12",hour24:n?.hour24??"h23",numeral:n?.numeral??S,calendar:n?.calendar??"gregory",ignoreCase:n?.ignoreCase??!1,timeZone:(D(n?.timeZone)||"string"==typeof n?.timeZone)&&n.timeZone||void 0,locale:n?.locale??y},a={_index:0,_length:0,_match:0},i=[...n?.plugins??[],v],c=(e,t)=>{for(const n of i)if(n[e])return n[e](t,s,r)};e=s.numeral.decode(e);for(const t of r){const n=e.substring(a._index),r=c(t,n);if(r){if(!r.length)break;r.token&&Y(r.token)&&(a[r.token]=r.value+0),a._index+=r.length,a._match++}else if(t===n[0]||" "===t)a._index++;else{if(!$.test(t)||n.indexOf(t.replace($,"$1"))){if("..."===t){a._index=e.length;break}break}a._index+=t.length-2}}return a._length=e.length,a}const A=e=>!((e%4||!(e%100))&&e%400),Z=(e,t)=>e.toDateString()===t.toDateString(),L=(e,t,n)=>Date.UTC(e,t-(e<100?22800:0),n);function k(...e){const[t,n]=1===e.length?[e[0].getFullYear(),e[0].getMonth()+1]:e;return new Date(L(t,n,0)).getUTCDate()}const _=e=>{const t=new Date(e);return t.setUTCDate(t.getUTCDate()+(4-(t.getUTCDay()||7))),t};function F(...e){const[t,n,r]=1===e.length?[e[0].getFullYear(),e[0].getMonth()+1,e[0].getDate()]:e;return _(L(t,n-1,r)).getUTCFullYear()}function j(...e){const[t,n,r]=1===e.length?[e[0].getFullYear(),e[0].getMonth()+1,e[0].getDate()]:e,s=_(L(t,n-1,r));return Math.round((s.getTime()-_(L(s.getUTCFullYear(),0,4)).getTime())/864e5/7)+1}function x(e,t){const n=void 0===e.Y?1970:e.Y-("buddhist"===t?.calendar?543:0),[r,s]="h11"===t?.hour12?[0,11]:[1,12],[o,a]="h24"===t?.hour24?[1,24]:[0,23],i=(e,t,n)=>void 0===e||e>=t&&e<=n;return e._index>0&&e._length>0&&e._index===e._length&&e._match>0&&i(n,1,9999)&&i(e.M,1,12)&&i(e.D,1,k(n,e.M??1))&&i(e.H,o,a)&&i(e.A,0,1)&&i(e.h,r,s)&&i(e.m,0,59)&&i(e.s,0,59)&&i(e.S,0,999)&&i(e.Z,-913,956)}function z(e,t,n){return x(H(e,t,n),n)}function P(e,t,n){const r=H(e,t,n);return x(r,n)?(r.Y=r.Y?r.Y-("buddhist"===n?.calendar?543:0):1970,r.M=(r.M??1)-(r.Y<100?22801:1),r.D??=1,r.H=(r.H??0)%24||12*(r.A??0)+(r.h??0)%12,r.m??=0,r.s??=0,r.S??=0,l(n?.timeZone)||"Z"in r?new Date(Date.UTC(r.Y,r.M,r.D,r.H,r.m+(r.Z??0),r.s,r.S)):n?.timeZone?p(Date.UTC(r.Y,r.M,r.D,r.H,r.m,r.s,r.S),n.timeZone):new Date(r.Y,r.M,r.D,r.H,r.m,r.s,r.S)):new Date(NaN)}function W(e,t,n,r,s){return b(P(e,t,r),n,s)}function N(e,t,n){const r=D(n)?n.zone_name:n??void 0;if(!r||l(r)){const r=new Date(e.getTime());return l(n)?(r.setUTCMonth(r.getUTCMonth()+t),r.getUTCDate()<e.getUTCDate()?(r.setUTCDate(0),r):r):(r.setMonth(r.getMonth()+t),r.getDate()<e.getDate()?(r.setDate(0),r):r)}const s=h(e,r);s.month+=t,s.timezoneOffset=0;const o=new Date(c(s));return o.getUTCDate()<s.day&&o.setUTCDate(0),p(c({...s,year:o.getUTCFullYear(),month:o.getUTCMonth()+1,day:o.getUTCDate()}),r)}function J(e,t,n){return N(e,12*t,n)}function E(e,t,n){const r=D(n)?n.zone_name:n??void 0;if(!r||l(r)){const r=new Date(e.getTime());return l(n)?(r.setUTCDate(r.getUTCDate()+t),r):(r.setDate(r.getDate()+t),r)}const s=h(e,r);return s.day+=t,s.timezoneOffset=0,p(c(s),r)}function I(e,t){return new Date(e.getTime()+36e5*t)}function q(e,t){return new Date(e.getTime()+6e4*t)}function B(e,t){return new Date(e.getTime()+1e3*t)}function G(e,t){return new Date(e.getTime()+t)}const K=/^\[(.*)\]$/,Q=(e,t)=>(e.F=Math.trunc(1e6*t),e),R=(e,t)=>(e.f=Math.trunc(1e3*t),Q(e,1e3*Math.abs(t)%1/1e3)),V=(e,t)=>(e.S=Math.trunc(t),R(e,Math.abs(t)%1)),X=(e,t)=>(e.s=Math.trunc(t/1e3),V(e,Math.abs(t)%1e3)),ee=(e,t)=>(e.m=Math.trunc(t/6e4),X(e,Math.abs(t)%6e4)),te=(e,t)=>(e.H=Math.trunc(t/36e5),ee(e,Math.abs(t)%36e5)),ne=(e,t,n=S)=>{const r=o(t).slice(1);return r.reduce((t,r)=>t+(t=>{if(t[0]in e){const r=e[t[0]]??0;return n.encode(`${(e=>e<0||0===e&&1/e==-1/0?"-":"")(r)}${String(Math.abs(r)).padStart(t.length,"0")}`)}return K.test(t)?t.replace(K,"$1"):t})(r),"")};class re{constructor(e){this.time=e}toNanoseconds(){return{value:1e6*this.time,format:(e,t)=>ne(Q({},this.time),e,t),toParts:()=>({nanoseconds:Math.trunc(1e6*this.time)+0})}}toMicroseconds(){return{value:1e3*this.time,format:(e,t)=>ne(R({},this.time),e,t),toParts:()=>({microseconds:Math.trunc(1e3*this.time)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toMilliseconds(){return{value:this.time,format:(e,t)=>ne(V({},this.time),e,t),toParts:()=>({milliseconds:Math.trunc(this.time)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toSeconds(){return{value:this.time/1e3,format:(e,t)=>ne(X({},this.time),e,t),toParts:()=>({seconds:Math.trunc(this.time/1e3)+0,milliseconds:Math.trunc(this.time%1e3)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toMinutes(){return{value:this.time/6e4,format:(e,t)=>ne(ee({},this.time),e,t),toParts:()=>({minutes:Math.trunc(this.time/6e4)+0,seconds:Math.trunc(this.time%864e5%36e5%6e4/1e3)+0,milliseconds:Math.trunc(this.time%1e3)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toHours(){return{value:this.time/36e5,format:(e,t)=>ne(te({},this.time),e,t),toParts:()=>({hours:Math.trunc(this.time/36e5)+0,minutes:Math.trunc(this.time%864e5%36e5/6e4)+0,seconds:Math.trunc(this.time%864e5%36e5%6e4/1e3)+0,milliseconds:Math.trunc(this.time%1e3)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toDays(){return{value:this.time/864e5,format:(e,t)=>{return ne((n={},r=this.time,n.D=Math.trunc(r/864e5),te(n,Math.abs(r)%864e5)),e,t);var n,r},toParts:()=>({days:Math.trunc(this.time/864e5)+0,hours:Math.trunc(this.time%864e5/36e5)+0,minutes:Math.trunc(this.time%864e5%36e5/6e4)+0,seconds:Math.trunc(this.time%864e5%36e5%6e4/1e3)+0,milliseconds:Math.trunc(this.time%1e3)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}}const se=(e,t)=>new re(t.getTime()-e.getTime());export{re as Duration,E as addDays,I as addHours,G as addMilliseconds,q as addMinutes,N as addMonths,B as addSeconds,J as addYears,o as compile,b as format,k as getDaysInMonth,j as getISOWeek,F as getISOWeekYear,A as isLeapYear,Z as isSameDay,z as isValid,P as parse,H as preparse,se as subtract,W as transform};
|
|
2
|
+
const e=/\\\[/g,t=/\\\]/g,n=/\uE000/g,r=/\uE001/g,s=/\[(?:[^[\]]|\[[^[\]]*])*]|([A-Za-z])\1*|\.{3}|./g,o=o=>{const a=o.replace(e,"").replace(t,"").match(s)??[];return[o,...a.map(e=>e.replace(n,"[").replace(r,"]"))]},a=new Map,i=e=>a.get(e)??(()=>{const t=new Intl.DateTimeFormat("en-US",{hour12:!1,weekday:"short",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",fractionalSecondDigits:3,timeZone:e});return e&&a.set(e,t),t})(),c=e=>Date.UTC(e.year,e.month-(e.year<100?22801:1),e.day,e.hour,e.minute,e.second,e.fractionalSecond+6e4*e.timezoneOffset),u=(e,t)=>e.formatToParts(t).reduce((e,{type:t,value:n})=>{switch(t){case"weekday":e[t]="SunMonTueWedThuFriSat".indexOf(n)/3;break;case"hour":e[t]=+n%24;break;case"year":case"month":case"day":case"minute":case"second":case"fractionalSecond":e[t]=+n}return e},{weekday:4,year:1970,month:1,day:1,hour:0,minute:0,second:0,fractionalSecond:0,timezoneOffset:0}),l=e=>"string"==typeof e&&"UTC"===e.toUpperCase(),h=(e,t)=>{if(l(t))return{weekday:e.getUTCDay(),year:e.getUTCFullYear(),month:e.getUTCMonth()+1,day:e.getUTCDate(),hour:e.getUTCHours(),minute:e.getUTCMinutes(),second:e.getUTCSeconds(),fractionalSecond:e.getUTCMilliseconds(),timezoneOffset:0};const n=e.getTime(),r=u(i(t),n);return r.timezoneOffset=(n-c(r))/6e4,r};class d{constructor(e,t){this.parts=h(e,t),this.time=e.getTime()}getFullYear(){return this.parts.year}getMonth(){return this.parts.month-1}getDate(){return this.parts.day}getHours(){return this.parts.hour}getMinutes(){return this.parts.minute}getSeconds(){return this.parts.second}getMilliseconds(){return this.parts.fractionalSecond}getDay(){return this.parts.weekday}getTime(){return this.time}getTimezoneOffset(){return this.parts.timezoneOffset}}class m{}const g=(e,t)=>e.getFullYear()+("buddhist"===t?543:0);const M=new class extends m{YYYY(e,t){return`000${String(g(e,t.calendar))}`.slice(-4)}YY(e,t){return`0${String(g(e,t.calendar))}`.slice(-2)}Y(e,t){return String(g(e,t.calendar))}MMMM(e,t,n){return t.locale.getMonthList({style:"long",compiledObj:n})[e.getMonth()]??""}MMM(e,t,n){return t.locale.getMonthList({style:"short",compiledObj:n})[e.getMonth()]??""}MM(e){return`0${String(e.getMonth()+1)}`.slice(-2)}M(e){return String(e.getMonth()+1)}DD(e){return`0${String(e.getDate())}`.slice(-2)}D(e){return String(e.getDate())}HH(e,t){return`0${String(e.getHours()||("h24"===t.hour24?24:0))}`.slice(-2)}H(e,t){return String(e.getHours()||("h24"===t.hour24?24:0))}AA(e,t,n){return t.locale.getMeridiemList({style:"long",compiledObj:n,case:"uppercase"})[+(e.getHours()>11)]??""}A(e,t,n){return t.locale.getMeridiemList({style:"short",compiledObj:n,case:"uppercase"})[+(e.getHours()>11)]??""}aa(e,t,n){return t.locale.getMeridiemList({style:"long",compiledObj:n,case:"lowercase"})[+(e.getHours()>11)]??""}a(e,t,n){return t.locale.getMeridiemList({style:"short",compiledObj:n,case:"lowercase"})[+(e.getHours()>11)]??""}hh(e,t){return`0${String(e.getHours()%12||("h12"===t.hour12?12:0))}`.slice(-2)}h(e,t){return String(e.getHours()%12||("h12"===t.hour12?12:0))}mm(e){return`0${String(e.getMinutes())}`.slice(-2)}m(e){return String(e.getMinutes())}ss(e){return`0${String(e.getSeconds())}`.slice(-2)}s(e){return String(e.getSeconds())}SSS(e){return`00${String(e.getMilliseconds())}`.slice(-3)}SS(e){return`00${String(e.getMilliseconds())}`.slice(-3,-1)}S(e){return`00${String(e.getMilliseconds())}`.slice(-3,-2)}dddd(e,t,n){return t.locale.getDayOfWeekList({style:"long",compiledObj:n})[e.getDay()]??""}ddd(e,t,n){return t.locale.getDayOfWeekList({style:"short",compiledObj:n})[e.getDay()]??""}dd(e,t,n){return t.locale.getDayOfWeekList({style:"narrow",compiledObj:n})[e.getDay()]??""}Z(e){const t=e.getTimezoneOffset(),n=Math.abs(t);return`${t>0?"-":"+"}${`0${String(n/60|0)}`.slice(-2)}${`0${String(n%60)}`.slice(-2)}`}ZZ(e){const t=e.getTimezoneOffset(),n=Math.abs(t);return`${t>0?"-":"+"}${`0${String(n/60|0)}`.slice(-2)}:${`0${String(n%60)}`.slice(-2)}`}},f={MMMM:["January","February","March","April","May","June","July","August","September","October","November","December"],MMM:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dddd:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ddd:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dd:["Su","Mo","Tu","We","Th","Fr","Sa"],A:["AM","PM"],AA:["A.M.","P.M."],a:["am","pm"],aa:["a.m.","p.m."]};var y=new class{getLocale(){return"en"}getMonthList(e){return"long"===e.style?f.MMMM:f.MMM}getDayOfWeekList(e){return"long"===e.style?f.dddd:"short"===e.style?f.ddd:f.dd}getMeridiemList(e){return"long"===e.style?"lowercase"===e.case?f.aa:f.AA:"lowercase"===e.case?f.a:f.A}},D={encode:e=>e,decode:e=>e};const S=e=>!!e&&"object"==typeof e&&"zone_name"in e&&"gmt_offset"in e,p=(e,t)=>{const n=S(t)?t.zone_name:t;return new Date(e-((e,t)=>{const n=(()=>{try{return i(t)}catch{return}})(),r=new Set;if(n)for(let t=0;t<2;t++){const s=e-86400*t*1e3;let o=54822e3;do{const e=c(u(n,s-o))-s;if(0===e)return o;r.add(o),o+=e}while(!r.has(o));r.clear()}return NaN})(e,n))},T=/^\[(.*)\]$/;function b(e,t,n){const r=("string"==typeof t?o(t):t).slice(1),s=S(n?.timeZone)?n.timeZone.zone_name:n?.timeZone,a=s?new d(e,s):e,i={hour12:n?.hour12??"h12",hour24:n?.hour24??"h23",numeral:n?.numeral??D,calendar:n?.calendar??"gregory",timeZone:n?.timeZone,locale:n?.locale??y},c=[...n?.plugins??[],M],u=i.numeral.encode;return r.reduce((e,t)=>e+((e,t)=>{for(const n of c)if(n[e])return u(n[e](a,i,t));return T.test(e)?e.replace(T,"$1"):e})(t,r),"")}class w{}const C=(e,t,n)=>{const r=e.exec(t)?.[0]??"";return{value:+r,length:r.length,token:n}},O=(e,t,n,r)=>{const[s,o]=n.ignoreCase?(()=>{const r=n.locale.getLocale();return[e.map(e=>e.toLocaleLowerCase(r)),t.toLocaleLowerCase(r)]})():[e,t];return s.reduce((e,t,n)=>t.length>e.length&&!o.indexOf(t)?{value:n,length:t.length,token:r}:e,{value:-1,length:0,token:r})},U=new Set(["Y","M","D","H","A","h","m","s","S","Z"]),A=e=>U.has(e);const Y=new class extends w{YYYY(e){return C(/^\d{4}/,e,"Y")}Y(e){return C(/^\d{1,4}/,e,"Y")}MMMM(e,t,n){const r=t.locale.getMonthList({style:"long",compiledObj:n}),s=O(r,e,t,"M");return s.value++,s}MMM(e,t,n){const r=t.locale.getMonthList({style:"short",compiledObj:n}),s=O(r,e,t,"M");return s.value++,s}MM(e){return C(/^\d\d/,e,"M")}M(e){return C(/^\d\d?/,e,"M")}DD(e){return C(/^\d\d/,e,"D")}D(e){return C(/^\d\d?/,e,"D")}HH(e){return C(/^\d\d/,e,"H")}H(e){return C(/^\d\d?/,e,"H")}AA(e,t,n){const r=t.locale.getMeridiemList({style:"long",compiledObj:n,case:"uppercase"});return O(r,e,t,"A")}A(e,t,n){const r=t.locale.getMeridiemList({style:"short",compiledObj:n,case:"uppercase"});return O(r,e,t,"A")}aa(e,t,n){const r=t.locale.getMeridiemList({style:"long",compiledObj:n,case:"lowercase"});return O(r,e,t,"A")}a(e,t,n){const r=t.locale.getMeridiemList({style:"short",compiledObj:n,case:"lowercase"});return O(r,e,t,"A")}hh(e){return C(/^\d\d/,e,"h")}h(e){return C(/^\d\d?/,e,"h")}mm(e){return C(/^\d\d/,e,"m")}m(e){return C(/^\d\d?/,e,"m")}ss(e){return C(/^\d\d/,e,"s")}s(e){return C(/^\d\d?/,e,"s")}SSS(e){return C(/^\d{1,3}/,e,"S")}SS(e){const t=C(/^\d\d?/,e,"S");return t.value*=10,t}S(e){const t=C(/^\d/,e,"S");return t.value*=100,t}Z(e){const t=C(/^[+-][01]\d[0-5]\d/,e,"Z");return t.value=-60*(t.value/100|0)-t.value%100,t}ZZ(e){const t=/^([+-][01]\d):([0-5]\d)/.exec(e)??["","",""],n=+(t[1]+t[2]);return{value:-60*(n/100|0)-n%100,length:t[0].length,token:"Z"}}},v=/^\[(.*)\]$/;function $(e,t,n){const r=("string"==typeof t?o(t):t).slice(1),s={hour12:n?.hour12??"h12",hour24:n?.hour24??"h23",numeral:n?.numeral??D,calendar:n?.calendar??"gregory",ignoreCase:n?.ignoreCase??!1,timeZone:(S(n?.timeZone)||"string"==typeof n?.timeZone)&&n.timeZone||void 0,locale:n?.locale??y,defaultDate:n?.defaultDate??{}},a={_index:0,_length:0,_match:0},i=[...n?.plugins??[],Y],c=(e,t)=>{for(const n of i)if(n[e])return n[e](t,s,r)};e=s.numeral.decode(e);for(const t of r){const n=e.substring(a._index),r=c(t,n);if(r){if(!r.length)break;r.token&&A(r.token)&&(a[r.token]=r.value+0),a._index+=r.length,a._match++}else if(t===n[0]||" "===t)a._index++;else{if(!v.test(t)||n.indexOf(t.replace(v,"$1"))){if("..."===t){a._index=e.length;break}break}a._index+=t.length-2}}return a._length=e.length,a}const H=e=>!((e%4||!(e%100))&&e%400),Z=(e,t)=>e.toDateString()===t.toDateString(),L=(e,t,n)=>Date.UTC(e,t-(e<100?22800:0),n);function k(...e){const[t,n]=1===e.length?[e[0].getFullYear(),e[0].getMonth()+1]:e;return new Date(L(t,n,0)).getUTCDate()}const _=e=>{const t=new Date(e);return t.setUTCDate(t.getUTCDate()+(4-(t.getUTCDay()||7))),t};function F(...e){const[t,n,r]=1===e.length?[e[0].getFullYear(),e[0].getMonth()+1,e[0].getDate()]:e;return _(L(t,n-1,r)).getUTCFullYear()}function j(...e){const[t,n,r]=1===e.length?[e[0].getFullYear(),e[0].getMonth()+1,e[0].getDate()]:e,s=_(L(t,n-1,r));return Math.round((s.getTime()-_(L(s.getUTCFullYear(),0,4)).getTime())/864e5/7)+1}const x=(e,t)=>void 0===e?e:e-("buddhist"===t?.calendar?543:0),z=(e={})=>({Y:e.Y??1970,M:e.M??1,D:e.D??1,H:e.H,A:e.A,h:e.h,m:e.m??0,s:e.s??0,S:e.S??0,Z:e.Z});function P(e,t){const[n,r]="h11"===t?.hour12?[0,11]:[1,12],[s,o]="h24"===t?.hour24?[1,24]:[0,23],a=(e,t,n)=>void 0===e||e>=t&&e<=n,i=z(t?.defaultDate),c=x(e.Y,t)??i.Y,u=e.M??i.M;return e._index>0&&e._length>0&&e._index===e._length&&e._match>0&&a(c,1,9999)&&a(u,1,12)&&a(e.D??i.D,1,k(c,u))&&a(e.H??i.H,s,o)&&a(e.A??i.A,0,1)&&a(e.h??i.h,n,r)&&a(e.m??i.m,0,59)&&a(e.s??i.s,0,59)&&a(e.S??i.S,0,999)&&a(e.Z??i.Z,-913,956)}function W(e,t,n){return P($(e,t,n),n)}function N(e,t,n){const r=$(e,t,n);if(!P(r,n))return new Date(NaN);const s=z(n?.defaultDate),o=x(r.Y,n)??s.Y,a=r.Z??s.Z;return((e,t,n,r,s,o,a,i)=>{if(i){const c=Date.UTC(e,t-1,n,r,s,o,a);return l(i)?new Date(c):p(c,i)}return new Date(e,t-1,n,r,s,o,a)})(o,(r.M??s.M)-(o<100?22800:0),r.D??s.D,(r.H??s.H??0)%24||12*(r.A??s.A??0)+(r.h??s.h??0)%12,(r.m??s.m)+(a??0),r.s??s.s,r.S??s.S,"number"==typeof a?"UTC":n?.timeZone)}function J(e,t,n,r,s){return b(N(e,t,r),n,s)}function E(e,t,n){const r=S(n)?n.zone_name:n??void 0;if(!r||l(r)){const r=new Date(e.getTime());return l(n)?(r.setUTCMonth(r.getUTCMonth()+t),r.getUTCDate()<e.getUTCDate()?(r.setUTCDate(0),r):r):(r.setMonth(r.getMonth()+t),r.getDate()<e.getDate()?(r.setDate(0),r):r)}const s=h(e,r);s.month+=t,s.timezoneOffset=0;const o=new Date(c(s));return o.getUTCDate()<s.day&&o.setUTCDate(0),p(c({...s,year:o.getUTCFullYear(),month:o.getUTCMonth()+1,day:o.getUTCDate()}),r)}function I(e,t,n){return E(e,12*t,n)}function q(e,t,n){const r=S(n)?n.zone_name:n??void 0;if(!r||l(r)){const r=new Date(e.getTime());return l(n)?(r.setUTCDate(r.getUTCDate()+t),r):(r.setDate(r.getDate()+t),r)}const s=h(e,r);return s.day+=t,s.timezoneOffset=0,p(c(s),r)}function B(e,t){return new Date(e.getTime()+36e5*t)}function G(e,t){return new Date(e.getTime()+6e4*t)}function K(e,t){return new Date(e.getTime()+1e3*t)}function Q(e,t){return new Date(e.getTime()+t)}const R=/^\[(.*)\]$/,V=(e,t)=>(e.F=Math.trunc(1e6*t),e),X=(e,t)=>(e.f=Math.trunc(1e3*t),V(e,1e3*Math.abs(t)%1/1e3)),ee=(e,t)=>(e.S=Math.trunc(t),X(e,Math.abs(t)%1)),te=(e,t)=>(e.s=Math.trunc(t/1e3),ee(e,Math.abs(t)%1e3)),ne=(e,t)=>(e.m=Math.trunc(t/6e4),te(e,Math.abs(t)%6e4)),re=(e,t)=>(e.H=Math.trunc(t/36e5),ne(e,Math.abs(t)%36e5)),se=(e,t,n=D)=>{const r=o(t).slice(1);return r.reduce((t,r)=>t+(t=>{if(t[0]in e){const r=e[t[0]]??0;return n.encode(`${(e=>e<0||0===e&&1/e==-1/0?"-":"")(r)}${String(Math.abs(r)).padStart(t.length,"0")}`)}return R.test(t)?t.replace(R,"$1"):t})(r),"")};class oe{constructor(e){this.time=e}toNanoseconds(){return{value:1e6*this.time,format:(e,t)=>se(V({},this.time),e,t),toParts:()=>({nanoseconds:Math.trunc(1e6*this.time)+0})}}toMicroseconds(){return{value:1e3*this.time,format:(e,t)=>se(X({},this.time),e,t),toParts:()=>({microseconds:Math.trunc(1e3*this.time)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toMilliseconds(){return{value:this.time,format:(e,t)=>se(ee({},this.time),e,t),toParts:()=>({milliseconds:Math.trunc(this.time)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toSeconds(){return{value:this.time/1e3,format:(e,t)=>se(te({},this.time),e,t),toParts:()=>({seconds:Math.trunc(this.time/1e3)+0,milliseconds:Math.trunc(this.time%1e3)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toMinutes(){return{value:this.time/6e4,format:(e,t)=>se(ne({},this.time),e,t),toParts:()=>({minutes:Math.trunc(this.time/6e4)+0,seconds:Math.trunc(this.time%864e5%36e5%6e4/1e3)+0,milliseconds:Math.trunc(this.time%1e3)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toHours(){return{value:this.time/36e5,format:(e,t)=>se(re({},this.time),e,t),toParts:()=>({hours:Math.trunc(this.time/36e5)+0,minutes:Math.trunc(this.time%864e5%36e5/6e4)+0,seconds:Math.trunc(this.time%864e5%36e5%6e4/1e3)+0,milliseconds:Math.trunc(this.time%1e3)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}toDays(){return{value:this.time/864e5,format:(e,t)=>{return se((n={},r=this.time,n.D=Math.trunc(r/864e5),re(n,Math.abs(r)%864e5)),e,t);var n,r},toParts:()=>({days:Math.trunc(this.time/864e5)+0,hours:Math.trunc(this.time%864e5/36e5)+0,minutes:Math.trunc(this.time%864e5%36e5/6e4)+0,seconds:Math.trunc(this.time%864e5%36e5%6e4/1e3)+0,milliseconds:Math.trunc(this.time%1e3)+0,microseconds:Math.trunc(1e3*this.time%1e3)+0,nanoseconds:Math.trunc(1e6*this.time%1e3)+0})}}}const ae=(e,t)=>new oe(t.getTime()-e.getTime());export{oe as Duration,q as addDays,B as addHours,Q as addMilliseconds,G as addMinutes,E as addMonths,K as addSeconds,I as addYears,o as compile,b as format,k as getDaysInMonth,j as getISOWeek,F as getISOWeekYear,H as isLeapYear,Z as isSameDay,W as isValid,N as parse,$ as preparse,ae as subtract,J as transform};
|
package/dist/plugin.d.ts
CHANGED
|
@@ -106,6 +106,48 @@ declare abstract class FormatterPlugin {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
type ParserToken = 'Y' | 'M' | 'D' | 'H' | 'A' | 'h' | 'm' | 's' | 'S' | 'Z';
|
|
109
|
+
interface ParsedComponents {
|
|
110
|
+
/**
|
|
111
|
+
* Year component
|
|
112
|
+
*/
|
|
113
|
+
Y?: number;
|
|
114
|
+
/**
|
|
115
|
+
* Month component (1-12)
|
|
116
|
+
*/
|
|
117
|
+
M?: number;
|
|
118
|
+
/**
|
|
119
|
+
* Day component
|
|
120
|
+
*/
|
|
121
|
+
D?: number;
|
|
122
|
+
/**
|
|
123
|
+
* Hour in 24-hour format
|
|
124
|
+
*/
|
|
125
|
+
H?: number;
|
|
126
|
+
/**
|
|
127
|
+
* Meridiem indicator (0:AM / 1:PM)
|
|
128
|
+
*/
|
|
129
|
+
A?: number;
|
|
130
|
+
/**
|
|
131
|
+
* Hour in 12-hour format
|
|
132
|
+
*/
|
|
133
|
+
h?: number;
|
|
134
|
+
/**
|
|
135
|
+
* Minute component
|
|
136
|
+
*/
|
|
137
|
+
m?: number;
|
|
138
|
+
/**
|
|
139
|
+
* Second component
|
|
140
|
+
*/
|
|
141
|
+
s?: number;
|
|
142
|
+
/**
|
|
143
|
+
* Millisecond component
|
|
144
|
+
*/
|
|
145
|
+
S?: number;
|
|
146
|
+
/**
|
|
147
|
+
* Timezone offset in minutes
|
|
148
|
+
*/
|
|
149
|
+
Z?: number;
|
|
150
|
+
}
|
|
109
151
|
interface ParserPluginOptions {
|
|
110
152
|
/**
|
|
111
153
|
* The hour format to use for parsing.
|
|
@@ -146,6 +188,12 @@ interface ParserPluginOptions {
|
|
|
146
188
|
* This is an object that provides methods to get localized month names, day names, and meridiems.
|
|
147
189
|
*/
|
|
148
190
|
locale: Locale;
|
|
191
|
+
/**
|
|
192
|
+
* Default date components to use when certain components are missing from the input string.
|
|
193
|
+
* This allows the parser to fill in missing components with default values, which can be useful for parsing partial date strings.
|
|
194
|
+
* For example, if the input string only contains a month and day, the parser can use the default year from this object.
|
|
195
|
+
*/
|
|
196
|
+
defaultDate: ParsedComponents;
|
|
149
197
|
}
|
|
150
198
|
interface ParseResult {
|
|
151
199
|
value: number;
|
|
@@ -24,6 +24,48 @@ interface TimeZone {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
type ParserToken = 'Y' | 'M' | 'D' | 'H' | 'A' | 'h' | 'm' | 's' | 'S' | 'Z';
|
|
27
|
+
interface ParsedComponents {
|
|
28
|
+
/**
|
|
29
|
+
* Year component
|
|
30
|
+
*/
|
|
31
|
+
Y?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Month component (1-12)
|
|
34
|
+
*/
|
|
35
|
+
M?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Day component
|
|
38
|
+
*/
|
|
39
|
+
D?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Hour in 24-hour format
|
|
42
|
+
*/
|
|
43
|
+
H?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Meridiem indicator (0:AM / 1:PM)
|
|
46
|
+
*/
|
|
47
|
+
A?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Hour in 12-hour format
|
|
50
|
+
*/
|
|
51
|
+
h?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Minute component
|
|
54
|
+
*/
|
|
55
|
+
m?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Second component
|
|
58
|
+
*/
|
|
59
|
+
s?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Millisecond component
|
|
62
|
+
*/
|
|
63
|
+
S?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Timezone offset in minutes
|
|
66
|
+
*/
|
|
67
|
+
Z?: number;
|
|
68
|
+
}
|
|
27
69
|
interface ParserPluginOptions {
|
|
28
70
|
/**
|
|
29
71
|
* The hour format to use for parsing.
|
|
@@ -64,6 +106,12 @@ interface ParserPluginOptions {
|
|
|
64
106
|
* This is an object that provides methods to get localized month names, day names, and meridiems.
|
|
65
107
|
*/
|
|
66
108
|
locale: Locale;
|
|
109
|
+
/**
|
|
110
|
+
* Default date components to use when certain components are missing from the input string.
|
|
111
|
+
* This allows the parser to fill in missing components with default values, which can be useful for parsing partial date strings.
|
|
112
|
+
* For example, if the input string only contains a month and day, the parser can use the default year from this object.
|
|
113
|
+
*/
|
|
114
|
+
defaultDate: ParsedComponents;
|
|
67
115
|
}
|
|
68
116
|
interface ParseResult {
|
|
69
117
|
value: number;
|
|
@@ -24,6 +24,48 @@ interface TimeZone {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
type ParserToken = 'Y' | 'M' | 'D' | 'H' | 'A' | 'h' | 'm' | 's' | 'S' | 'Z';
|
|
27
|
+
interface ParsedComponents {
|
|
28
|
+
/**
|
|
29
|
+
* Year component
|
|
30
|
+
*/
|
|
31
|
+
Y?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Month component (1-12)
|
|
34
|
+
*/
|
|
35
|
+
M?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Day component
|
|
38
|
+
*/
|
|
39
|
+
D?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Hour in 24-hour format
|
|
42
|
+
*/
|
|
43
|
+
H?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Meridiem indicator (0:AM / 1:PM)
|
|
46
|
+
*/
|
|
47
|
+
A?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Hour in 12-hour format
|
|
50
|
+
*/
|
|
51
|
+
h?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Minute component
|
|
54
|
+
*/
|
|
55
|
+
m?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Second component
|
|
58
|
+
*/
|
|
59
|
+
s?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Millisecond component
|
|
62
|
+
*/
|
|
63
|
+
S?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Timezone offset in minutes
|
|
66
|
+
*/
|
|
67
|
+
Z?: number;
|
|
68
|
+
}
|
|
27
69
|
interface ParserPluginOptions {
|
|
28
70
|
/**
|
|
29
71
|
* The hour format to use for parsing.
|
|
@@ -64,6 +106,12 @@ interface ParserPluginOptions {
|
|
|
64
106
|
* This is an object that provides methods to get localized month names, day names, and meridiems.
|
|
65
107
|
*/
|
|
66
108
|
locale: Locale;
|
|
109
|
+
/**
|
|
110
|
+
* Default date components to use when certain components are missing from the input string.
|
|
111
|
+
* This allows the parser to fill in missing components with default values, which can be useful for parsing partial date strings.
|
|
112
|
+
* For example, if the input string only contains a month and day, the parser can use the default year from this object.
|
|
113
|
+
*/
|
|
114
|
+
defaultDate: ParsedComponents;
|
|
67
115
|
}
|
|
68
116
|
interface ParseResult {
|
|
69
117
|
value: number;
|
|
@@ -24,6 +24,48 @@ interface TimeZone {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
type ParserToken = 'Y' | 'M' | 'D' | 'H' | 'A' | 'h' | 'm' | 's' | 'S' | 'Z';
|
|
27
|
+
interface ParsedComponents {
|
|
28
|
+
/**
|
|
29
|
+
* Year component
|
|
30
|
+
*/
|
|
31
|
+
Y?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Month component (1-12)
|
|
34
|
+
*/
|
|
35
|
+
M?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Day component
|
|
38
|
+
*/
|
|
39
|
+
D?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Hour in 24-hour format
|
|
42
|
+
*/
|
|
43
|
+
H?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Meridiem indicator (0:AM / 1:PM)
|
|
46
|
+
*/
|
|
47
|
+
A?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Hour in 12-hour format
|
|
50
|
+
*/
|
|
51
|
+
h?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Minute component
|
|
54
|
+
*/
|
|
55
|
+
m?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Second component
|
|
58
|
+
*/
|
|
59
|
+
s?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Millisecond component
|
|
62
|
+
*/
|
|
63
|
+
S?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Timezone offset in minutes
|
|
66
|
+
*/
|
|
67
|
+
Z?: number;
|
|
68
|
+
}
|
|
27
69
|
interface ParserPluginOptions {
|
|
28
70
|
/**
|
|
29
71
|
* The hour format to use for parsing.
|
|
@@ -64,6 +106,12 @@ interface ParserPluginOptions {
|
|
|
64
106
|
* This is an object that provides methods to get localized month names, day names, and meridiems.
|
|
65
107
|
*/
|
|
66
108
|
locale: Locale;
|
|
109
|
+
/**
|
|
110
|
+
* Default date components to use when certain components are missing from the input string.
|
|
111
|
+
* This allows the parser to fill in missing components with default values, which can be useful for parsing partial date strings.
|
|
112
|
+
* For example, if the input string only contains a month and day, the parser can use the default year from this object.
|
|
113
|
+
*/
|
|
114
|
+
defaultDate: ParsedComponents;
|
|
67
115
|
}
|
|
68
116
|
interface ParseResult {
|
|
69
117
|
value: number;
|
|
@@ -106,6 +106,48 @@ declare abstract class FormatterPlugin {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
type ParserToken = 'Y' | 'M' | 'D' | 'H' | 'A' | 'h' | 'm' | 's' | 'S' | 'Z';
|
|
109
|
+
interface ParsedComponents {
|
|
110
|
+
/**
|
|
111
|
+
* Year component
|
|
112
|
+
*/
|
|
113
|
+
Y?: number;
|
|
114
|
+
/**
|
|
115
|
+
* Month component (1-12)
|
|
116
|
+
*/
|
|
117
|
+
M?: number;
|
|
118
|
+
/**
|
|
119
|
+
* Day component
|
|
120
|
+
*/
|
|
121
|
+
D?: number;
|
|
122
|
+
/**
|
|
123
|
+
* Hour in 24-hour format
|
|
124
|
+
*/
|
|
125
|
+
H?: number;
|
|
126
|
+
/**
|
|
127
|
+
* Meridiem indicator (0:AM / 1:PM)
|
|
128
|
+
*/
|
|
129
|
+
A?: number;
|
|
130
|
+
/**
|
|
131
|
+
* Hour in 12-hour format
|
|
132
|
+
*/
|
|
133
|
+
h?: number;
|
|
134
|
+
/**
|
|
135
|
+
* Minute component
|
|
136
|
+
*/
|
|
137
|
+
m?: number;
|
|
138
|
+
/**
|
|
139
|
+
* Second component
|
|
140
|
+
*/
|
|
141
|
+
s?: number;
|
|
142
|
+
/**
|
|
143
|
+
* Millisecond component
|
|
144
|
+
*/
|
|
145
|
+
S?: number;
|
|
146
|
+
/**
|
|
147
|
+
* Timezone offset in minutes
|
|
148
|
+
*/
|
|
149
|
+
Z?: number;
|
|
150
|
+
}
|
|
109
151
|
interface ParserPluginOptions {
|
|
110
152
|
/**
|
|
111
153
|
* The hour format to use for parsing.
|
|
@@ -146,6 +188,12 @@ interface ParserPluginOptions {
|
|
|
146
188
|
* This is an object that provides methods to get localized month names, day names, and meridiems.
|
|
147
189
|
*/
|
|
148
190
|
locale: Locale;
|
|
191
|
+
/**
|
|
192
|
+
* Default date components to use when certain components are missing from the input string.
|
|
193
|
+
* This allows the parser to fill in missing components with default values, which can be useful for parsing partial date strings.
|
|
194
|
+
* For example, if the input string only contains a month and day, the parser can use the default year from this object.
|
|
195
|
+
*/
|
|
196
|
+
defaultDate: ParsedComponents;
|
|
149
197
|
}
|
|
150
198
|
interface ParseResult {
|
|
151
199
|
value: number;
|
|
@@ -24,6 +24,48 @@ interface TimeZone {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
type ParserToken = 'Y' | 'M' | 'D' | 'H' | 'A' | 'h' | 'm' | 's' | 'S' | 'Z';
|
|
27
|
+
interface ParsedComponents {
|
|
28
|
+
/**
|
|
29
|
+
* Year component
|
|
30
|
+
*/
|
|
31
|
+
Y?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Month component (1-12)
|
|
34
|
+
*/
|
|
35
|
+
M?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Day component
|
|
38
|
+
*/
|
|
39
|
+
D?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Hour in 24-hour format
|
|
42
|
+
*/
|
|
43
|
+
H?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Meridiem indicator (0:AM / 1:PM)
|
|
46
|
+
*/
|
|
47
|
+
A?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Hour in 12-hour format
|
|
50
|
+
*/
|
|
51
|
+
h?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Minute component
|
|
54
|
+
*/
|
|
55
|
+
m?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Second component
|
|
58
|
+
*/
|
|
59
|
+
s?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Millisecond component
|
|
62
|
+
*/
|
|
63
|
+
S?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Timezone offset in minutes
|
|
66
|
+
*/
|
|
67
|
+
Z?: number;
|
|
68
|
+
}
|
|
27
69
|
interface ParserPluginOptions {
|
|
28
70
|
/**
|
|
29
71
|
* The hour format to use for parsing.
|
|
@@ -64,6 +106,12 @@ interface ParserPluginOptions {
|
|
|
64
106
|
* This is an object that provides methods to get localized month names, day names, and meridiems.
|
|
65
107
|
*/
|
|
66
108
|
locale: Locale;
|
|
109
|
+
/**
|
|
110
|
+
* Default date components to use when certain components are missing from the input string.
|
|
111
|
+
* This allows the parser to fill in missing components with default values, which can be useful for parsing partial date strings.
|
|
112
|
+
* For example, if the input string only contains a month and day, the parser can use the default year from this object.
|
|
113
|
+
*/
|
|
114
|
+
defaultDate: ParsedComponents;
|
|
67
115
|
}
|
|
68
116
|
interface ParseResult {
|
|
69
117
|
value: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "date-and-time",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"description": "The simplest, most intuitive date and time library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"date",
|
|
@@ -56,13 +56,13 @@
|
|
|
56
56
|
"dist/"
|
|
57
57
|
],
|
|
58
58
|
"scripts": {
|
|
59
|
-
"build": "rollup -c",
|
|
59
|
+
"build": "rm -rf dist && rollup -c",
|
|
60
60
|
"build-watch": "rollup -c --watch",
|
|
61
61
|
"build:ts": "rollup -c --config-ts",
|
|
62
62
|
"build:types": "rollup -c --config-types",
|
|
63
|
-
"docs:build": "
|
|
64
|
-
"docs:dev": "
|
|
65
|
-
"docs:preview": "
|
|
63
|
+
"docs:build": "astro build",
|
|
64
|
+
"docs:dev": "astro dev",
|
|
65
|
+
"docs:preview": "astro preview",
|
|
66
66
|
"lint": "eslint",
|
|
67
67
|
"prepublishOnly": "npm run build",
|
|
68
68
|
"test": "vitest run",
|
|
@@ -87,24 +87,22 @@
|
|
|
87
87
|
"type": "module",
|
|
88
88
|
"sideEffects": false,
|
|
89
89
|
"devDependencies": {
|
|
90
|
+
"@astrojs/starlight": "^0.38.5",
|
|
90
91
|
"@eslint/js": "^10.0.1",
|
|
91
92
|
"@rollup/plugin-alias": "^6.0.0",
|
|
92
93
|
"@rollup/plugin-terser": "^1.0.0",
|
|
93
94
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
94
|
-
"@types/node": "^25.
|
|
95
|
-
"@vitest/coverage-v8": "^4.1.
|
|
96
|
-
"
|
|
95
|
+
"@types/node": "^25.6.0",
|
|
96
|
+
"@vitest/coverage-v8": "^4.1.5",
|
|
97
|
+
"astro": "^6.2.2",
|
|
98
|
+
"eslint": "^10.3.0",
|
|
97
99
|
"glob": "^13.0.6",
|
|
98
|
-
"prettier": "^3.8.
|
|
99
|
-
"rollup": "^4.60.
|
|
100
|
+
"prettier": "^3.8.3",
|
|
101
|
+
"rollup": "^4.60.3",
|
|
100
102
|
"rollup-plugin-dts": "^6.4.1",
|
|
101
103
|
"rollup-plugin-esbuild": "^6.2.1",
|
|
102
104
|
"tsx": "^4.21.0",
|
|
103
|
-
"typescript-eslint": "^8.
|
|
104
|
-
"
|
|
105
|
-
"vitest": "^4.1.2"
|
|
106
|
-
},
|
|
107
|
-
"overrides": {
|
|
108
|
-
"esbuild": "^0.25.0"
|
|
105
|
+
"typescript-eslint": "^8.59.2",
|
|
106
|
+
"vitest": "^4.1.5"
|
|
109
107
|
}
|
|
110
108
|
}
|