UNPKG

ticktock-es

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