@fr0st/datetime 5.0.2 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -31
- package/dist/frost-datetime.js +34 -26
- package/dist/frost-datetime.js.map +1 -1
- package/dist/frost-datetime.min.js +1 -1
- package/dist/frost-datetime.min.js.map +1 -1
- package/package.json +4 -4
- package/src/helpers.js +2 -2
- package/src/prototype/utility.js +32 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).DateTime=t()}(this,(function(){"use strict";const e={};function t(t,n){return t in e||(e[t]=n()),e[t]}function n(e){return t(`dateFormatter.${e}`,(t=>r("en",{timeZone:e,hourCycle:"h23",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric"})))}function r(e,t){return new Intl.DateTimeFormat(e,{timeZone:"UTC",...t})}const s=(new Intl.DateTimeFormat).resolvedOptions(),i={clampDates:!0,defaultLocale:s.locale,defaultTimeZone:s.timeZone},o=/\s(?:UTC|GMT|Z|[\+\-]\d)|\d{4}\-\d{2}\-\d{2}T\d{2}\:\d{2}\:\d{2}\.\d{3}[\+\-]\d{2}\:\d{2}/i,a="eee MMM dd yyyy",u="yyyy-MM-dd'T'HH:mm:ss.SSSxxx",c="eee MMM dd yyyy HH:mm:ss xx (VV)",h="HH:mm:ss xx (VV)",l=/([a-z])\1*|'[^']*'/i,f=[31,28,31,30,31,30,31,31,30,31,30,31],g=/(?:GMT)?([\+\-])(\d{2})(\:?)(\d{2})?/,m=[["year","weekYear"],["era"],["quarter","month","week","dayOfYear"],["weekOfMonth"],["date","weekDay"],["weekDayInMonth"],["hours24","hours12","dayPeriod"],["minutes","seconds","milliseconds"]],d={month:12,week:null,day:7,hour:24,minute:60,second:60};function y(e,t,n,r=!0,s=1){return n>0?(n=Math.floor(n),r&&e<t&&(n+=s)):n<0&&(n=Math.ceil(n),r&&e>t&&(n-=s)),n}function p(e){const t=e.getTimeZone();if("UTC"===t)return 0;const r=n("UTC").format(e),s=n(t).format(e);return(new Date(r)-new Date(s))/6e4}function k(e){return e.getTime()-6e4*e.getTimeZoneOffset()}function w(e,t,n){switch(n=n.toLowerCase()){case"second":case"seconds":return e.setSeconds(e.getSeconds()+t);case"minute":case"minutes":return e.setMinutes(e.getMinutes()+t);case"hour":case"hours":return e.setHours(e.getHours()+t);case"week":case"weeks":return e.setDate(e.getDate()+7*t);case"day":case"days":return e.setDate(e.getDate()+t);case"month":case"months":return e.setMonth(e.getMonth()+t);case"year":case"years":return e.setYear(e.getYear()+t);default:throw new Error("Invalid time unit supplied")}}function T(e,t){let n=0;for(const r of e){if(r!==t[n])throw new Error(`Unmatched character in DateTime string: ${r}`);n++}}function D(e,t){return e.setTime(t+6e4*e.getTimeZoneOffset())}function M(e,n="long"){return t(`periods.${e}.${n}`,(t=>{const n=r(e,{hour:"numeric",hourCycle:"h11"});return new Array(2).fill().map(((e,t)=>n.formatToParts(Date.UTC(2018,0,1,12*t)).find((e=>"dayPeriod"===e.type)).value))}))}function Z(e,n="long",s=!0){return t(`days.${e}.${n}.${s}`,(t=>{if(s){const t=r(e,{weekday:n});return new Array(7).fill().map(((e,n)=>t.format(Date.UTC(2018,0,n))))}const i=r(e,{year:"numeric",month:"numeric",day:"numeric",weekday:n});return new Array(7).fill().map(((e,t)=>i.formatToParts(Date.UTC(2018,0,t)).find((e=>"weekday"===e.type)).value))}))}function Y(e,n="long"){return t(`eras.${e}.${n}`,(t=>{const s=r(e,{era:n});return new Array(2).fill().map(((e,t)=>s.formatToParts(Date.UTC(t-1,0,1)).find((e=>"era"===e.type)).value))}))}function L(e,n="long",s=!0){return t(`months.${e}.${n}.${s}`,(t=>{if(s){const t=r(e,{month:n});return new Array(12).fill().map(((e,n)=>t.format(Date.UTC(2018,n,1))))}const i=r(e,{year:"numeric",month:n,day:"numeric"});return new Array(12).fill().map(((e,t)=>i.formatToParts(Date.UTC(2018,t,1)).find((e=>"month"===e.type)).value))}))}function x(e){return t(`numbers.${e}`,(t=>{const n=r(e,{minute:"numeric"});return new Array(10).fill().map(((e,t)=>n.format(Date.UTC(2018,0,1,0,t))))}))}function W(e){return`(?:${x(e).join("|")})+`}function O(e,t,n="long",r=!0){return Z(e,n,r)[t]}function C(e,t,n="long",r=!0){return L(e,n,r)[t-1]}function b(e,t,n=0){const r=x(e);return`${t}`.padStart(n,0).replace(/\d/g,(e=>r[e]))}function H(e,t=!0,n=!1){const r=Math.abs(e/60|0),s=Math.abs(e%60),i=e>0?"-":"+",o=`${r}`.padStart(2,0),a=s||!n?`${s}`.padStart(2,0):"";return`${i}${o}${t&&a?":":""}${a}`}class U{constructor(e=null,t={}){let n,r=!1;if(null===e)n=Date.now();else if(!isNaN(parseInt(e))&&isFinite(e))n=e;else{if(e!==`${e}`)throw new Error("Invalid date supplied");if(n=Date.parse(e),isNaN(n))throw new Error("Invalid date string supplied");e.match(o)||(n-=6e4*(new Date).getTimezoneOffset()),r=!0}this._date=new Date(n),this._dynamicTz=!1,this.isValid=!0;let s=t.timeZone;s||(s=i.defaultTimeZone),["Z","GMT"].includes(s)&&(s="UTC");const a=s.match(g);if(a?(this._offset=60*a[2]+parseInt(a[4]||0),this._offset&&"+"===a[1]&&(this._offset*=-1),this._offset?this._timeZone=H(this._offset):(this._dynamicTz=!0,this._timeZone="UTC")):(this._dynamicTz=!0,this._timeZone=s),this._dynamicTz&&(this._offset=p(this)),r&&this._offset){const e=this._offset;this._date.setTime(this.getTime()+6e4*this._offset),this._dynamicTz&&(this._offset=p(this),e!==this._offset&&this._date.setTime(this.getTime()-6e4*(e-offset)))}"locale"in t||(t.locale=i.defaultLocale),this._locale=t.locale}getLocale(){return this._locale}getTime(){return this._date.getTime()}getTimeZone(){return this._timeZone}getTimeZoneOffset(){return this._offset}setLocale(e){return new U(this.getTime(),{locale:e,timeZone:this._timeZone})}setTime(e){return new U(e,{locale:this._locale,timeZone:this._timeZone})}setTimeZone(e){return new U(this.getTime(),{locale:this._locale,timeZone:e})}setTimeZoneOffset(e){return new U(this.getTime(),{locale:this._locale,timeZone:H(e)})}valueOf(){return this.getTime()}[Symbol.toPrimitive](e){return"number"===e?this.valueOf():this.toString()}}const I={1:["af","am","ar-il","ar-sa","ar-ye","as","bn","bo","brx","ccp","ceb","chr","dav","dz","ebu","en","fil","gu","guz","haw","he","hi","id","ii","ja","jv","kam","ki","kln","km","kn","ko","kok","ks","lkt","lo","luo","luy","mas","mer","mgh","ml","mr","mt","my","nd","ne","om","or","pa","ps-pk","pt","qu","saq","sd","seh","sn","ta","te","th","ti","ug","ur","xh","yue","zh","zu"],7:["ar","ckb","en-ae","en-sd","fa","kab","lrc","mzn","ps"]},S={4:["ast","bg","br","ca","ce","cs","cy","da","de","dsb","el","en-at","en-be","en-ch","en-de","en-dk","en-fi","en-fj","en-gb","en-gg","en-gi","en-ie","en-im","en-je","en-nl","en-se","es","et","eu","fi","fo","fr","fur","fy","ga","gd","gl","gsw","gv","hsb","hu","is","it","ksh","kw","lb","lt","nb","nds","nl","nn","os-ru","pl","pt-ch","pt-lu","pt-pt","rm","ru","sah","se","sk","smn","sv","tt","wae"]};function $(e){switch(e){case 5:return"narrow";case 4:return"long";default:return"short"}}function _(e){return t(`minimumDays.${e}`,(t=>{let n=1;const r=e.toLowerCase().split("-");for(;1===n&&r.length;){for(const e in S)if({}.hasOwnProperty.call(S,e)&&S[e].includes(r.join("-"))){n=parseInt(e);break}r.pop()}return n}))}function v(e,n){return(7+parseInt(n)-function(e){return t(`weekStartOffset.${e}`,(t=>{let n;const r=e.toLowerCase().split("-");for(;!n&&r.length;){for(const e in I)if({}.hasOwnProperty.call(I,e)&&I[e].includes(r.join("-"))){n=parseInt(e);break}r.pop()}return n?n-2:0}))}(e))%7||7}function A(e,t,n="long",r=!0){return v(e,Z(e,n,r).indexOf(t)||7)}function z(e,t,n="long",r=!0){return L(e,n,r).indexOf(t)+1}function j(e,t){const n=x(e);return parseInt(`${t}`.replace(/./g,(e=>n.indexOf(e))))}var E={G:{key:"era",maxLength:5,regex:(e,t)=>Y(e,$(t)).join("|"),input:(e,t,n)=>function(e,t,n="long"){return Y(e,n).indexOf(t)}(e,t,$(n)),output:(e,t)=>{const n=$(t);return e.era(n)}},y:{key:"year",regex:e=>W(e),input:(e,t,n)=>(t=j(e,t),2!==n||2!==`${t}`.length?t:t>40?1900+t:2e3+t),output:(e,t)=>{let n=e.getYear();return 2===t&&(n=`${n}`.slice(-2)),b(e.getLocale(),Math.abs(n),t)}},Y:{key:"weekYear",regex:e=>W(e),input:(e,t,n)=>(t=j(e,t),2!==n||2!==`${t}`.length?t:t>40?1900+t:2e3+t),output:(e,t)=>{let n=e.getWeekYear();return 2===t&&(n=`${n}`.slice(-2)),b(e.getLocale(),Math.abs(n),t)}},Q:{key:"quarter",regex:e=>W(e),input:(e,t)=>j(e,t),output:(e,t)=>b(e.getLocale(),e.getQuarter(),t)},q:{key:"quarter",regex:e=>W(e),input:(e,t)=>j(e,t),output:(e,t)=>b(e.getLocale(),e.getQuarter(),t)},M:{key:"month",regex:(e,t)=>{switch(t){case 5:case 4:case 3:return L(e,$(t),!1).join("|");default:return W(e)}},input:(e,t,n)=>{switch(n){case 5:return null;case 4:case 3:return z(e,t,$(n),!1);default:return j(e,t)}},output:(e,t)=>{const n=e.getLocale(),r=e.getMonth();switch(t){case 5:case 4:case 3:return C(n,r,$(t),!1);default:return b(n,r,t)}}},L:{key:"month",regex:(e,t)=>{switch(t){case 5:case 4:case 3:return L(e,$(t)).join("|");default:return W(e)}},input:(e,t,n)=>{switch(n){case 5:return null;case 4:case 3:return z(e,t,$(n));default:return j(e,t)}},output:(e,t)=>{const n=e.getLocale(),r=e.getMonth();switch(t){case 5:case 4:case 3:return C(n,r,$(t));default:return b(n,r,t)}}},w:{key:"week",regex:e=>W(e),input:(e,t)=>j(e,t),output:(e,t)=>b(e.getLocale(),e.getWeek(),t)},W:{key:"weekOfMonth",regex:e=>W(e),input:(e,t)=>j(e,t),output:e=>b(e.getLocale(),e.getWeekOfMonth())},d:{key:"date",regex:e=>W(e),input:(e,t)=>j(e,t),output:(e,t)=>b(e.getLocale(),e.getDate(),t)},D:{key:"dayOfYear",regex:e=>W(e),input:(e,t)=>j(e,t),output:(e,t)=>b(e.getLocale(),e.getDayOfYear(),t)},F:{key:"weekDayInMonth",regex:e=>W(e),input:(e,t)=>j(e,t),output:e=>b(e.getLocale(),e.getWeekDayInMonth())},E:{key:"weekDay",regex:(e,t)=>Z(e,$(t),!1).join("|"),input:(e,t,n)=>5===n?null:A(e,t,$(n),!1),output:(e,t)=>{const n=$(t);return O(e.getLocale(),e.getDay(),n,!1)}},e:{key:"weekDay",maxLength:5,regex:(e,t)=>{switch(t){case 5:case 4:case 3:return Z(e,$(t),!1).join("|");default:return W(e)}},input:(e,t,n)=>{switch(n){case 5:return null;case 4:case 3:return A(e,t,$(n),!1);default:return j(e,t)}},output:(e,t)=>{const n=e.getLocale();switch(t){case 5:case 4:case 3:const r=$(t);return O(n,e.getDay(),r,!1);default:return b(n,e.getWeekDay(),t)}}},c:{key:"weekDay",maxLength:5,regex:(e,t)=>{switch(t){case 5:case 4:case 3:return Z(e,$(t)).join("|");default:return W(e)}},input:(e,t,n)=>{switch(n){case 5:return null;case 4:case 3:return A(e,t,$(n));default:return j(e,t)}},output:(e,t)=>{const n=e.getLocale();switch(t){case 5:case 4:case 3:const r=$(t);return O(n,e.getDay(),r);default:return b(n,e.getWeekDay())}}},a:{key:"dayPeriod",regex:(e,t)=>M(e,$(t)).join("|"),input:(e,t,n)=>function(e,t,n="long"){return M(e,n).indexOf(t)}(e,t,$(n)),output:(e,t)=>{const n=$(t);return e.dayPeriod(n)}},h:{key:"hours12",regex:e=>W(e),input:(e,t)=>(12===(t=j(e,t))&&(t=0),t),output:(e,t)=>b(e.getLocale(),e.getHours()%12||12,t)},H:{key:"hours24",regex:e=>W(e),input:(e,t)=>j(e,t),output:(e,t)=>b(e.getLocale(),e.getHours(),t)},K:{key:"hours12",regex:e=>W(e),input:(e,t)=>j(e,t),output:(e,t)=>b(e.getLocale(),e.getHours()%12,t)},k:{key:"hours24",regex:e=>W(e),input:(e,t)=>(24===(t=j(e,t))&&(t=0),t),output:(e,t)=>b(e.getLocale(),e.getHours()||24,t)},m:{key:"minutes",regex:e=>W(e),input:(e,t)=>j(e,t),output:(e,t)=>b(e.getLocale(),e.getMinutes(),t)},s:{key:"seconds",regex:e=>W(e),input:(e,t)=>j(e,t),output:(e,t)=>b(e.getLocale(),e.getSeconds(),t)},S:{key:"milliseconds",regex:e=>W(e),input:e=>0,output:(e,t)=>b(e.getLocale(),`${Math.floor(1e3*e.getMilliseconds())}`.padEnd(t,"0").slice(0,t))},z:{output:(e,t)=>{5===t&&(t=1);const n=$(t);return e.timeZoneName(n)}},Z:{key:"timeZone",regex:(e,t)=>{switch(t){case 5:return"[\\+\\-]\\d{2}\\:\\d{2}|Z";case 4:return"GMT[\\+\\-]\\d{2}\\:\\d{2}|GMT";default:return"[\\+\\-]\\d{4}"}},input:(e,t)=>t,output:(e,t)=>{const n=e.getTimeZoneOffset();let r=!0,s="";switch(t){case 5:if(!n)return"Z";break;case 4:if(s="GMT",!n)return s;break;default:r=!1}return s+H(n,r)}},O:{key:"timeZone",regex:(e,t)=>4===t?"GMT[\\+\\-]\\d{2}\\:\\d{2}|GMT":"GMT[\\+\\-]\\d{2}|GMT",input:(e,t)=>t,output:(e,t)=>{const n=e.getTimeZoneOffset();if(!n)return"GMT";let r=!1;return 4===t||(r=!0),"GMT"+H(n,!0,r)}},V:{key:"timeZone",regex:e=>"([a-zA-Z_/]+)",input:(e,t)=>t,output:e=>e.getTimeZone()},X:{key:"timeZone",regex:(e,t)=>{switch(t){case 5:case 3:return"[\\+\\-]\\d{2}\\:\\d{2}|Z";case 4:case 2:return"[\\+\\-]\\d{4}|Z";default:return"[\\+\\-]\\d{2}(?:\\d{2})?|Z"}},input:(e,t)=>t,output:(e,t)=>{const n=e.getTimeZoneOffset();if(!n)return"Z";let r;switch(t){case 5:case 3:r=!0;break;default:r=!1}return H(n,r,1===t)}},x:{key:"timeZone",regex:(e,t)=>{switch(t){case 5:case 3:return"[\\+\\-]\\d{2}\\:\\d{2}";case 4:case 2:return"[\\+\\-]\\d{4}";default:return"[\\+\\-]\\d{2}(?:\\d{2})?"}},input:(e,t)=>t,output:(e,t)=>{let n;switch(t){case 5:case 3:n=!0;break;default:n=!1}return H(e.getTimeZoneOffset(),n,1===t)}}};function F(e,t,n){return new Array(t-1).fill().reduce(((t,n,r)=>t+G(e,r+1)),n)}function G(e,t){const n=new Date(Date.UTC(e,t-1));return t=n.getUTCMonth(),f[t]+(1==t&&N(n.getUTCFullYear())?1:0)}function P(e){return N(e)?366:365}function N(e){return 29===new Date(e,1,29).getDate()}U.dayOfYear=F,U.daysInMonth=G,U.daysInYear=P,U.fromArray=function(e,t={}){const n=e.slice(0,3),r=e.slice(3);return n.length<3&&n.push(...new Array(3-n.length).fill(1)),r.length<4&&r.push(...new Array(4-r.length).fill(0)),new U(null,t).setTimestamp(0).setYear(...n).setHours(...r)},U.fromDate=function(e,t={}){return new U(e.getTime(),t)},U.fromFormat=function(e,t,n={}){"locale"in n||(n.locale=i.defaultLocale);const r=[];let s;for(;e&&(s=e.match(l));){const i=s[1],o=s.index,a=s[0].length;if(o&&T(e.substring(0,o),t),e=e.substring(o+a),t=t.substring(o),!i){const e=s[0].slice(1,-1);T(e||"'",t),t=t.substring(e.length);continue}if(!(i in E))throw new Error(`Invalid token in DateTime format: ${i}`);const u=E[i].regex(n.locale,a),c=t.match(new RegExp(`^${u}`));if(!c)throw new Error(`Unmatched token in DateTime string: ${i}`);const h=c[0],l=E[i].input(n.locale,h,a);if(null!==l){const e=E[i].key;r.push({key:e,value:l,literal:h,token:i,length:a})}t=t.substring(h.length)}e&&T(e,t),"timeZone"in n||(n.timeZone=i.defaultTimeZone);let o=n.timeZone;for(const{key:e,value:t}of r)"timeZone"===e&&(o=t);let a=this.fromTimestamp(0,{locale:n.locale}).setYear(1).setTimeZone(o);const u=function(){let e=!1,t=!0;return{date:{get:e=>e.getDate(),set:(e,t)=>e.setDate(t)},dayPeriod:{get:e=>e.getHours()<12?0:1,set:(n,r)=>{e=r;let s=r?12:0;return t&&(s+=n.getHours()),n.setHours(s)}},dayOfYear:{get:e=>e.getDayOfYear(),set:(e,t)=>e.setDayOfYear(t)},era:{get:e=>e.getYear()<1?0:1,set:(e,t)=>{const n=t?1:-1;return e.setYear(e.getYear()*n)}},hours12:{get:e=>e.getHours()%12,set:(n,r)=>(e&&(r+=12),t=!0,n.setHours(r))},hours24:{get:e=>e.getHours(),set:(e,n)=>(t=!1,e.setHours(n))},milliseconds:{get:e=>e.getMilliseconds(),set:(e,t)=>e.setMilliseconds(t)},minutes:{get:e=>e.getMinutes(),set:(e,t)=>e.setMinutes(t)},month:{get:e=>e.getMonth(),set:(e,t)=>e.setMonth(t)},quarter:{get:e=>e.getQuarter(),set:(e,t)=>e.setQuarter(t)},seconds:{get:e=>e.getSeconds(),set:(e,t)=>e.setSeconds(t)},week:{get:e=>e.getWeek(),set:(e,t)=>e.setWeek(t)},weekDay:{get:e=>e.getWeekDay(),set:(e,t)=>e.setWeekDay(t)},weekDayInMonth:{get:e=>e.getWeekDayInMonth(),set:(e,t)=>e.setWeekDayInMonth(t)},weekOfMonth:{get:e=>e.getWeekOfMonth(),set:(e,t)=>e.setWeekOfMonth(t)},weekYear:{get:e=>e.getWeekYear(),set:(e,t)=>e.setWeekYear(t)},year:{get:e=>{const t=e.getYear();return Math.abs(t)},set:(e,t)=>e.setYear(t)}}}(),c=[];for(const e of m)for(const t of e)if("era"!==t||r.find((e=>"year"===e.key)))for(const e of r){const{key:n,value:r,literal:s,token:i,length:o}=e;if(n===t){if(5===o&&["M","L","E","e","c"].includes(i)){const e=i.repeat(o);if(a.format(e)===s)continue}a=u[n].set(a,r),c.push(e)}}let h=!0;for(const{key:e,value:t}of c)if(e in u&&u[e].get(a)!==t){h=!1;break}return n.timeZone!==o&&(a=a.setTimeZone(n.timeZone)),a.isValid=h,a},U.fromISOString=function(e,t={}){let n=this.fromFormat(u,e,{locale:"en"});return"timeZone"in t&&(n=n.setTimeZone(t.timeZone)),"locale"in t&&(n=n.setLocale(t.locale)),n},U.fromTimestamp=function(e,t={}){return new U(null,t).setTimestamp(e)},U.getDefaultLocale=function(){return i.defaultLocale},U.getDefaultTimeZone=function(){return i.defaultTimeZone},U.isLeapYear=N,U.now=function(e={}){return new U(null,e)},U.setDateClamping=function(e){i.clampDates=e},U.setDefaultLocale=function(e){i.defaultLocale=e},U.setDefaultTimeZone=function(e){i.defaultTimeZone=e};const q=U.prototype;return q.add=function(e,t){return w(this,e,t)},q.dayName=function(e="long"){return O(this.getLocale(),this.getDay(),e)},q.dayPeriod=function(e="long"){return function(e,t,n="long"){return M(e,n)[t]}(this.getLocale(),this.getHours()<12?0:1,e)},q.daysInMonth=function(){return G(this.getYear(),this.getMonth())},q.daysInYear=function(){return P(this.getYear())},q.diff=function(e,t,n=!0){if(e||(e=new this.constructor),!t)return this-e;switch(t&&(t=t.toLowerCase()),e=e.setTimeZone(this.getTimeZone()),t){case"year":case"years":const t=this.getYear()-e.getYear();return y(this,e.setYear(this.getYear()),t,!n,-1);case"month":case"months":const r=12*(this.getYear()-e.getYear())+this.getMonth()-e.getMonth();return y(this,e.setYear(this.getYear(),this.getMonth()),r,!n,-1);case"week":case"weeks":const s=(this-e)/6048e5;return y(this,e.setWeekYear(this.getWeekYear(),this.getWeek()),s,n);case"day":case"days":const i=(this-e)/864e5;return y(this,e.setYear(this.getYear(),this.getMonth(),this.getDate()),i,n);case"hour":case"hours":const o=(this-e)/36e5;return y(this,e.setYear(this.getYear(),this.getMonth(),this.getDate()).setHours(this.getHours()),o,n);case"minute":case"minutes":const a=(this-e)/6e4;return y(this,e.setYear(this.getYear(),this.getMonth(),this.getDate()).setHours(this.getHours(),this.getMinutes()),a,n);case"second":case"seconds":const u=(this-e)/1e3;return y(this,e.setYear(this.getYear(),this.getMonth(),this.getDate()).setHours(this.getHours(),this.getMinutes(),this.getSeconds()),u,n);default:throw new Error("Invalid time unit supplied")}},q.endOf=function(e){switch(e=e.toLowerCase()){case"second":return this.setMilliseconds(999);case"minute":return this.setSeconds(59,999);case"hour":return this.setMinutes(59,59,999);case"day":return this.setHours(23,59,59,999);case"week":return this.setWeekDay(7).setHours(23,59,59,999);case"month":return this.setDate(this.daysInMonth()).setHours(23,59,59,999);case"quarter":const e=3*this.getQuarter();return this.setMonth(e,G(this.getYear(),e)).setHours(23,59,59,999);case"year":return this.setMonth(12,31).setHours(23,59,59,999);default:throw new Error("Invalid time unit supplied")}},q.era=function(e="long"){return function(e,t,n="long"){return Y(e,n)[t]}(this.getLocale(),this.getYear()<0?0:1,e)},q.format=function(e){let t,n="";for(;e&&(t=e.match(l));){const r=t[1],s=t.index,i=t[0].length;if(s&&(n+=e.substring(0,s)),e=e.substring(s+i),r){if(!(r in E))throw new Error(`Invalid token in DateTime format: ${r}`);n+=E[r].output(this,i)}else n+=t[0].slice(1,-1)}return n+=e,n},q.getDate=function(){return new Date(k(this)).getUTCDate()},q.getDay=function(){return new Date(k(this)).getUTCDay()},q.getDayOfYear=function(){return F(this.getYear(),this.getMonth(),this.getDate())},q.getHours=function(){return new Date(k(this)).getUTCHours()},q.getMilliseconds=function(){return new Date(k(this)).getUTCMilliseconds()},q.getMinutes=function(){return new Date(k(this)).getUTCMinutes()},q.getMonth=function(){return new Date(k(this)).getUTCMonth()+1},q.getQuarter=function(){return Math.ceil(this.getMonth()/3)},q.getSeconds=function(){return new Date(k(this)).getUTCSeconds()},q.getTimestamp=function(){return Math.floor(this.getTime()/1e3)},q.getWeek=function(){const e=this.startOf("day").setWeekDay(1),t=e.setWeek(1,1);return 1+((e-t)/6048e5|0)},q.getWeekDay=function(){return v(this.getLocale(),this.getDay())},q.getWeekDayInMonth=function(){const e=this.getWeek(),t=this.setDate(1),n=t.getWeek(),r=t.getWeekDay()>this.getWeekDay()?0:1;return n>e?e+r:e-n+r},q.getWeekOfMonth=function(){const e=this.getWeek(),t=this.setDate(1).getWeek();return t>e?e+1:e-t+1},q.getWeekYear=function(){const e=_(this.getLocale());return this.setWeekDay(7-e+1).getYear()},q.getYear=function(){return new Date(k(this)).getUTCFullYear()},q.humanDiff=function(e,n){const r=(s=this.getLocale(),"RelativeTimeFormat"in Intl?t(`relativeFormatter.${s}`,(e=>new Intl.RelativeTimeFormat(s,{numeric:"auto",style:"long"}))):null);var s;if(!r)throw new Error("RelativeTimeFormat not supported");let i;return e||(e=new this.constructor),n?i=this.diff(e,n):[i,n]=function(e,t){let n;for(const r of["year","month","week","day","hour","minute","second"]){const s=e.diff(t,r);if(n&&d[r]&&Math.abs(s)>=d[r])return n;if(e.diff(t,r,!1))return[s,r];n=s?[s,r]:null}return n||[0,"second"]}(this,e),r.format(i,n)},q.isAfter=function(e,t){return this.diff(e,t)>0},q.isBefore=function(e,t){return this.diff(e,t)<0},q.isBetween=function(e,t,n){return this.diff(e,n)>0&&this.diff(t,n)<0},q.isDST=function(){if(!this._dynamicTz)return!1;const e=this.getYear(),t=U.fromArray([e,1,1],{timeZone:this.getTimeZone()}),n=U.fromArray([e,6,1],{timeZone:this.getTimeZone()});return this.getTimeZoneOffset()<Math.max(t.getTimeZoneOffset(),n.getTimeZoneOffset())},q.isLeapYear=function(){return N(this.getYear())},q.isSame=function(e,t){return 0===this.diff(e,t)},q.isSameOrAfter=function(e,t){return this.diff(e,t)>=0},q.isSameOrBefore=function(e,t){return this.diff(e,t)<=0},q.monthName=function(e="long"){return C(this.getLocale(),this.getMonth(),e)},q.setDate=function(e){return D(this,new Date(k(this)).setUTCDate(e))},q.setDay=function(e){return D(this,new Date(k(this)).setUTCDate(this.getDate()-this.getDay()+parseInt(e)))},q.setDayOfYear=function(e){return D(this,new Date(k(this)).setUTCMonth(0,e))},q.setHours=function(...e){return D(this,new Date(k(this)).setUTCHours(...e))},q.setMilliseconds=function(e){return D(this,new Date(k(this)).setUTCMilliseconds(e))},q.setMinutes=function(...e){return D(this,new Date(k(this)).setUTCMinutes(...e))},q.setMonth=function(e,t=null){return null===t&&(t=this.getDate(),i.clampDates&&(t=Math.min(t,G(this.getYear(),e)))),D(this,new Date(k(this)).setUTCMonth(e-1,t))},q.setQuarter=function(e){return D(this,new Date(k(this)).setUTCMonth(3*e-3))},q.setSeconds=function(...e){return D(this,new Date(k(this)).setUTCSeconds(...e))},q.setTimestamp=function(e){return this.setTime(1e3*e)},q.setWeek=function(e,t=null){null===t&&(t=this.getWeekDay());const n=_(this.getLocale());return this.setYear(this.getWeekYear(),1,n+7*(e-1)).setWeekDay(t)},q.setWeekDay=function(e){return D(this,new Date(k(this)).setUTCDate(this.getDate()-this.getWeekDay()+parseInt(e)))},q.setWeekDayInMonth=function(e){return this.setDate(this.getDate()+7*(e-this.getWeekDayInMonth()))},q.setWeekOfMonth=function(e){return this.setDate(this.getDate()+7*(e-this.getWeekOfMonth()))},q.setWeekYear=function(e,t=null,n=null){const r=_(this.getLocale());return null===t&&(t=Math.min(this.getWeek(),U.fromArray([e,1,r]).weeksInYear())),null===n&&(n=this.getWeekDay()),this.setYear(e,1,r+7*(t-1)).setWeekDay(n)},q.setYear=function(e,t=null,n=null){return null===t&&(t=this.getMonth()),null===n&&(n=this.getDate(),i.clampDates&&(n=Math.min(n,G(this.getYear(),t)))),D(this,new Date(k(this)).setUTCFullYear(e,t-1,n))},q.startOf=function(e){switch(e=e.toLowerCase()){case"second":return this.setMilliseconds(0);case"minute":return this.setSeconds(0,0);case"hour":return this.setMinutes(0,0,0);case"day":return this.setHours(0,0,0,0);case"week":return this.setWeekDay(1).setHours(0,0,0,0);case"month":return this.setDate(1).setHours(0,0,0,0);case"quarter":const e=3*this.getQuarter()-2;return this.setMonth(e,1).setHours(0,0,0,0);case"year":return this.setMonth(1,1).setHours(0,0,0,0);default:throw new Error("Invalid time unit supplied")}},q.sub=function(e,t){return w(this,-e,t)},q.timeZoneName=function(e="long"){return this._dynamicTz?function(e,t,n,s="long"){return r(e,{second:"numeric",timeZone:n,timeZoneName:s}).formatToParts(t).find((e=>"timeZoneName"===e.type)).value}(this.getLocale(),this.getTime(),this.getTimeZone(),e):"GMT"+H(this.getTimeZoneOffset(),!0,"short"===e)},q.toDateString=function(){return this.format(a)},q.toISOString=function(){return this.setLocale("en").setTimeZone("UTC").format(u)},q.toString=function(){return this.format(c)},q.toTimeString=function(){return this.format(h)},q.toUTCString=function(){return this.setLocale("en").setTimeZone("UTC").toString()},q.weeksInYear=function(){const e=_(this.getLocale());return this.setMonth(12,24+e).getWeek()},U}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).DateTime=t()}(this,(function(){"use strict";const e={};function t(t,n){return t in e||(e[t]=n()),e[t]}function n(e){return t(`dateFormatter.${e}`,(t=>r("en",{timeZone:e,hourCycle:"h23",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric"})))}function r(e,t){return new Intl.DateTimeFormat(e,{timeZone:"UTC",...t})}const s=(new Intl.DateTimeFormat).resolvedOptions(),i={clampDates:!0,defaultLocale:s.locale,defaultTimeZone:s.timeZone},o=/\s(?:UTC|GMT|Z|[\+\-]\d)|\d{4}\-\d{2}\-\d{2}T\d{2}\:\d{2}\:\d{2}\.\d{3}[\+\-]\d{2}\:\d{2}/i,a="eee MMM dd yyyy",u="yyyy-MM-dd'T'HH:mm:ss.SSSxxx",c="eee MMM dd yyyy HH:mm:ss xx (VV)",h="HH:mm:ss xx (VV)",l=/([a-z])\1*|'[^']*'/i,f=[31,28,31,30,31,30,31,31,30,31,30,31],g=/(?:GMT)?([\+\-])(\d{2})(\:?)(\d{2})?/,m=[["year","weekYear"],["era"],["quarter","month","week","dayOfYear"],["weekOfMonth"],["date","weekDay"],["weekDayInMonth"],["hours24","hours12","dayPeriod"],["minutes","seconds","milliseconds"]],d={month:12,week:null,day:7,hour:24,minute:60,second:60};function y(e,t,n,r=!0,s=1){return n>0?(n=Math.floor(n),r&&e<t&&(n+=s)):n<0&&(n=Math.ceil(n),r&&e>t&&(n-=s)),n}function p(e){const t=e.getTimeZone();if("UTC"===t)return 0;const r=n("UTC").format(e),s=n(t).format(e);return(new Date(r)-new Date(s))/6e4}function k(e){return e.getTime()-6e4*e.getTimeZoneOffset()}function w(e,t,n){switch(n=n.toLowerCase()){case"second":case"seconds":return e.setSeconds(e.getSeconds()+t);case"minute":case"minutes":return e.setMinutes(e.getMinutes()+t);case"hour":case"hours":return e.setHours(e.getHours()+t);case"week":case"weeks":return e.setDate(e.getDate()+7*t);case"day":case"days":return e.setDate(e.getDate()+t);case"month":case"months":return e.setMonth(e.getMonth()+t);case"year":case"years":return e.setYear(e.getYear()+t);default:throw new Error("Invalid time unit supplied")}}function T(e,t){let n=0;for(const r of e){if(r!==t[n])throw new Error(`Unmatched character in DateTime string: ${r}`);n++}}function D(e,t){return e.setTime(t+6e4*e.getTimeZoneOffset())}function M(e,n="long"){return t(`periods.${e}.${n}`,(t=>{const n=r(e,{hour:"numeric",hourCycle:"h11"});return new Array(2).fill().map(((e,t)=>n.formatToParts(Date.UTC(2018,0,1,12*t)).find((e=>"dayPeriod"===e.type)).value))}))}function Z(e,n="long",s=!0){return t(`days.${e}.${n}.${s}`,(t=>{if(s){const t=r(e,{weekday:n});return new Array(7).fill().map(((e,n)=>t.format(Date.UTC(2018,0,n))))}const i=r(e,{year:"numeric",month:"numeric",day:"numeric",weekday:n});return new Array(7).fill().map(((e,t)=>i.formatToParts(Date.UTC(2018,0,t)).find((e=>"weekday"===e.type)).value))}))}function Y(e,n="long"){return t(`eras.${e}.${n}`,(t=>{const s=r(e,{era:n});return new Array(2).fill().map(((e,t)=>s.formatToParts(Date.UTC(t-1,0,1)).find((e=>"era"===e.type)).value))}))}function L(e,n="long",s=!0){return t(`months.${e}.${n}.${s}`,(t=>{if(s){const t=r(e,{month:n});return new Array(12).fill().map(((e,n)=>t.format(Date.UTC(2018,n,1))))}const i=r(e,{year:"numeric",month:n,day:"numeric"});return new Array(12).fill().map(((e,t)=>i.formatToParts(Date.UTC(2018,t,1)).find((e=>"month"===e.type)).value))}))}function x(e){return t(`numbers.${e}`,(t=>{const n=r(e,{minute:"numeric"});return new Array(10).fill().map(((e,t)=>n.format(Date.UTC(2018,0,1,0,t))))}))}function U(e){return`(?:${x(e).join("|")})+`}function W(e,t,n="long",r=!0){return Z(e,n,r)[t]}function O(e,t,n="long",r=!0){return L(e,n,r)[t-1]}function C(e,t,n=0){const r=x(e);return`${t}`.padStart(n,0).replace(/\d/g,(e=>r[e]))}function b(e,t=!0,n=!1){const r=Math.abs(e/60|0),s=Math.abs(e%60),i=e>0?"-":"+",o=`${r}`.padStart(2,0),a=s||!n?`${s}`.padStart(2,0):"";return`${i}${o}${t&&a?":":""}${a}`}class H{constructor(e=null,t={}){let n,r=!1;if(null===e)n=Date.now();else if(!isNaN(parseInt(e))&&isFinite(e))n=e;else{if(e!==`${e}`)throw new Error("Invalid date supplied");if(n=Date.parse(e),isNaN(n))throw new Error("Invalid date string supplied");e.match(o)||(n-=6e4*(new Date).getTimezoneOffset()),r=!0}this._date=new Date(n),this._dynamicTz=!1,this.isValid=!0;let s=t.timeZone;s||(s=i.defaultTimeZone),["Z","GMT"].includes(s)&&(s="UTC");const a=s.match(g);if(a?(this._offset=60*a[2]+parseInt(a[4]||0),this._offset&&"+"===a[1]&&(this._offset*=-1),this._offset?this._timeZone=b(this._offset):(this._dynamicTz=!0,this._timeZone="UTC")):(this._dynamicTz=!0,this._timeZone=s),this._dynamicTz&&(this._offset=p(this)),r&&this._offset){const e=this._offset;this._date.setTime(this.getTime()+6e4*this._offset),this._dynamicTz&&(this._offset=p(this),e!==this._offset&&this._date.setTime(this.getTime()-6e4*(e-offset)))}"locale"in t||(t.locale=i.defaultLocale),this._locale=t.locale}getLocale(){return this._locale}getTime(){return this._date.getTime()}getTimeZone(){return this._timeZone}getTimeZoneOffset(){return this._offset}setLocale(e){return new H(this.getTime(),{locale:e,timeZone:this._timeZone})}setTime(e){return new H(e,{locale:this._locale,timeZone:this._timeZone})}setTimeZone(e){return new H(this.getTime(),{locale:this._locale,timeZone:e})}setTimeZoneOffset(e){return new H(this.getTime(),{locale:this._locale,timeZone:b(e)})}valueOf(){return this.getTime()}[Symbol.toPrimitive](e){return"number"===e?this.valueOf():this.toString()}}const I={1:["af","am","ar-il","ar-sa","ar-ye","as","bn","bo","brx","ccp","ceb","chr","dav","dz","ebu","en","fil","gu","guz","haw","he","hi","id","ii","ja","jv","kam","ki","kln","km","kn","ko","kok","ks","lkt","lo","luo","luy","mas","mer","mgh","ml","mr","mt","my","nd","ne","om","or","pa","ps-pk","pt","qu","saq","sd","seh","sn","ta","te","th","ti","ug","ur","xh","yue","zh","zu"],7:["ar","ckb","en-ae","en-sd","fa","kab","lrc","mzn","ps"]},S={4:["ast","bg","br","ca","ce","cs","cy","da","de","dsb","el","en-at","en-be","en-ch","en-de","en-dk","en-fi","en-fj","en-gb","en-gg","en-gi","en-ie","en-im","en-je","en-nl","en-se","es","et","eu","fi","fo","fr","fur","fy","ga","gd","gl","gsw","gv","hsb","hu","is","it","ksh","kw","lb","lt","nb","nds","nl","nn","os-ru","pl","pt-ch","pt-lu","pt-pt","rm","ru","sah","se","sk","smn","sv","tt","wae"]};function $(e){switch(e){case 5:return"narrow";case 4:return"long";default:return"short"}}function _(e){return t(`minimumDays.${e}`,(t=>{let n=1;const r=e.toLowerCase().split("-");for(;1===n&&r.length;){for(const e in S)if({}.hasOwnProperty.call(S,e)&&S[e].includes(r.join("-"))){n=parseInt(e);break}r.pop()}return n}))}function v(e,n){return(7+parseInt(n)-function(e){return t(`weekStartOffset.${e}`,(t=>{let n;const r=e.toLowerCase().split("-");for(;!n&&r.length;){for(const e in I)if({}.hasOwnProperty.call(I,e)&&I[e].includes(r.join("-"))){n=parseInt(e);break}r.pop()}return n?n-2:0}))}(e))%7||7}function A(e,t,n="long",r=!0){return v(e,Z(e,n,r).indexOf(t)||7)}function z(e,t,n="long",r=!0){return L(e,n,r).indexOf(t)+1}function j(e,t){const n=x(e);return parseInt(`${t}`.replace(/./g,(e=>n.indexOf(e))))}var E={G:{key:"era",maxLength:5,regex:(e,t)=>Y(e,$(t)).join("|"),input:(e,t,n)=>function(e,t,n="long"){return Y(e,n).indexOf(t)}(e,t,$(n)),output:(e,t)=>{const n=$(t);return e.era(n)}},y:{key:"year",regex:e=>U(e),input:(e,t,n)=>(t=j(e,t),2!==n||2!==`${t}`.length?t:t>40?1900+t:2e3+t),output:(e,t)=>{let n=e.getYear();return 2===t&&(n=`${n}`.slice(-2)),C(e.getLocale(),Math.abs(n),t)}},Y:{key:"weekYear",regex:e=>U(e),input:(e,t,n)=>(t=j(e,t),2!==n||2!==`${t}`.length?t:t>40?1900+t:2e3+t),output:(e,t)=>{let n=e.getWeekYear();return 2===t&&(n=`${n}`.slice(-2)),C(e.getLocale(),Math.abs(n),t)}},Q:{key:"quarter",regex:e=>U(e),input:(e,t)=>j(e,t),output:(e,t)=>C(e.getLocale(),e.getQuarter(),t)},q:{key:"quarter",regex:e=>U(e),input:(e,t)=>j(e,t),output:(e,t)=>C(e.getLocale(),e.getQuarter(),t)},M:{key:"month",regex:(e,t)=>{switch(t){case 5:case 4:case 3:return L(e,$(t),!1).join("|");default:return U(e)}},input:(e,t,n)=>{switch(n){case 5:return null;case 4:case 3:return z(e,t,$(n),!1);default:return j(e,t)}},output:(e,t)=>{const n=e.getLocale(),r=e.getMonth();switch(t){case 5:case 4:case 3:return O(n,r,$(t),!1);default:return C(n,r,t)}}},L:{key:"month",regex:(e,t)=>{switch(t){case 5:case 4:case 3:return L(e,$(t)).join("|");default:return U(e)}},input:(e,t,n)=>{switch(n){case 5:return null;case 4:case 3:return z(e,t,$(n));default:return j(e,t)}},output:(e,t)=>{const n=e.getLocale(),r=e.getMonth();switch(t){case 5:case 4:case 3:return O(n,r,$(t));default:return C(n,r,t)}}},w:{key:"week",regex:e=>U(e),input:(e,t)=>j(e,t),output:(e,t)=>C(e.getLocale(),e.getWeek(),t)},W:{key:"weekOfMonth",regex:e=>U(e),input:(e,t)=>j(e,t),output:e=>C(e.getLocale(),e.getWeekOfMonth())},d:{key:"date",regex:e=>U(e),input:(e,t)=>j(e,t),output:(e,t)=>C(e.getLocale(),e.getDate(),t)},D:{key:"dayOfYear",regex:e=>U(e),input:(e,t)=>j(e,t),output:(e,t)=>C(e.getLocale(),e.getDayOfYear(),t)},F:{key:"weekDayInMonth",regex:e=>U(e),input:(e,t)=>j(e,t),output:e=>C(e.getLocale(),e.getWeekDayInMonth())},E:{key:"weekDay",regex:(e,t)=>Z(e,$(t),!1).join("|"),input:(e,t,n)=>5===n?null:A(e,t,$(n),!1),output:(e,t)=>{const n=$(t);return W(e.getLocale(),e.getDay(),n,!1)}},e:{key:"weekDay",maxLength:5,regex:(e,t)=>{switch(t){case 5:case 4:case 3:return Z(e,$(t),!1).join("|");default:return U(e)}},input:(e,t,n)=>{switch(n){case 5:return null;case 4:case 3:return A(e,t,$(n),!1);default:return j(e,t)}},output:(e,t)=>{const n=e.getLocale();switch(t){case 5:case 4:case 3:const r=$(t);return W(n,e.getDay(),r,!1);default:return C(n,e.getWeekDay(),t)}}},c:{key:"weekDay",maxLength:5,regex:(e,t)=>{switch(t){case 5:case 4:case 3:return Z(e,$(t)).join("|");default:return U(e)}},input:(e,t,n)=>{switch(n){case 5:return null;case 4:case 3:return A(e,t,$(n));default:return j(e,t)}},output:(e,t)=>{const n=e.getLocale();switch(t){case 5:case 4:case 3:const r=$(t);return W(n,e.getDay(),r);default:return C(n,e.getWeekDay())}}},a:{key:"dayPeriod",regex:(e,t)=>M(e,$(t)).join("|"),input:(e,t,n)=>function(e,t,n="long"){return M(e,n).indexOf(t)}(e,t,$(n)),output:(e,t)=>{const n=$(t);return e.dayPeriod(n)}},h:{key:"hours12",regex:e=>U(e),input:(e,t)=>(12===(t=j(e,t))&&(t=0),t),output:(e,t)=>C(e.getLocale(),e.getHours()%12||12,t)},H:{key:"hours24",regex:e=>U(e),input:(e,t)=>j(e,t),output:(e,t)=>C(e.getLocale(),e.getHours(),t)},K:{key:"hours12",regex:e=>U(e),input:(e,t)=>j(e,t),output:(e,t)=>C(e.getLocale(),e.getHours()%12,t)},k:{key:"hours24",regex:e=>U(e),input:(e,t)=>(24===(t=j(e,t))&&(t=0),t),output:(e,t)=>C(e.getLocale(),e.getHours()||24,t)},m:{key:"minutes",regex:e=>U(e),input:(e,t)=>j(e,t),output:(e,t)=>C(e.getLocale(),e.getMinutes(),t)},s:{key:"seconds",regex:e=>U(e),input:(e,t)=>j(e,t),output:(e,t)=>C(e.getLocale(),e.getSeconds(),t)},S:{key:"milliseconds",regex:e=>U(e),input:e=>0,output:(e,t)=>C(e.getLocale(),`${Math.floor(1e3*e.getMilliseconds())}`.padEnd(t,"0").slice(0,t))},z:{output:(e,t)=>{5===t&&(t=1);const n=$(t);return e.timeZoneName(n)}},Z:{key:"timeZone",regex:(e,t)=>{switch(t){case 5:return"[\\+\\-]\\d{2}\\:\\d{2}|Z";case 4:return"GMT[\\+\\-]\\d{2}\\:\\d{2}|GMT";default:return"[\\+\\-]\\d{4}"}},input:(e,t)=>t,output:(e,t)=>{const n=e.getTimeZoneOffset();let r=!0,s="";switch(t){case 5:if(!n)return"Z";break;case 4:if(s="GMT",!n)return s;break;default:r=!1}return s+b(n,r)}},O:{key:"timeZone",regex:(e,t)=>4===t?"GMT[\\+\\-]\\d{2}\\:\\d{2}|GMT":"GMT[\\+\\-]\\d{2}|GMT",input:(e,t)=>t,output:(e,t)=>{const n=e.getTimeZoneOffset();if(!n)return"GMT";let r=!1;return 4===t||(r=!0),"GMT"+b(n,!0,r)}},V:{key:"timeZone",regex:e=>"([a-zA-Z_/]+)",input:(e,t)=>t,output:e=>e.getTimeZone()},X:{key:"timeZone",regex:(e,t)=>{switch(t){case 5:case 3:return"[\\+\\-]\\d{2}\\:\\d{2}|Z";case 4:case 2:return"[\\+\\-]\\d{4}|Z";default:return"[\\+\\-]\\d{2}(?:\\d{2})?|Z"}},input:(e,t)=>t,output:(e,t)=>{const n=e.getTimeZoneOffset();if(!n)return"Z";let r;switch(t){case 5:case 3:r=!0;break;default:r=!1}return b(n,r,1===t)}},x:{key:"timeZone",regex:(e,t)=>{switch(t){case 5:case 3:return"[\\+\\-]\\d{2}\\:\\d{2}";case 4:case 2:return"[\\+\\-]\\d{4}";default:return"[\\+\\-]\\d{2}(?:\\d{2})?"}},input:(e,t)=>t,output:(e,t)=>{let n;switch(t){case 5:case 3:n=!0;break;default:n=!1}return b(e.getTimeZoneOffset(),n,1===t)}}};function F(e,t,n){return new Array(t-1).fill().reduce(((t,n,r)=>t+G(e,r+1)),n)}function G(e,t){const n=new Date(Date.UTC(e,t-1));return t=n.getUTCMonth(),f[t]+(1==t&&N(n.getUTCFullYear())?1:0)}function P(e){return N(e)?366:365}function N(e){return 29===new Date(e,1,29).getDate()}H.dayOfYear=F,H.daysInMonth=G,H.daysInYear=P,H.fromArray=function(e,t={}){const n=e.slice(0,3),r=e.slice(3);return n.length<3&&n.push(...new Array(3-n.length).fill(1)),r.length<4&&r.push(...new Array(4-r.length).fill(0)),new H(null,t).setTimestamp(0).setYear(...n).setHours(...r)},H.fromDate=function(e,t={}){return new H(e.getTime(),t)},H.fromFormat=function(e,t,n={}){"locale"in n||(n.locale=i.defaultLocale);const r=[];let s;for(;e&&(s=e.match(l));){const i=s[1],o=s.index,a=s[0].length;if(o&&T(e.substring(0,o),t),e=e.substring(o+a),t=t.substring(o),!i){const e=s[0].slice(1,-1);T(e||"'",t),t=t.substring(e.length);continue}if(!(i in E))throw new Error(`Invalid token in DateTime format: ${i}`);const u=E[i].regex(n.locale,a),c=t.match(new RegExp(`^${u}`));if(!c)throw new Error(`Unmatched token in DateTime string: ${i}`);const h=c[0],l=E[i].input(n.locale,h,a);if(null!==l){const e=E[i].key;r.push({key:e,value:l,literal:h,token:i,length:a})}t=t.substring(h.length)}e&&T(e,t),"timeZone"in n||(n.timeZone=i.defaultTimeZone);let o=n.timeZone;for(const{key:e,value:t}of r)"timeZone"===e&&(o=t);let a=this.fromTimestamp(0,{locale:n.locale}).setYear(1).setTimeZone(o);const u=function(){let e=!1,t=!0;return{date:{get:e=>e.getDate(),set:(e,t)=>e.setDate(t)},dayPeriod:{get:e=>e.getHours()<12?0:1,set:(n,r)=>{e=r;let s=r?12:0;return t&&(s+=n.getHours()),n.setHours(s)}},dayOfYear:{get:e=>e.getDayOfYear(),set:(e,t)=>e.setDayOfYear(t)},era:{get:e=>e.getYear()<1?0:1,set:(e,t)=>{const n=t?1:-1;return e.setYear(e.getYear()*n)}},hours12:{get:e=>e.getHours()%12,set:(n,r)=>(e&&(r+=12),t=!0,n.setHours(r))},hours24:{get:e=>e.getHours(),set:(e,n)=>(t=!1,e.setHours(n))},milliseconds:{get:e=>e.getMilliseconds(),set:(e,t)=>e.setMilliseconds(t)},minutes:{get:e=>e.getMinutes(),set:(e,t)=>e.setMinutes(t)},month:{get:e=>e.getMonth(),set:(e,t)=>e.setMonth(t)},quarter:{get:e=>e.getQuarter(),set:(e,t)=>e.setQuarter(t)},seconds:{get:e=>e.getSeconds(),set:(e,t)=>e.setSeconds(t)},week:{get:e=>e.getWeek(),set:(e,t)=>e.setWeek(t)},weekDay:{get:e=>e.getWeekDay(),set:(e,t)=>e.setWeekDay(t)},weekDayInMonth:{get:e=>e.getWeekDayInMonth(),set:(e,t)=>e.setWeekDayInMonth(t)},weekOfMonth:{get:e=>e.getWeekOfMonth(),set:(e,t)=>e.setWeekOfMonth(t)},weekYear:{get:e=>e.getWeekYear(),set:(e,t)=>e.setWeekYear(t)},year:{get:e=>{const t=e.getYear();return Math.abs(t)},set:(e,t)=>e.setYear(t)}}}(),c=[];for(const e of m)for(const t of e)if("era"!==t||r.find((e=>"year"===e.key)))for(const e of r){const{key:n,value:r,literal:s,token:i,length:o}=e;if(n===t){if(5===o&&["M","L","E","e","c"].includes(i)){const e=i.repeat(o);if(a.format(e)===s)continue}a=u[n].set(a,r),c.push(e)}}let h=!0;for(const{key:e,value:t}of c)if(e in u&&u[e].get(a)!==t){h=!1;break}return n.timeZone!==o&&(a=a.setTimeZone(n.timeZone)),a.isValid=h,a},H.fromISOString=function(e,t={}){let n=this.fromFormat(u,e,{locale:"en"});return"timeZone"in t&&(n=n.setTimeZone(t.timeZone)),"locale"in t&&(n=n.setLocale(t.locale)),n},H.fromTimestamp=function(e,t={}){return new H(null,t).setTimestamp(e)},H.getDefaultLocale=function(){return i.defaultLocale},H.getDefaultTimeZone=function(){return i.defaultTimeZone},H.isLeapYear=N,H.now=function(e={}){return new H(null,e)},H.setDateClamping=function(e){i.clampDates=e},H.setDefaultLocale=function(e){i.defaultLocale=e},H.setDefaultTimeZone=function(e){i.defaultTimeZone=e};const q=H.prototype;return q.add=function(e,t){return w(this,e,t)},q.dayName=function(e="long"){return W(this.getLocale(),this.getDay(),e)},q.dayPeriod=function(e="long"){return function(e,t,n="long"){return M(e,n)[t]}(this.getLocale(),this.getHours()<12?0:1,e)},q.daysInMonth=function(){return G(this.getYear(),this.getMonth())},q.daysInYear=function(){return P(this.getYear())},q.diff=function(e,{timeUnit:t,relative:n=!0}={}){if(e||(e=new this.constructor),!t)return this-e;switch(t&&(t=t.toLowerCase()),e=e.setTimeZone(this.getTimeZone()),t){case"year":case"years":const t=this.getYear()-e.getYear();return y(this,e.setYear(this.getYear()),t,!n,-1);case"month":case"months":const r=12*(this.getYear()-e.getYear())+this.getMonth()-e.getMonth();return y(this,e.setYear(this.getYear(),this.getMonth()),r,!n,-1);case"week":case"weeks":const s=(this-e)/6048e5;return y(this,e.setWeekYear(this.getWeekYear(),this.getWeek()),s,n);case"day":case"days":const i=(this-e)/864e5;return y(this,e.setYear(this.getYear(),this.getMonth(),this.getDate()),i,n);case"hour":case"hours":const o=(this-e)/36e5;return y(this,e.setYear(this.getYear(),this.getMonth(),this.getDate()).setHours(this.getHours()),o,n);case"minute":case"minutes":const a=(this-e)/6e4;return y(this,e.setYear(this.getYear(),this.getMonth(),this.getDate()).setHours(this.getHours(),this.getMinutes()),a,n);case"second":case"seconds":const u=(this-e)/1e3;return y(this,e.setYear(this.getYear(),this.getMonth(),this.getDate()).setHours(this.getHours(),this.getMinutes(),this.getSeconds()),u,n);default:throw new Error("Invalid time unit supplied")}},q.endOf=function(e){switch(e=e.toLowerCase()){case"second":return this.setMilliseconds(999);case"minute":return this.setSeconds(59,999);case"hour":return this.setMinutes(59,59,999);case"day":return this.setHours(23,59,59,999);case"week":return this.setWeekDay(7).setHours(23,59,59,999);case"month":return this.setDate(this.daysInMonth()).setHours(23,59,59,999);case"quarter":const e=3*this.getQuarter();return this.setMonth(e,G(this.getYear(),e)).setHours(23,59,59,999);case"year":return this.setMonth(12,31).setHours(23,59,59,999);default:throw new Error("Invalid time unit supplied")}},q.era=function(e="long"){return function(e,t,n="long"){return Y(e,n)[t]}(this.getLocale(),this.getYear()<0?0:1,e)},q.format=function(e){let t,n="";for(;e&&(t=e.match(l));){const r=t[1],s=t.index,i=t[0].length;if(s&&(n+=e.substring(0,s)),e=e.substring(s+i),r){if(!(r in E))throw new Error(`Invalid token in DateTime format: ${r}`);n+=E[r].output(this,i)}else n+=t[0].slice(1,-1)}return n+=e,n},q.getDate=function(){return new Date(k(this)).getUTCDate()},q.getDay=function(){return new Date(k(this)).getUTCDay()},q.getDayOfYear=function(){return F(this.getYear(),this.getMonth(),this.getDate())},q.getHours=function(){return new Date(k(this)).getUTCHours()},q.getMilliseconds=function(){return new Date(k(this)).getUTCMilliseconds()},q.getMinutes=function(){return new Date(k(this)).getUTCMinutes()},q.getMonth=function(){return new Date(k(this)).getUTCMonth()+1},q.getQuarter=function(){return Math.ceil(this.getMonth()/3)},q.getSeconds=function(){return new Date(k(this)).getUTCSeconds()},q.getTimestamp=function(){return Math.floor(this.getTime()/1e3)},q.getWeek=function(){const e=this.startOf("day").setWeekDay(1),t=e.setWeek(1,1);return 1+((e-t)/6048e5|0)},q.getWeekDay=function(){return v(this.getLocale(),this.getDay())},q.getWeekDayInMonth=function(){const e=this.getWeek(),t=this.setDate(1),n=t.getWeek(),r=t.getWeekDay()>this.getWeekDay()?0:1;return n>e?e+r:e-n+r},q.getWeekOfMonth=function(){const e=this.getWeek(),t=this.setDate(1).getWeek();return t>e?e+1:e-t+1},q.getWeekYear=function(){const e=_(this.getLocale());return this.setWeekDay(7-e+1).getYear()},q.getYear=function(){return new Date(k(this)).getUTCFullYear()},q.humanDiff=function(e,{timeUnit:n}={}){const r=(s=this.getLocale(),"RelativeTimeFormat"in Intl?t(`relativeFormatter.${s}`,(e=>new Intl.RelativeTimeFormat(s,{numeric:"auto",style:"long"}))):null);var s;if(!r)throw new Error("RelativeTimeFormat not supported");let i;return e||(e=new this.constructor),n?i=this.diff(e,{timeUnit:n}):[i,n]=function(e,t){let n;for(const r of["year","month","week","day","hour","minute","second"]){const s=e.diff(t,{timeUnit:r});if(n&&d[r]&&Math.abs(s)>=d[r])return n;if(e.diff(t,{timeUnit:r,relative:!1}))return[s,r];n=s?[s,r]:null}return n||[0,"second"]}(this,e),r.format(i,n)},q.isAfter=function(e,{granularity:t}={}){return this.diff(e,{timeUnit:t})>0},q.isBefore=function(e,{granularity:t}={}){return this.diff(e,{timeUnit:t})<0},q.isBetween=function(e,t,{granularity:n}={}){return this.diff(e,{timeUnit:n})>0&&this.diff(t,{timeUnit:n})<0},q.isDST=function(){if(!this._dynamicTz)return!1;const e=this.getYear(),t=H.fromArray([e,1,1],{timeZone:this.getTimeZone()}),n=H.fromArray([e,6,1],{timeZone:this.getTimeZone()});return this.getTimeZoneOffset()<Math.max(t.getTimeZoneOffset(),n.getTimeZoneOffset())},q.isLeapYear=function(){return N(this.getYear())},q.isSame=function(e,{granularity:t}={}){return 0===this.diff(e,{timeUnit:t})},q.isSameOrAfter=function(e,{granularity:t}={}){return this.diff(e,{timeUnit:t})>=0},q.isSameOrBefore=function(e,{granularity:t}={}){return this.diff(e,{timeUnit:t})<=0},q.monthName=function(e="long"){return O(this.getLocale(),this.getMonth(),e)},q.setDate=function(e){return D(this,new Date(k(this)).setUTCDate(e))},q.setDay=function(e){return D(this,new Date(k(this)).setUTCDate(this.getDate()-this.getDay()+parseInt(e)))},q.setDayOfYear=function(e){return D(this,new Date(k(this)).setUTCMonth(0,e))},q.setHours=function(...e){return D(this,new Date(k(this)).setUTCHours(...e))},q.setMilliseconds=function(e){return D(this,new Date(k(this)).setUTCMilliseconds(e))},q.setMinutes=function(...e){return D(this,new Date(k(this)).setUTCMinutes(...e))},q.setMonth=function(e,t=null){return null===t&&(t=this.getDate(),i.clampDates&&(t=Math.min(t,G(this.getYear(),e)))),D(this,new Date(k(this)).setUTCMonth(e-1,t))},q.setQuarter=function(e){return D(this,new Date(k(this)).setUTCMonth(3*e-3))},q.setSeconds=function(...e){return D(this,new Date(k(this)).setUTCSeconds(...e))},q.setTimestamp=function(e){return this.setTime(1e3*e)},q.setWeek=function(e,t=null){null===t&&(t=this.getWeekDay());const n=_(this.getLocale());return this.setYear(this.getWeekYear(),1,n+7*(e-1)).setWeekDay(t)},q.setWeekDay=function(e){return D(this,new Date(k(this)).setUTCDate(this.getDate()-this.getWeekDay()+parseInt(e)))},q.setWeekDayInMonth=function(e){return this.setDate(this.getDate()+7*(e-this.getWeekDayInMonth()))},q.setWeekOfMonth=function(e){return this.setDate(this.getDate()+7*(e-this.getWeekOfMonth()))},q.setWeekYear=function(e,t=null,n=null){const r=_(this.getLocale());return null===t&&(t=Math.min(this.getWeek(),H.fromArray([e,1,r]).weeksInYear())),null===n&&(n=this.getWeekDay()),this.setYear(e,1,r+7*(t-1)).setWeekDay(n)},q.setYear=function(e,t=null,n=null){return null===t&&(t=this.getMonth()),null===n&&(n=this.getDate(),i.clampDates&&(n=Math.min(n,G(this.getYear(),t)))),D(this,new Date(k(this)).setUTCFullYear(e,t-1,n))},q.startOf=function(e){switch(e=e.toLowerCase()){case"second":return this.setMilliseconds(0);case"minute":return this.setSeconds(0,0);case"hour":return this.setMinutes(0,0,0);case"day":return this.setHours(0,0,0,0);case"week":return this.setWeekDay(1).setHours(0,0,0,0);case"month":return this.setDate(1).setHours(0,0,0,0);case"quarter":const e=3*this.getQuarter()-2;return this.setMonth(e,1).setHours(0,0,0,0);case"year":return this.setMonth(1,1).setHours(0,0,0,0);default:throw new Error("Invalid time unit supplied")}},q.sub=function(e,t){return w(this,-e,t)},q.timeZoneName=function(e="long"){return this._dynamicTz?function(e,t,n,s="long"){return r(e,{second:"numeric",timeZone:n,timeZoneName:s}).formatToParts(t).find((e=>"timeZoneName"===e.type)).value}(this.getLocale(),this.getTime(),this.getTimeZone(),e):"GMT"+b(this.getTimeZoneOffset(),!0,"short"===e)},q.toDateString=function(){return this.format(a)},q.toISOString=function(){return this.setLocale("en").setTimeZone("UTC").format(u)},q.toString=function(){return this.format(c)},q.toTimeString=function(){return this.format(h)},q.toUTCString=function(){return this.setLocale("en").setTimeZone("UTC").toString()},q.weeksInYear=function(){const e=_(this.getLocale());return this.setMonth(12,24+e).getWeek()},H}));
|