ticktock-es
Version:
A Date utility library
2 lines (1 loc) • 23.7 kB
JavaScript
var[b,v,q,H]=["2-digit","numeric","long","short"],A={fixed:{MM:{month:q},M:{month:H},m:{month:v},mm:{month:b},yyyy:{year:v},yy:{year:b},WD:{weekday:q},wd:{weekday:H},d:{day:v},dd:{day:b},h:{hour:v},hh:{hour:b},mi:{minute:v},mmi:{minute:b},s:{second:v},ss:{second:b},ms:{fractionalSecondDigits:3},tz:{timeZoneName:"shortOffset"},dl:{locale:"default"},h12:{hour12:!1},yn:{yearName:""},ry:{relatedYear:!0},msp:{fractionalSecond:!0}},dynamic:{tzn:e=>({timeZoneName:e.slice(4)}),hrc:e=>({hourCycle:`h${e.slice(4)}`}),ds:e=>({dateStyle:e.slice(3)}),ts:e=>({timeStyle:e.slice(3)}),tz:e=>({timeZone:e.slice(3)}),e:e=>({era:e.slice(2)}),l:e=>({locale:e.slice(2)})}},w={...A,retrieveDynamic(e){let r=e?.slice(0,e?.indexOf(":"));return A.dynamic[r]&&A.dynamic[r](e)},get re(){return new RegExp(`\\b(${Object.keys(A.fixed).join("|")})\\b`,"g")}},N=je;function je(e,r,n="l:default"){return/ds:|ts:/.test(n)?Le(e,me(void 0),n):We(e,me(r||void 0),n)}function me(e="dtf",r=0){let n=` ${e.replace(/(?<=\{)(.+?)(?=})/g,a=>`[${r++}]`).replace(/[{}]/g,"").trim()} `,t=e.match(/(?<=\{)(.+?)(?=})/g)||[];return{get texts(){return t},formatString(a){n=a},set formatStr(a){n=a},get formatStr(){return n},get units(){return n.match(w.re)||[]},finalize(a="",o="",s="",u=""){return n.replace(/~([\d+]?)/g,"$1").replace(/dtf/,a).replace(/era/,s).replace(/dp\b|~dp\b/,o).replace(/yn\b/,u).replace(/\[(\d+?)]/g,(l,i)=>t[i].trim()).trim()}}}function fe(...e){return e?.reduce((r,n)=>({...r,...w.retrieveDynamic(n)||w.fixed[n]}),w.fixed.dl)}function Le(e,r,n){let t=fe(...de(n).split(",")),a=Intl.DateTimeFormat(t.locale,t).format(e);return r.finalize(a)}function Pe(e,r){return e==="numeric"&&r.startsWith("0")?r.slice(1):r}function We(e,r,n){let t=fe(...r.units.concat(de(n).split(",")).flat()),a={...w.fixed},o=Intl.DateTimeFormat(t.locale,t).formatToParts(e).reduce((s,u)=>u.type==="literal"&&/[ ,/-]/.test(u.value)?s:{...s,[u.type]:Pe(t[u.type],u.value)},{});return a.ms=t.fractionalSecondDigits?a.msp:a.ms,a.yyyy=o.relatedYear?a.ry:a.yyyy,r.formatStr=r.formatStr.replace(w.re,s=>/^(M|MM)$/.test(s)?Ye(e,t.locale,t.timeZone,/^M$/.test(s)):o[Object.keys(a[s]).shift()]||s),r.finalize(void 0,o.dayPeriod,o.era,o.yearName)}function Ye(e,r,n,t){return e.toLocaleString(r,{timeZone:n,month:t?H:q})}function de(e){return e.replace(/\s+/g,"")}var ge=Ve;function Ve(){let e=(t,a)=>{let o=isNaN(new Date(t)),s=isNaN(new Date(a));if(s){let[u,l,i]=Array(3).fill("end date not valid");return{error:!0,message:u,full:l,clean:i}}if(o){let[u,l,i]=Array(3).fill("start date not valid");return{error:!0,message:u,full:l,clean:i}}if(o&&!s){let[u,l,i]=Array(3).fill("start- and/or end date are not valid");return{error:!0,message:u,full:l,clean:i}}return{error:!1}},r=n();return function({start:t,end:a,diffs:o={}}={}){let s=e(t,a),u=a>t?"+":"-";if(s.error)return s;let l=Math.abs(t-a),i=new Date(l),c=i.getUTCFullYear()-1970,g=i.getUTCMonth(),D=i.getUTCDate()-1,C=D%7,le=Math.floor(D/7),$=i.getUTCHours(),S=i.getUTCMinutes(),Z=i.getUTCSeconds(),Ue=i.getUTCMilliseconds(),xe=Math.floor(l/864e5);o={...o,fromUTC:t,toUTC:a,sign:"",years:c,months:g,days:D,hours:$,minutes:S,seconds:Z,milliseconds:Ue,diffInDays:xe},o.full=r({values:o,full:!0}),o.clean=r({values:o}),o.equalDates=o.clean==="Dates are equal";let ce=$+S+Z>0?"T":"";return o.clean!=="Dates are equal"&&(o.sign=u,o.jsPeriod=`${u}P${c>0?`${c}Y`:""}${g>0?`${g}M`:""}${le>0?`${le}W`:""}${C>0?`${C}D`:""}${ce}${$>0?`${$}H`:""}${S>0?`${S}M`:""}${Z>0?`${Z}S`:""}`,o.ISOPeriod=`P${c>0?`${c}Y`:""}${g>0?`${g}M`:""}${D>0?`${D}D`:""}${ce}${$>0?`${$}H`:""}${S>0?`${S}M`:""}${Z>0?`${Z}S`:""}`),o};function n(){let t=(...i)=>c=>i.reduce((g,D)=>D(g),c),a=(i,c)=>i===1?c.slice(0,-1):c;return t(({values:i,full:c})=>[Object.entries(i).filter(([g])=>/^(years|month|days|hours|minutes|seconds)/i.test(g)),c],([i,c])=>c?i:i.filter(([,g])=>c?+g:g>0),i=>i.reduce((c,[g,D])=>[...c,`${D} ${a(D,g)}`],[]),i=>i.length<1?"Dates are equal":`${i.slice(0,-1).join(", ")}${i.length>1?" and ":""}${i.slice(-1).shift()}`)}}var ye=Ee;function Ee(){let e=Object.entries({year:"FullYear",month:"Month",date:"Date",day:"Date",hour:"Hours",minute:"Minutes",second:"Seconds",millisecond:"Milliseconds"}).reduce((t,[a,o])=>({...t,[a]:o,[`${a}s`]:o}),{}),r=!1,n=function(...t){let a=t.length===1;return r=t[0].trim().startsWith("subtract,"),r&&(t=a?t[0].trim().replace(/^subtract,/i,"").split(",").map(o=>o.trim()):t.filter(o=>!o.startsWith("subtract"))),a&&!r&&(t=t[0].split(",").map(o=>o.trim())),t.map(function(o){if(!o)return!1;let s=o.toLowerCase().split(/ {1,}/);return s.length<2?!1:s.map(u=>{u=`${u}`.trim().replace(/[^a-z0-9-+]/g,"");let l=parseInt(u,10);return Number.isNaN(l)?u:r?-l:+l})}).filter(o=>o)};return function(t,...a){if(a.length<1)return t;let o=n(...a);return o.length&&o.forEach(([s,u])=>{u=u,u=e[u],s&&u&&t[`set${u}`](t[`get${u}`]()+s)}),t}}var $e=ge(),Se=Re(),h=ye();function _(e,...r){return h(e,...r),e}function U(e,{start:r,end:n,future:t,past:a,include:o={start:!1,end:!1}}={}){let s=e.clone.UTC;return r=r?.value||r?.constructor===Date?m(r?.value||r).UTC:m.now.UTC,n=n&&n?.value||n?.constructor===Date?m(n?.value||n).UTC:m.now.UTC,s.milliseconds=0,r.milliseconds=0,n.milliseconds=0,t?r>n:a?r<n:(o.start?+s>=+r:+s>+r)&&(o.end?+s<=+n:+s<+n)}function G(e,{zoneTime:r=!1,formatStr:n,moreOptions:t}={}){return t=r?e.localeInfo.formatOptions+(t?`,${t}`:""):f.formatOptions+(t?`,${t}`:""),r?(e.localeInfo||(e.localeInfo=f),N(e,n,t)):qe(e,n,t)}function qe(e,r,n){let t=e.clone.relocate(f);return n=(n||"").startsWith("+")?`${t.localeInfo.formatOptions},${n.slice(1)}`:n||t.localeInfo.formatOptions,N(t,r,n)}function Ze(e,r){let n=$e({start:e,end:r||e});return parseInt(`${n.sign}${n.diffInDays}`)}function R(e,r=!1){let{locale:n,timeZone:t}=r?e.localeInfo:f,a=se(n,t),o=e.format("MM|WD",a).split("|");return{locale:n,timeZone:t,monthName:o[0],dayName:o[1],dayNames:ae(n),monthNames:Y(n)}}function J(e,r=!1){let[n,t,a,o]=x(e,r),u={values4Timezone:r?f.timeZone:e.timeZone,hours:n,minutes:t,seconds:a,milliseconds:o};return Object.freeze(u)}function x(e,r=!1){let t=`l:en-CA,${r?`tz:${f.timeZone}`:`tz:${e.timeZone}`},hrc:23,ts:medium`;return e.format("",t).split(/:/).map(Number).concat(e.getMilliseconds())}function B(e,r){let n=r?`tz:${f.timeZone}`:`,tz:${e.timeZone}`,[t,a,o]=e.format("yyyy-mm-dd",n).split(/-/).map(Number);a-=1;let s=r?f.timeZone:e.timeZone;return Object.freeze({values4Timezone:s,year:t,month:a,date:o})}function K(e,r=!0){if(r)return[e.getFullYear(),e.getMonth(),e.getDate()];let n=e.format("yyyy-m-d",e.localeInfo.formatOptions).split(/-/).map(Number);return n[1]-=1,n}function be(e,{sunday:r=!1}={}){return L(e,{day:r?"sunday":"monday"})}function He(e,r){let n=e.toString().match(/GMT([+-])\d+/)?.[0]?.slice(3)??"+0000",t=r.toString().match(/GMT([+-])\d+/)?.[0]?.slice(3)??"+0000";return n=k(n.slice(0,3)+":"+n.slice(-2),!0),t=k(t.slice(0,3)+":"+t.slice(-2),!0),[-n[0]+t[0],-n[1]+t[1]].map(a=>n[0]<0?-a:a)}function Q({start:e,end:r}={}){r||(r=e.clone),r?.clone||(r=m(r,{timeZone:e.timeZone})),e=m(pe(e,e.timeZone),{timeZone:e.timeZone}),r=m(pe(r,r.timeZone),{timeZone:r.timeZone});let n=$e({start:e,end:r,diffs:{timeZoneStart:e.timeZone,timeZoneEnd:r.timeZone}}),t=He(r,e),a=t[0]>0?"ahead of":"behind",[o,s]=t.map(i=>Math.abs(i)),[u,l]=[`${o} ${M(o,"hour")}`,`${s} ${M(s,"minute")}`];return n.timeZonesOffsetDifference=n.sign.length<1||o+s===0?`Offsets of ${e.timeZone} and ${r.timeZone} are equal`:`${e.timeZone} is ${u}${s>0?` and ${l}`:""} ${a} ${r.timeZone}`,n}function _e(e){return e==="+"?"-":"+"}function X(e,r){let n=String(r).toLowerCase()==="utc"||r.timeZone==="UTC";r=n?e.clone.relocate({timeZone:"UTC"}):m(e.value,{timeZone:r.timeZone||f.timeZone});let t=Q({start:e.clone,end:r}),o=`${n?_e(t.sign):t.sign}${he(t.hours)}:${he(t.minutes)}`;return{fromTZ:e.timeZone,toTZ:r.timeZone,offset:o,offsetText:`${r.timeZone} `+Ge(o)+` ${e.timeZone}`}}function he(e,r=2){return`${e}`.padStart(r,"0")}function M(e,r){return`${r}${e>1||e===0?"s":""}`}function Ge(e){if(/00:00/.test(e))return"no time diffence to";let r=e.slice(1).split(":").map(Number),[n,t]=r,a=e.at(0)==="+";return t>0?`${n} ${M(n,"hour")} and ${t} ${M(t,"minute")} ${a?"ahead of":"behind"}`:`${n} ${M(n,"hour")} ${a?"ahead of":"behind"}`}function De(e,r,n){return e.clone.format(r,n||e.localeInfo.formatOptions)}function ve(e,{withFormat:r,withFormatOptions:n,local:t=!1}={}){if(r)return t?De(e,r,$D.localeInformation.formatOptions):De(e,r,n);let a=e.clone.relocate({locale:"en"}),o=t?f.formatOptions:a.localeInfo.formatOptions,u=`wd M dd yyyy hh:mmi:ss ${a.format("tz",o+",tzn:longOffset").replace(":","")} (tz)`;return a.format(u,o+",tzn:long, hrc:23")}function ee(e,r=!1){let n=Intl.DateTimeFormat("en",{timeZone:r?e.timeZone:f.timeZone,weekday:"short"});return Se(n.format(e))}function we(e){let r=f,n=e.localeInfo,t=e.clone.relocate({locale:r.locale,timeZone:r.timeZone}),a=e.offsetFrom(t),o=t.offsetFrom(e),s=r,u=n,l=e.format("hh:mmi:ss dp",`hrc:12,tz:${e.timeZone}`),i=t.format("hh:mmi:ss dp",`hrc:12,tz:${t.timeZone}`),c={note:"'user' are values for your locale/timeZone, 'remote' (if applicable) idem for the instance",locales:{user:{locale:s.locale,timeZone:s.timeZone}},dateTime:{user:{...e.dateTime,monthName:t.monthName,weekdayNr:t.day,weekdayName:t.dayName,dayPeriodTime:i,hasDST:t.hasDST,DSTActive:t.DSTActive,offsetFromRemote:a.offset,string:t.toString()}},offset:{fromUTC:e.UTC.offsetFrom(e).offsetText}};return n.timeZone!==r.timeZone&&(c.locales.remote={locale:u.locale,timeZone:u.timeZone},c.dateTime.remote={...e.zoneDateTime,monthName:e.zoneNames.monthName,weekdayNr:ee(e,!0),weekdayName:e.zoneNames.dayName,dayPeriodTime:l,hasDST:e.hasDST,DSTActive:e.DSTActive,offsetFromUser:o.offset,string:e.toString()},c.offset.fromUserTime=o.offsetText),c}function O(e,r=!0){if(r)return[e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()];let n=e.format("yyyy-m-d-hh-mmi-ss",`${e.localeInfo.formatOptions},hrc23:true`).split(/-/).map(Number).concat(e.getMilliseconds());return n[1]-=1,n}function te(e){return new Date(e.year,e.month+1,0,0,0,0).getDate()}function j(e,r){r=d({locale:r}).locale;let n=e.clone.relocate({locale:r});return n.date={date:1},[n].concat([...Array(te(n)-1)].map((t,a)=>n.clone.add(`${a+1} days`)))}function L(e,{day:r,next:n=!1}={}){let t=Se(r?.toLowerCase()),a=m(new Date(...e.dateTimeValues),e.localeInfo);return t<0?(console.error(`[TickTock instance].next/previous invalid day value ${r}`),a):Ne(a,t,n?1:-1)}function Ne(e,r,n){return h(e,`${n} day`).getDay()<r?Ne(e,r,n):e}function I(e,{dateOnly:r=!1,timeOnly:n=!1}={}){e.localeInfo||(e.localeInfo=T());let{locale:t,timeZone:a}=e.localeInfo;return r?new Date(e).toLocaleDateString(t,{timeZone:a}):n?new Date(e).toLocaleTimeString(t,{timeZone:a}):new Date(e).toLocaleString(t,{timeZone:a})}function pe(e,r){let n={timeZone:r,hourCycle:"h23"};return new Date(new Date(e).toLocaleString("en",n))}function z(e,{year:r,month:n,date:t}={}){return y(r)&&e.setFullYear(parseInt(r)),y(t)&&e.setDate(parseInt(t)),y(n)&&e.setMonth(parseInt(n)),e}function p(e,{hours:r,minutes:n,seconds:t,milliseconds:a}={}){return y(r)&&e.setHours(parseInt(r)),y(n)&&e.setMinutes(parseInt(n)),y(t)&&e.setSeconds(parseInt(t)),y(a)&&e.setMilliseconds(parseInt(a)),e}function ze(e){return e?.constructor===Date||e?.value}function re(e,r){return ze(r)?m(r?.value||r,e.localeInfo):m.from(...e.dateTimeValues).relocate(e.localeInfo)}function Re(){let e={short:["sun","mon","tue","wed","thu","fri","sat"],long:["sunday","monday","tuesday","wednesday","thursday","friday","saturday"]};return function(r){r=`${r}`.toLowerCase();let n=e.short.indexOf(r);return n<0?e.long.indexOf(r):n}}function k(e,r=!1){if(r){let n=e.slice(1).split(/[-:]/).map(Number),t=e.slice(0,1)==="-";return n=n.map(a=>t?-a:a),n}return Number(e.split(/[+-]/).slice(-1)[0].replace(/:/,""))}function Me(e){return e.time={hours:0,minutes:0,seconds:0,milliseconds:0},e}function Te(e,r){return Intl.DateTimeFormat("en-CA",{timeZone:r,timeZoneName:"long"}).format(e).split(/,/)[1].trim()}function P(e,r){r=r||e?.timeZone||f.timeZone,e=e?.value?e:e?.constructor===Date?m(e,{timeZone:r}):m({timeZone:r});let n=e.year||e.getFullYear(),t=Te(new Date(n,0,1),r),a=Te(new Date(n,5,1),r);return t!==a}function W(e,r){return r=r||e?.timeZone||f.timeZone,e=e?.hasDST?e:e?.constructor===Date?m(e,{timeZone:r}):m({timeZone:r}),e.hasDST?!/standard/i.test(e.toString()):!1}function Oe(e,{locale:r,timeZone:n,l:t,tz:a}={}){return e.localeInfo=d({locale:t||r||e.l||e.locale,timeZone:a||n||e.tz||e.timeZone}),e}function Ie(e,r){return ze(r)&&(e=m(r.value||r,r.localeInfo||e.localeInfo)),e}function F(e,r){let n=oe(new Date(e,11,r||31));return n===1?F(e,(r||31)-1):n}function ne(e,r){let n=e.month;switch(!0){case n<3:return r?1:"First";case n<6:return r?2:"Second";case n<9:return r?3:"Third";case n<12:return r?4:"Fourth";default:return"unknown"}}function oe(e){let r=new Date(e),n=(r.getDay()+6)%7;r.setDate(r.getDate()-n+3);let t=r.valueOf();return r.setMonth(0,1),r.getDay()!==4&&r.setMonth(0,1+(4-r.getDay()+7)%7),1+Math.ceil((t-r)/6048e5)}var V=Je;function Je({localeInfo:e,customMethods:r,dateValue:n}={}){let t,a={add(...o){return _(t,...o)},between({start:o,end:s,include:u}={}){return U(t,{start:o,end:s,include:u})},cloneWith(o){return re(t,o)},daysUntil(o){return Ze(t,o)},differenceTo(o){return Q({start:t,end:o})},differenceUntil(o){return t.differenceTo(o).clean},firstWeekday({sunday:o=!1,midnight:s=!1}={}){return be(t,{sunday:o,midnight:s})},format(o,s){return G(t,{formatStr:o,moreOptions:s})},fullMonth(o){return j(t,o)},isFuture(o){return U(t,{start:t,end:o,future:!0})},isPast(o){return U(t,{start:t,end:o,past:!0})},next(o){return L(t,{day:o,next:!0})},offsetFrom(o){return X(t,o)},previous(o){return L(t,{day:o,next:!1})},relocate({locale:o,timeZone:s,l:u,tz:l}={}){return Oe(t,{locale:o,timeZone:s,l:u,tz:l})},revalue(o){return t=Ie(t,o),t},setDateValues({year:o,month:s,date:u}={}){return z(t,{year:o,month:s,date:u})},setTimeValues({hours:o,minutes:s,seconds:u,milliseconds:l}={}){return p(t,{hours:o,minutes:s,seconds:u,milliseconds:l})},subtract(...o){return _(t,"subtract,"+o.join(","))},toArray(o=!1){return O(t,o)},toString({template:o,formatOptions:s,local:u}={}){return ve(t,{withFormat:o,withFormatOptions:s,local:u})},values(o=!1){return o?t.dateTime:t.zoneDateTime},zoneFormat(o,s){return G(t,{zoneTime:!0,formatStr:o,moreOptions:s})},set date({year:o,month:s,date:u}){z(t,{year:o,month:s,date:u})},set dateNr(o){z(t,{date:o})},set hours(o){p(t,{hours:o})},set localeInfo({locale:o,timeZone:s,l:u,tz:l}){e=T({locale:o,timeZone:s,l:u,tz:l})},set milliseconds(o){p(t,{milliseconds:`${o}`})},set minutes(o){p(t,{minutes:o})},set month(o){z(t,{month:o})},set seconds(o){p(t,{seconds:o})},set time({hours:o,minutes:s,seconds:u,milliseconds:l}){p(t,{hours:o,minutes:s,seconds:u,milliseconds:l})},set year(o){z(t,{year:o})},get age(){return t.differenceTo(new Date).years},get ageFull(){return t.differenceTo(new Date).clean},get clone(){return re(t)},get date(){return B(t,!0)},get dateNr(){return t.date.date},get dateTime(){return{...t.date,...t.time}},get dateTimeValues(){return O(t,!0)},get dateValues(){return K(t,!0)},get day(){return t.getDay()},get dayName(){return t.names.dayName},get daysThisMonth(){return te(t)},get DSTActive(){return W(t)},get hasDST(){return P(t)},get hours(){return t.time.hours},get info(){return we(t)},get isLeapYear(){return new Date(t.getFullYear(),2,0).getDate()===29},get ISO(){return t.toISOString()},get local(){return I(t)},get localDate(){return I(t,{dateOnly:!0})},get locale(){return(e||T()).locale},get localeInfo(){return e},get localeString(){return I(t)},get localTime(){return I(t,{timeOnly:!0})},get milliseconds(){return t.getMilliseconds()},get minutes(){return t.time.minutes},get month(){return t.date.month},get monthName(){return t.names.monthName},get names(){return R(t)},get quarter(){return ne(t)},get quarterNr(){return ne(t,!0)},get removeTime(){return Me(t)},get seconds(){return t.time.seconds},get time(){return J(t,!0)},get timeValues(){return x(t,!0)},get timeZone(){return(e||T()).timeZone},get unixEpochTimestamp(){return Math.floor(+t/1e3)},get userLocaleInfo(){return f},get UTC(){return t.clone.relocate({locale:t.locale,timeZone:"UTC"})},get UTCOffset(){return X(t,"UTC")},get value(){return new Date(t)},get weeknr(){return oe(t)},get weeksInYear(){return F(t.year,31)},get year(){return t.date.year},get zoneDate(){return B(t,!1)},get zoneDateNr(){return t.zoneDate.date},get zoneDateTime(){return{...t.zoneDate,...t.zoneTime}},get zoneDateTimeValues(){return O(t,!1)},get zoneDateValues(){return K(t,!1)},get zoneDay(){return ee(t,!0)},get zoneDayname(){return t.zoneNames.dayName},get zoneHours(){return t.zoneTime.hours},get zoneMinutes(){return t.zoneTime.minutes},get zoneMonth(){return t.zoneDate.month},get zoneMonthname(){return t.zoneNames.monthName},get zoneNames(){return R(t,!0)},get zoneSeconds(){return t.zoneTime.seconds},get zoneTime(){return J(t)},get zoneTimeValues(){return x(t)},get zoneYear(){return t.zoneDate.year},get zoneValues(){return t.zoneDateTime},get zoneArray(){return O(t,!1)}};return!e&&!n?a:(a.localeInfo=e||T(),t=new Proxy(n,Be(a)),Object.entries(Object.getOwnPropertyDescriptors(ue(t,r))).forEach(([o,s])=>Object.defineProperty(a,o,s)),Object.freeze(t))}function Be(e){return{get(r,n){return n!=="toString"&&n in r?r[n].bind(r):Reflect.get(e,n)},set(r,n,t){return n in e&&Reflect.set(e,n,t)}}}var f=ie(Intl.DateTimeFormat().resolvedOptions()),Ke=Object.getOwnPropertyNames(Date.prototype).filter(e=>e.startsWith("set")).reduce((e,r)=>[...e,{native:r,syn:"change"+r.slice(3)}],[]);function ae(e="en-GB"){return e=d({locale:e}).locale,{long:[...Array(7).keys()].map(r=>new Date(Date.UTC(1970,0,4+r)).toLocaleDateString(e,{timeZone:"Etc/UTC",weekday:"long"})),short:[...Array(7).keys()].map(r=>new Date(Date.UTC(1970,0,4+r)).toLocaleDateString(e,{timeZone:"Etc/UTC",weekday:"short"}))}}function Y(e="en"){return e=d({locale:e}).locale,{long:[...Array(12).keys()].map(r=>new Date(Date.UTC(1970,r,1)).toLocaleDateString(e,{timeZone:"Etc/UTC",month:"long"})),short:[...Array(12).keys()].map(r=>new Date(Date.UTC(1970,r,1)).toLocaleDateString(e,{timeZone:"Etc/UTC",month:"short"}))}}function Qe({year:e,locale:r}={}){e=y(e)?parseInt(e):new Date().getFullYear();let n={year:e,calendar:{}},t=Y().long.map(a=>a.toLowerCase());for(let a=0;a<12;a+=1){let o=m.from(e,a,1);n.calendar[t[a]]=j(o,r)}return n}function Xe({year:e,monthNr:r,locale:n="en-CA"}={}){e=y(r)&&parseInt(e)||-1,r=y(r)&&parseInt(r)||new Date().getFullYear();let t=r>=1&&r<=12;return n=d({locale:n}).locale,r=t?r-1:void 0,t?m.from(e,r,1).relocate({locale:n}).fullMonth(n):"MonthNr should be a specific number (1 = january - 12 = december)"}function ie(e){let r=se(e.locale,e.timeZone);return Object.defineProperty(e,"formatOptions",{value:r,enumerable:!1})}function se(e,r){return[`${e&&!(Array.isArray(e)&&e.length<1)?`l:${e}`:""}`,`${r?`tz:${r}`:""}`].filter(n=>n).join(",")}function d({locale:e,timeZone:r,l:n,tz:t}={}){return r=r||t,e=e||n,!e&&!r?f:et({trial:function(){let a=Intl.DateTimeFormat(e,{timeZone:r}).resolvedOptions();return e&&a.locale!==e&&console.error(`\u{1F6AB} Intl changed locale (using best fit) "${e}" to "${a.locale}"`),ie(a)},whenError:function(a){switch(!0){case/incorrect locale/i.test(a.message):return console.error(`\u{1F6AB} Intl locale "${e}" best fit impossible, using "${f.locale}"`),d({locale:f.locale,timeZone:r});case/invalid time zone/i.test(a.message):return console.error(`\u{1F6AB} timeZone "${r}" not valid. Using "${f.timeZone}"`),d({locale:e,timeZone:f.timeZone});default:return f||ie(Intl.DateTimeFormat().resolvedOptions())}}})}function T({locale:e,timeZone:r,l:n,tz:t}={}){return d({locale:e,timeZone:r,l:n,tz:t},!0)}function Fe(e){return!Number.isNaN(+e)&&e?.constructor===Date&&!e?.toISOString?.().startsWith("1970-01-01T00:00:00")?e:new Date}function Ce(e){let r=new Date;switch(!0){case e?.constructor===String:return Fe(new Date(e));case(Array.isArray(e)&&e.map(Number).length===e.length):return e.length===1?new Date(e[0],0,1):new Date(...e);case e?.constructor===Date:return Fe(e);default:return r}}function et({trial:e,whenError:r=()=>{}}={}){if(e?.constructor===Function)try{return e()}catch(n){return r?.constructor===Function?r(n):void 0}}function tt({timeZoneDate:e,timeZoneID:r,userTimeZoneID:n}={}){let t={timeZone:d({timeZone:r}).timeZone},a={timeZone:d({timeZone:n||""}).timeZone},o=m(e,t),s=m(e,a),u=s.differenceTo(o),l=o.offsetFrom(s).offset,[i,c]=k(l,!0),g=s.clone.add(`${i} hours, ${c} minutes`),C=u.equalDates?"No difference":`Time offset ${l}: ${a.timeZone} is ${u.clean} ${i<0?"behind":"ahead of"} ${t.timeZone}`;return{remoteTimezone:t.timeZone,userTimezone:a.timeZone,timeDifference:C,result:{[t.timeZone.replace(/\//,"_")]:m(e).toString({template:"yyyy/mm/dd hh:mmi:ss",formatOptions:"hrc:23"}),[a.timeZone.replace(/\//,"_")]:g.toString({template:"yyyy/mm/dd hh:mmi:ss",formatOptions:"hrc:23"})}}}function y(e){return!Number.isNaN(parseInt(e))}function E(e,r,n){return e?.constructor===Number?h(r,`${e} ${n}`):r}function rt(e){let r={addYears(n=1){return E(n,e,"years")},addMonths(n=1){return E(n,e,"months")},addWeeks(n=1){return n=n?.constructor===Number?n*7:1,E(n,e,"days")},addDays(n=1){return E(n,e,"days")},get nextYear(){return h(e,"1 year")},get nextWeek(){return h(e,"7 days")},get previousWeek(){return h(e,"-7 days")},get previousYear(){return h(e,"-1 year")},get nextMonth(){return h(e,"1 month")},get previousMonth(){return h(e,"-1 month")},get tomorrow(){return h(e,"1 day")},get yesterday(){return h(e,"-1 day")}};for(let n of Ke)r[n.syn]=function(...t){return e[n.native](...t),e};return r}function ue(e,r){let n=rt(e);for(let[t,a]of Object.entries(r||{})){let o=a.enumerable,s=a.isGetter?{get(){return a.method(e)},enumerable:o}:{value(...u){return a.method(e,...u)},enumerable:o};Object.defineProperty(n,t,s)}return n}function Ae(e,r){return Object.defineProperties(e,{now:{get(){return e(new Date)}},localeInformation:{get(){return d()}},localWeekdaynames:{value(n){return ae(n)}},localMonthnames:{value(n){return Y(n)}},daysInMonth:{value(n,t=!1){return n=y(n)?parseInt(n):0,n>=1&&n<=12?new Date(t?2e3:2005,n,0).getDate():`${n} should be a Number (1 (january) - 12 (december))`}},yearCalendar:{value:Qe},monthCalendar:{value:Xe},from:{value(...n){return e(n)}},fromUxTS:{value(n,t){n=y(n)?parseInt(n)*1e3:void 0;let a=n?new Date(n):new Date;return m(a,t||f)}},hasDST:{value({date:n,timeZone:t}={}){return P(n,t)}},DSTActive:{value({date:n,timeZone:t}={}){return W(n,t)}},values:{value({date:n,timeZone:t}={}){n=n||n?.value||new Date;let a=N(n,"yyyy-m-d-h-mi-s",d({timeZone:t}).formatOptions.concat(",hrc:23")).split("-").map(Number).concat(n.getMilliseconds());return a[1]-=1,a}},format:{value({date:n,template:t,timeZone:a,locale:o,opts:s}={}){n=n||n?.value||new Date,t=t?.constructor===String?t:"yyyy/mm/dd hh:mmi:ss dp";let u=d({timeZone:a,locale:o}).formatOptions;return u+=s?`,${s}`:"",N(n,t,u)}},addCustom:{value({name:n,method:t,enumerable:a=!1,isGetter:o=!1}={}){n?.constructor===String&&t?.constructor===Function&&t.length>0&&(r[n]={method:t,enumerable:a,isGetter:o})}},validateLocaleInformation:{value:d},timeAcrossZones:{value:tt},weeksInYear:{value(n){return F(n,31)}},keys:{get(){let n=Object.fromEntries(Object.entries(r).filter(([a,o])=>o.enumerable===!0));return[...Object.keys(V()),...Object.keys(ue()),...Object.keys(n)].sort((a,o)=>a.localeCompare(o))}}}),e}var ke={},m=Ae(nt,ke);function nt(e,r){if(e?.localeInfo)return e.clone;let n=e?.locale||e?.timeZone||e?.tz||e?.l;return V({localeInfo:d(n?e:r),dateValue:new Date(n?Date.now():Ce(e)),customMethods:ke})}export{m as default};