const t=new Map;class e{constructor(t,e){this._format=t,this._timezone=e,this._isIso="datetime-iso"===this._format,this._isMillisIncluded=this._isIso,this._isZoneOffsetIncluded=this._isIso}format(t){const e=this.formatToParts(t);return Object.values(e).filter((t=>null!=t)).join("")}formatToParts(t){const e=this.toParts(t),i={date:`${e.year}-${e.month}-${e.day}`,separator:this._isIso?"T":" ",time:`${e.hour}:${e.minute}:${e.second}`};return this._isMillisIncluded&&(i.millisecond=`.${e.millisecond}`),this._isZoneOffsetIncluded&&(i.timezone=e.timezone),i}mapParts(t,e){const o=this.toParts(t),n=s("-"),r=s(":"),a=[i(o.year),n,i(o.month),n,i(o.day),s(this._isIso?"T":" "),i(o.hour),r,i(o.minute),r,i(o.second)];return this._isMillisIncluded&&(a.push({value:".",type:"separator"}),a.push(i(o.millisecond))),this._isZoneOffsetIncluded&&a.push(i(o.timezone)),a.map(e)}toParts(e){const i=function(e){let i=t.get(e);return null==i&&(i=new Intl.DateTimeFormat("en",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",fractionalSecondDigits:3,hourCycle:"h23",timeZoneName:"longOffset",timeZone:"local"===e?void 0:e}),t.set(e,i)),i}(this._timezone).formatToParts(e),s=Object.fromEntries(i.map((({type:t,value:e})=>[t,e]))),o={year:s.year,month:s.month,day:s.day,hour:s.hour,minute:s.minute,second:s.second};return this._isMillisIncluded&&(o.millisecond=s.fractionalSecond),this._isZoneOffsetIncluded&&(o.timezone="GMT"===s.timeZoneName?"Z":s.timeZoneName.slice(3)),o}}function i(t){return{value:t,type:"part"}}function s(t){return{value:t,type:"separator"}}export{e as DateFormatter};
//# sourceMappingURL=date-formatter.js.map
