datex.js 1.0.15 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/datex.min.js +3 -3
- package/dist/datex.min.mjs +3 -3
- package/package.json +14 -9
package/dist/datex.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* datex.js v1.0.
|
|
2
|
+
* datex.js v1.0.16
|
|
3
3
|
* a datetime format library
|
|
4
4
|
* https://passer-by.com/datex/
|
|
5
5
|
*
|
|
@@ -8,6 +8,6 @@
|
|
|
8
8
|
* Released under the MIT License
|
|
9
9
|
* https://github.com/mumuy/datex
|
|
10
10
|
*
|
|
11
|
-
* Created on: 2024-
|
|
11
|
+
* Created on: 2024-12-27
|
|
12
12
|
*/
|
|
13
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).datex=e()}(this,(function(){"use strict";function t(e,n){return t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},t(e,n)}function e(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(e=function(){return!!t})()}function n(n,r,o){if(e())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,r);var a=new(n.bind.apply(n,i));return o&&t(a,o.prototype),a}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function o(t){return function(t){if(Array.isArray(t))return r(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return r(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var i=["year","month","day","hour","minute","second","millsecond"],a=[1970,1,1,0,0,0,0],u={year:31536e6,month:2592e6,day:864e5,hour:36e5,minute:6e4,second:1e3,millsecond:1},s={Y:"year",M:"month",D:"day",H:"hour",m:"minute",s:"second",S:"millsecond",W:"week"};function c(t){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},c(t)}function f(t){return null!=t&&("object"==c(t)||"function"==typeof t)}function h(t){return"number"==typeof t&&!isNaN(t)}function l(t){return"string"==typeof t}function m(t){return"function"==typeof t}function g(t){return t instanceof Date}var d=[],p={_date:null,init:function t(){for(var e=arguments.length,r=new Array(e),u=0;u<e;u++)r[u]=arguments[u];var s,c=r.slice(0);if(c.length&&c[0]){if(Object.getPrototypeOf(c[0])==(this instanceof t?this.constructor:void 0))return c[0];if(g(c[0]))this._date=c[0];else{if(s=c[0],Array.isArray(s)?c=a.map((function(t,e){return c[0][e]||t})):f(c[0])&&(c=a.map((function(t,e){return c[0][i[e]]||t}))),1==c.length&&l(c[0])){var m=c[0].match(/(\d{1,4})[\-\/](\d{1,2})[\-\/](\d{1,2})([\sT](\d{1,2})?:(\d{1,2})?(:(\d{1,2}))?(\.(\d{1,3}))?)?/),p=c[0].match(/(\d{1,2})[\-\/](\d{1,2})[\-\/](\d{3,4})([\sT](\d{1,2})?:(\d{1,2})?(:(\d{1,2}))?(\.(\d{1,3}))?)?/),y=c[0].match(/^([12]\d{3})(\d{2})(\d{2})(\d{2})?(\d{2})?(\d{2})?(\d{1,3})?/);m&&!p?c=[1,2,3,5,6,8,10].map((function(t,e){return+(m[t]||a[e])})):p?c=[3,1,2,5,6,8,10].map((function(t,e){return+(p[t]||a[e])})):y&&(c=[1,2,3,4,5,6,7].map((function(t,e){return+(y[t]||a[e])})))}c.length>=3&&c[1]--,this._date=n(Date,o(c)),c.length>=2&&h(c[0])&&c[0]<100&&this._date.setFullYear(c[0])}}else this._date=new Date;var v=this;return d.forEach((function(t){t.bind(v).apply(void 0,r)})),this},onInit:function(t){d.push(t)}};function y(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return n(y.prototype.init,e)}function v(t){var e=function(t,e){if("object"!=c(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=c(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==c(e)?e:e+""}function b(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,v(r.key),r)}}function M(t,e,n){w(t,e),e.set(t,n)}function w(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}function O(t,e){return t.get(j(t,e))}function _(t,e,n){return t.set(j(t,e),n),n}function j(t,e,n){if("function"==typeof t?t===e:t.has(e))return arguments.length<3?e:n;throw new TypeError("Private element is not present on this object")}y.now=Date.now,y.extend=function(t){t(y,p)},y.prototype=p,p.init.prototype=p;var S=new WeakMap,T=new WeakMap,D=new WeakMap,W=new WeakSet,Y=function(){return t=function t(){var e,n;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),w(e=this,n=W),n.add(e),M(this,S,null),M(this,T,null),M(this,D,0);for(var r=this,o=arguments.length,i=new Array(o),a=0;a<o;a++)i[a]=arguments[a];if(2==i.length)f(i[0])&&f(i[1])?(_(S,r,i[0]),_(T,r,i[1]),_(D,r,O(S,r).getTime()-O(T,r).getTime())):h(i[0])&&l(i[1])&&r.change(i[1],i[0]);else if(1==i.length)if(f(i[0]))for(var u in i[0])r.change(u,i[0][u]);else h(i[0])&&_(D,r,O(D,r)+i[0])},e=[{key:"change",value:function(t,e){var n=this;return O(S,n)&&O(T,n)?(O(S,n).change(t,e),_(D,n,O(S,n).getTime()-O(T,n).getTime())):u[t]&&_(D,n,O(D,n)+u[t]*e),n}},{key:"get",value:function(t){var e=this;if(t){if(O(S,e)&&O(T,e)){var n=O(S,e),r=O(T,e),o=O(D,e),i=0;return"month"==t?(i=12*(n.get("year")-1)+n.get("month")-(12*(r.get("year")-1)+r.get("month")))<0&&n.get("day")>r.get("day")?i+=1:i>0&&n.get("day")<r.get("day")&&(i-=1):"year"==t?(i=n.get("year")-r.get("year"))<0&&(n.get("month")>r.get("month")||n.get("month")==r.get("month")&&n.get("day")>r.get("day"))?i+=1:i>0&&(n.get("month")<r.get("month")||n.get("month")==r.get("month")&&n.get("day")<r.get("day"))&&(i-=1):u[t]&&(i=~~(o/u[t])),i}return u[t]&&Math.floor(O(D,e)/u[t])||0}return O(D,e)}},{key:"toObject",value:function(){var t=this;return Object.assign({value:O(D,t)},j(W,t,k).call(t,i))}},{key:"format",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"YYYY-MM-DD HH:mm:ss";if(l(t)){var e=[];t.match(/Y+|M+|D+|H+|m+|s+|S+/g).forEach((function(t){var n=s[t[0]];e.includes(n)||e.push(n)}));var n=j(W,this,k).call(this,e),r={Y:""+n.year,M:""+n.month,D:""+n.day,H:""+n.hour,m:""+n.minute,s:""+n.second,S:""+n.millsecond};return t.replace(/Y+|M+|D+|H+|m+|s+|S+/g,(function(t){if(r[t])return r[t];if(r[t[0]]){var e=r[t[0]]<0,n=Math.abs(r[t[0]]).toString().padStart(t.length,"0");return e?"-"+n:n}return""}))}if(m(t))return t(this.toObject()).toString()||""}}],e&&b(t.prototype,e),n&&b(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n}();function k(t){var e=this,n={};if(O(S,e)&&O(T,e)){var r=O(D,e),o=O(S,e).clone(),i=O(T,e).clone();t.forEach((function(t){n[t]=e.get(t),e.change(t,-n[t])})),_(D,e,r),_(S,e,o),_(T,e,i)}else{var a=O(D,e);t.forEach((function(t){u[t]&&(n[t]=Math.floor(a/u[t])||0,a%=u[t])}))}return n}var A={name:"en-us",format:{MMM:["Jan.","Feb.","Mar.","Apr.","May.","Jun.","Jul.","Aug.","Sept.","Oct.","Nov.","Dec."],MMMM:["January","February","March","April","May","June","July","August","September","October","November","December"],Do:["1st","2nd","3rd","4th","5th","6th","7th","8th","9th","10th","11th","12th","13th","14th","15th","16th","17th","18th","19th","20th","21st","22nd","23rd","24th","25th","26th","27th","28th","29th","30th","31st"],WW:["Sun.","Mon.","Tues.","Wed.","Thur.","Fri.","Sat."],WWW:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},duration:{"past moments":"just now","future moments":"moments later",now:"now"}},L={name:"zh-cn",format:{MMM:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],MMMM:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],Do:["1日","2日","3日","4日","5日","6日","7日","8日","9日","10日","11日","12日","13日","14日","15日","16日","17日","18日","19日","20日","21日","22日","23日","24日","25日","26日","27日","28日","29日","30日","31日"],WW:["周日","周一","周二","周三","周四","周五","周六"],WWW:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]},duration:{"past moments":"刚刚","future moments":"片刻后",now:"现在"}};return[function(t,e){Object.assign(e,{toDate:function(){return this._date},toObject:function(){var t=this._date;return{year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate(),hour:t.getHours(),minute:t.getMinutes(),second:t.getSeconds(),millsecond:t.getMilliseconds(),timestamp:t.getTime(),week:t.getDay()}},toArray:function(){var t=this.toObject();return i.map((function(e){return t[e]}))},toString:function(){return this._date.toString()},toISOString:function(){return this._date.toISOString()},getTime:function(){return this._date.getTime()},getUnix:function(){return~~(this._date.getTime()/1e3)},clone:function(){var e=t(this.getTime());return Object.assign(e,structuredClone(this))},isValid:function(){return h(this.getTime())},set:function(t,e){var n=this._date,r=this.toObject();switch(t){case"year":n.setFullYear(e);break;case"month":n.setMonth(e-1);break;case"day":n.setDate(e);break;case"hour":n.setHours(e);break;case"minute":n.setMinutes(e);break;case"second":n.setSeconds(e);break;case"millsecond":n.setMilliseconds(e);break;case"timestamp":n.setTime(e);break;case"week":n.setDate(r.day-r.week+e)}return this},change:function(t,e){var n=this.toObject();return["day","hour","minute","second","millsecond"].includes(t)?this.set("timestamp",n.timestamp+e*u[t]):this.set(t,n[t]+e)},get:function(t){return this.toObject()[t]},format:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"YYYY-MM-DD HH:mm:ss";if(l(t)){var e=this.clone(),n=e._date,r=e.toObject(),o=n.toTimeString().match(/GMT([\+\-])(\d{2})(\d{2})/),i={YYYY:(""+r.year).padStart(4,"0"),YY:(""+r.year%100).padStart(2,"0"),M:""+r.month,D:""+r.day,H:""+r.hour,h:""+r.hour%12,m:""+r.minute,s:""+r.second,S:""+~~(r.millsecond/100),SS:""+~~(r.millsecond/10),SSS:""+r.millsecond,Z:o[1]+o[2]+":"+o[3],ZZ:o[1]+o[2]+o[3],A:["AM","PM"][~~(r.hour/12)],a:["am","pm"][~~(r.hour/12)],X:r.timestamp,x:~~(r.timestamp/1e3),Q:""+~~(r.month/3),W:r.week};return t.replace(/Y+|M+|Do|D+|H+|h+|m+|s+|S+|Z+|A|a|X|x|Q|W+/g,(function(t){return i[t]||i[t[0]].padStart(t.length,"0")||""}))}if(m(t))return t(this.toObject())||""}})},function(t,e){Object.assign(e,{endOf:function(t){return this.startOf(t).change(t,"week"==t?7:1).change("millsecond",-1)},startOf:function(e){var n=this.toObject(),r=i.indexOf(e)+1,u=this.toArray(),s=a.slice(r);return u.splice.apply(u,[r,s.length].concat(o(s))),"timestamp"==e?this.clone():"week"==e?t(n.year,n.month,n.day-n.week,0,0,0,0):t.apply(void 0,o(u))}})},function(t,e){Object.assign(e,{isAfter:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"timestamp";return e=t(e),this.get(n)>e.get(n)},isBefore:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"timestamp";return e=t(e),this.get(n)<e.get(n)},isBetween:function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"timestamp";return e=t(e),n=t(n),this.get(r)>e.get(r)&&this.get(r)<n.get(r)},isSame:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"timestamp";return e=t(e),this.get(n)==e.get(n)}})},function(t,e){Object.assign(t,{duration:function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return n(Y,e)}}),Object.assign(e,{diffWith:function(e,n){if(!(e=t(e)).isValid())return 0;var r=t.duration(this,e);return n?r.get(n):r},fromNow:function(){var e=t(),n=t.duration(this,e).toObject(),r=n.value<0,o="",i=t.getLanguage(),a=this.getLanguageCode(),u=new Intl.RelativeTimeFormat(a);return["year","month","day","hour","minute","second"].forEach((function(t){var e=n[t];!o&&e&&(o=u.format(e,t))})),o||(o=n.value?r?i.duration["past moments"]:i.duration["future moments"]:i.duration.now),o}})},function(t,e){var n,r={};[A,L].forEach((function(t){r[t.name]=t}));var o=(null===globalThis||void 0===globalThis||null===(n=globalThis.navigator)||void 0===n?void 0:n.language.toLowerCase())||"en-us";Object.assign(t,{setLanguage:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t=t.toLowerCase(),r[t]=Object.assign(r[t]||{},e),this},switchLanguage:function(t){return o=t.toLowerCase(),this},getLanguage:function(){return r[o]},getLanguageCode:function(){return o}}),Object.assign(e,{_langMap:{},_lang:null,setLanguage:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t=t.toLowerCase(),this._langMap[t]=Object.assign(this._langMap[t]||{},e),this},switchLanguage:function(t){return this._lang=t.toLowerCase(),this},getLanguage:function(){return this._langMap[this._lang]},getLanguageCode:function(){return this._lang}}),e.onInit((function(){this._langMap=Object.assign(this._langMap,r),this._lang=o}));var i=e.format;Object.assign(e,{format:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"YYYY-MM-DD HH:mm:ss";if(l(e)){var n=this.clone().toObject(),r=t.getLanguage()||this.getLanguage(),o={};for(var a in o.MMM=r.format.MMM[n.month-1],o.MMMM=r.format.MMMM[n.month-1],o.Do=r.format.Do[n.day-1],o.WW=r.format.WW[n.week],o.WWW=r.format.WWW[n.week],o)e=e.replace(a,o[a]||"")}return i.bind(this)(e)}})},function(t,e){var n=Intl.DateTimeFormat().resolvedOptions().timeZone,r=0,o=function(t,e){return new Date(t.toLocaleString("en-US",{timeZone:e}))},i="1970/1/1";Object.assign(t,{supportedTimezones:"undefined"!=typeof Intl&&Intl.supportedValuesOf?Intl.supportedValuesOf("timeZone"):[],switchTimezone:function(t){return n=t,r=o(new Date(i),n).getTime()-Date.parse(i),this},getTimezoneOffset:function(){return(new Date).getTimezoneOffset()-r/6e4},getTimezone:function(){return n}}),Object.assign(e,{_timezone:null,_offset:0,switchTimezone:function(t){return this._timezone=t,this._offset=o(new Date(i),this._timezone).getTime()-Date.parse(i),this},getTimezoneOffset:function(){return this._date.getTimezoneOffset()-this._offset/6e4},getTimezone:function(){return this._timezone}}),e.onInit((function(){this._timezone=n,this._offset=r,arguments.length&&(arguments.length<=0?void 0:arguments[0])&&(g(arguments.length<=0?void 0:arguments[0])||(arguments.length<=0?void 0:arguments[0])instanceof t||1==arguments.length&&h(arguments.length<=0?void 0:arguments[0])||r&&this._date.setTime(this._date.getTime()-r))}));var a=e.format;Object.assign(e,{format:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"YYYY-MM-DD HH:mm:ss",e=this.clone();return e._date.setTime(e._date.getTime()+e._offset),a.bind(e)(t)}})},function(t,e){var n=t.getLanguage();e.onInit((function(){for(var e=arguments.length,r=new Array(e),o=0;o<e;o++)r[o]=arguments[o];var a=r.slice(0);if(a.length&&a[0]&&2==a.length&&l(a[0])&&l(a[1])){var u=function(e,r){var o=[],a=r.replace(/Y+|M+|Do|D+|H+|h+|m+|s+|S+|Z+|A|a|X|x|Q|W+/g,(function(t,e){if(n.format[t]){if(["MMM","MMMM"].includes(t))return o.push("month"),"("+n.format[t].join("|")+")";if(["Do"].includes(t))return o.push("day"),"("+n.format[t].join("|")+")";if(["WW","WWW"].includes(t))return o.push("week"),"("+n.format[t].join("|")+")"}else{if(s[t[0]])return o.push(s[t[0]]),"(\\d{1,"+t.length+"})";if(["h","hh"].includes(t))return o.push("hour_12"),"(\\d{1,2})";if("ZZ"==t)return o.push("timezone"),"(-?\\d{2}\\d{2})";if("Z"==t)return o.push("timezone"),"(-?\\d{2}:\\d{2})";if("A"==t)return o.push("am_pm"),"(AM|PM)";if("a"==t)return o.push("am_pm"),"(am|pm)";if("X"==t)return o.push("timestamp"),"(d+)";if("x"==t)return o.push("unix"),"(d+)"}return t})),u={},c=e.match(new RegExp(a));c&&c.slice(1).forEach((function(t,e){var n=o[e];u[n]=t}));var f={};return i.forEach((function(t){+u[t]&&(f[t]=+u[t])})),u.hour_12?(f.hour=+u.hour_12,u.am_pm&&["PM","pm"].includes(u.am_pm)&&(f.hour+=12)):u.timestamp?f=t(u.timestamp).toObject():u.unix&&(f=t(1e3*u.unix).toObject()),f}(a[0],a[1]);Object.keys(u).length?this._date=t(u).toDate():this._date=new Date("")}}))}].forEach(y.extend),y}));
|
|
13
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).datex=e()}(this,(function(){"use strict";function t(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(t=function(){return!!e})()}function e(t,n){return e=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},e(t,n)}function n(n,r,i){if(t())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,r);var a=new(n.bind.apply(n,o));return i&&e(a,i.prototype),a}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function i(t,e){if(t){if("string"==typeof t)return r(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}function o(t){return function(t){if(Array.isArray(t))return r(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||i(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var a=["year","month","day","hour","minute","second","millsecond"],u=[1970,1,1,0,0,0,0],s={year:31536e6,month:2592e6,day:864e5,hour:36e5,minute:6e4,second:1e3,millsecond:1},c={Y:"year",M:"month",D:"day",H:"hour",m:"minute",s:"second",S:"millsecond",W:"week"};function f(t){return f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},f(t)}function h(t){return null!=t&&("object"==f(t)||"function"==typeof t)}function l(t){return"number"==typeof t&&!isNaN(t)}function m(t){return"string"==typeof t}function g(t){return"function"==typeof t}function d(t){return t instanceof Date}var p=[],y={_date:null,parse:function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var i,s=e.slice(0);if(s.length&&s[0]){if(Object.getPrototypeOf(s[0])==Object.getPrototypeOf(this))return this._date=s[0].toDate(),s[0];if(d(s[0]))this._date=s[0];else{if(i=s[0],Array.isArray(i)?s=u.map((function(t,e){return s[0][e]||t})):h(s[0])&&(s=u.map((function(t,e){return s[0][a[e]]||t}))),1==s.length&&m(s[0])){var c=s[0].match(/(\d{1,4})[\-\/](\d{1,2})[\-\/](\d{1,2})([\sT](\d{1,2})?:(\d{1,2})?(:(\d{1,2}))?(\.(\d{1,3}))?)?/),f=s[0].match(/(\d{1,2})[\-\/](\d{1,2})[\-\/](\d{3,4})([\sT](\d{1,2})?:(\d{1,2})?(:(\d{1,2}))?(\.(\d{1,3}))?)?/),g=s[0].match(/^([12]\d{3})(\d{2})(\d{2})(\d{2})?(\d{2})?(\d{2})?(\d{1,3})?/);c&&!f?s=[1,2,3,5,6,8,10].map((function(t,e){return+(c[t]||u[e])})):f?s=[3,1,2,5,6,8,10].map((function(t,e){return+(f[t]||u[e])})):g&&(s=[1,2,3,4,5,6,7].map((function(t,e){return+(g[t]||u[e])})))}s.length>=3&&s[1]--,this._date=n(Date,o(s)),s.length>=2&&l(s[0])&&s[0]<100&&this._date.setFullYear(s[0])}}else this._date=new Date;return this},init:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];this.parse.apply(this,e);var r=this;return p.forEach((function(t){t.bind(r).apply(void 0,e)})),this},onInit:function(t){p.push(t)}};function v(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return n(v.prototype.init,e)}function b(t){var e=function(t,e){if("object"!=f(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=f(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==f(e)?e:e+""}function M(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,b(r.key),r)}}function O(t,e,n){w(t,e),e.set(t,n)}function w(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}function _(t,e){return t.get(j(t,e))}function T(t,e,n){return t.set(j(t,e),n),n}function j(t,e,n){if("function"==typeof t?t===e:t.has(e))return arguments.length<3?e:n;throw new TypeError("Private element is not present on this object")}v.now=Date.now,v.extend=function(t){t(v,y)},v.prototype=y,y.init.prototype=y;var S=new WeakMap,D=new WeakMap,W=new WeakSet,A=function(){return t=function t(){var e,n;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),w(e=this,n=W),n.add(e),O(this,S,null),O(this,D,null);var r=this;r.value=0;for(var i=arguments.length,o=new Array(i),a=0;a<i;a++)o[a]=arguments[a];if(2==o.length)h(o[0])&&h(o[1])?(T(S,r,o[0]),T(D,r,o[1]),r.value=_(S,r).getTime()-_(D,r).getTime()):l(o[0])&&m(o[1])&&r.change(o[1],o[0]);else if(1==o.length)if(h(o[0]))for(var u in o[0])r.change(u,o[0][u]);else l(o[0])&&(r.value+=o[0])},e=[{key:"change",value:function(t,e){var n=this;return _(S,n)&&_(D,n)?(_(S,n).change(t,e),n.value=_(S,n).getTime()-_(D,n).getTime()):s[t]&&(n.value+=s[t]*e),n}},{key:"get",value:function(t){var e=this;if(t){if(_(S,e)&&_(D,e)){var n=_(S,e),r=_(D,e),i=e.value,o=0;return"month"==t?(o=12*(n.get("year")-1)+n.get("month")-(12*(r.get("year")-1)+r.get("month")))<0&&n.get("day")>r.get("day")?o+=1:o>0&&n.get("day")<r.get("day")&&(o-=1):"year"==t?(o=n.get("year")-r.get("year"))<0&&(n.get("month")>r.get("month")||n.get("month")==r.get("month")&&n.get("day")>r.get("day"))?o+=1:o>0&&(n.get("month")<r.get("month")||n.get("month")==r.get("month")&&n.get("day")<r.get("day"))&&(o-=1):s[t]&&(o=~~(i/s[t])),o}return s[t]&&Math.floor(e.value/s[t])||0}return e.value}},{key:"toObject",value:function(){var t=this;return Object.assign({value:t.value},j(W,t,k).call(t,a))}},{key:"format",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"YYYY-MM-DD HH:mm:ss";if(m(t)){var e=[];t.match(/Y+|M+|D+|H+|m+|s+|S+/g).forEach((function(t){var n=c[t[0]];e.includes(n)||e.push(n)}));var n=j(W,this,k).call(this,e),r={Y:""+n.year,M:""+n.month,D:""+n.day,H:""+n.hour,m:""+n.minute,s:""+n.second,S:""+n.millsecond};return t.replace(/Y+|M+|D+|H+|m+|s+|S+/g,(function(t){if(r[t])return r[t];if(r[t[0]]){var e=r[t[0]]<0,n=Math.abs(r[t[0]]).toString().padStart(t.length,"0");return e?"-"+n:n}return""}))}if(g(t))return t(this.toObject()).toString()||""}}],e&&M(t.prototype,e),n&&M(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n}();function k(t){var e=this,n={};if(_(S,e)&&_(D,e)){var r=e.value,i=_(S,e).clone(),o=_(D,e).clone();t.forEach((function(t){n[t]=e.get(t),e.change(t,-n[t])})),e.value=r,T(S,e,i),T(D,e,o)}else{var a=e.value;t.forEach((function(t){s[t]&&(n[t]=Math.floor(a/s[t])||0,a%=s[t])}))}return n}var Y={name:"en-us",format:{MMM:["Jan.","Feb.","Mar.","Apr.","May.","Jun.","Jul.","Aug.","Sept.","Oct.","Nov.","Dec."],MMMM:["January","February","March","April","May","June","July","August","September","October","November","December"],Do:["1st","2nd","3rd","4th","5th","6th","7th","8th","9th","10th","11th","12th","13th","14th","15th","16th","17th","18th","19th","20th","21st","22nd","23rd","24th","25th","26th","27th","28th","29th","30th","31st"],WW:["Sun.","Mon.","Tues.","Wed.","Thur.","Fri.","Sat."],WWW:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},duration:{"past moments":"just now","future moments":"moments later",now:"now"}},z={name:"zh-cn",format:{MMM:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],MMMM:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],Do:["1日","2日","3日","4日","5日","6日","7日","8日","9日","10日","11日","12日","13日","14日","15日","16日","17日","18日","19日","20日","21日","22日","23日","24日","25日","26日","27日","28日","29日","30日","31日"],WW:["周日","周一","周二","周三","周四","周五","周六"],WWW:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]},duration:{"past moments":"刚刚","future moments":"片刻后",now:"现在"}};function L(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var r,i,o,a,u=[],s=!0,c=!1;try{if(o=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(r=o.call(n)).done)&&(u.push(r.value),u.length!==e);s=!0);}catch(t){c=!0,i=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw i}}return u}}(t,e)||i(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}return[function(t,e){Object.assign(e,{toDate:function(){return this._date},toObject:function(){var t=this._date;return{year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate(),hour:t.getHours(),minute:t.getMinutes(),second:t.getSeconds(),millsecond:t.getMilliseconds(),timestamp:t.getTime(),week:t.getDay()}},toArray:function(){var t=this.toObject();return a.map((function(e){return t[e]}))},toString:function(){return this._date.toString()},toISOString:function(){return this._date.toISOString()},getTime:function(){return this._date.getTime()},getUnix:function(){return~~(this._date.getTime()/1e3)},clone:function(){var e=t(this.getTime());return Object.assign(e,structuredClone(this))},isValid:function(){return l(this.getTime())},set:function(t,e){var n=this._date,r=this.toObject();switch(t){case"year":n.setFullYear(e);break;case"month":n.setMonth(e-1);break;case"day":n.setDate(e);break;case"hour":n.setHours(e);break;case"minute":n.setMinutes(e);break;case"second":n.setSeconds(e);break;case"millsecond":n.setMilliseconds(e);break;case"timestamp":n.setTime(e);break;case"week":n.setDate(r.day-r.week+e)}return this},change:function(t,e){var n=this.toObject();return["day","hour","minute","second","millsecond"].includes(t)?this.set("timestamp",n.timestamp+e*s[t]):this.set(t,n[t]+e)},get:function(t){return this.toObject()[t]},format:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"YYYY-MM-DD HH:mm:ss";if(m(t)){var e=this._date,n=this.toObject(),r=e.toTimeString().match(/GMT([\+\-])(\d{2})(\d{2})/),i={YYYY:(""+n.year).padStart(4,"0"),YY:(""+n.year%100).padStart(2,"0"),M:""+n.month,D:""+n.day,H:""+n.hour,h:""+n.hour%12,m:""+n.minute,s:""+n.second,S:""+~~(n.millsecond/100),SS:""+~~(n.millsecond/10),SSS:""+n.millsecond,Z:r[1]+r[2]+":"+r[3],ZZ:r[1]+r[2]+r[3],A:["AM","PM"][~~(n.hour/12)],a:["am","pm"][~~(n.hour/12)],X:n.timestamp,x:~~(n.timestamp/1e3),Q:""+~~(n.month/3),W:n.week};return t.replace(/Y+|M+|Do|D+|H+|h+|m+|s+|S+|Z+|A|a|X|x|Q|W+/g,(function(t){return i[t]||i[t[0]].padStart(t.length,"0")||""}))}if(g(t))return t(this.toObject())||""}})},function(t,e){Object.assign(e,{endOf:function(t){return this.startOf(t).change(t,"week"==t?7:1).change("millsecond",-1)},startOf:function(e){var n=this.clone();if("timestamp"==e)return n;if("week"==e){var r=n.toObject();return t(r.year,r.month,r.day-r.week,0,0,0,0)}var i=a.indexOf(e)+1,s=u.slice(i),c=n.toArray();return c.splice.apply(c,[i,s.length].concat(o(s))),t.apply(void 0,o(c))}})},function(t,e){Object.assign(e,{isAfter:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"timestamp";return e=t(e),this.get(n)>e.get(n)},isBefore:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"timestamp";return e=t(e),this.get(n)<e.get(n)},isBetween:function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"timestamp";return e=t(e),n=t(n),this.get(r)>e.get(r)&&this.get(r)<n.get(r)},isSame:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"timestamp";return e=t(e),this.get(n)==e.get(n)}})},function(t,e){Object.assign(t,{duration:function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return n(A,e)}}),Object.assign(e,{diffWith:function(e,n){if(!(e=t(e)).isValid())return 0;var r=t.duration(this,e);return n?r.get(n):r},fromNow:function(){var e=t(),n=t.duration(this,e).toObject(),r=n.value<0,i="",o=t.getLanguage(),a=this.getLanguageCode(),u=new Intl.RelativeTimeFormat(a,{numeric:"auto"});return["year","month","day","hour","minute","second"].forEach((function(t){var e=n[t];!i&&e&&(i=u.format(e,t))})),i||(i=n.value?r?o.duration["past moments"]:o.duration["future moments"]:o.duration.now),i}})},function(t,e){var n,r={};[Y,z].forEach((function(t){r[t.name]=t}));var i=(null===globalThis||void 0===globalThis||null===(n=globalThis.navigator)||void 0===n?void 0:n.language.toLowerCase())||"en-us";Object.assign(t,{setLanguage:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t=t.toLowerCase(),r[t]=Object.assign(r[t]||{},e),this},switchLanguage:function(t){return i=t.toLowerCase(),this},getLanguage:function(){return r[i]},getLanguageCode:function(){return i}}),Object.assign(e,{_langMap:{},_lang:null,setLanguage:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t=t.toLowerCase(),this._langMap[t]=Object.assign(this._langMap[t]||{},e),this},switchLanguage:function(t){return this._lang=t.toLowerCase(),this},getLanguage:function(){return this._langMap[this._lang]},getLanguageCode:function(){return this._lang}}),e.onInit((function(){this._langMap=Object.assign(this._langMap,r),this._lang=i}));var o=e.format;Object.assign(e,{format:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"YYYY-MM-DD HH:mm:ss";if(m(e)){var n=this.clone().toObject(),r=t.getLanguage()||this.getLanguage(),i={};for(var a in i.MMMM=r.format.MMMM[n.month-1],i.MMM=r.format.MMM[n.month-1],i.Do=r.format.Do[n.day-1],i.WWW=r.format.WWW[n.week],i.WW=r.format.WW[n.week],i)e=e.replace(a,i[a]||"")}return o.bind(this)(e)}})},function(t,e){var n=Intl.DateTimeFormat().resolvedOptions().timeZone,r=0,i=function(t,e){var n=e.replace(/\s/g,"").match(/(GMT|UTC)(\+|\-)?(\d{1,2})(\.|:)(\d{1,2})/);if(n){var r=L(n,6);r[0],r[1];var i=r[2],o=r[3],a=r[4],u=r[5],s=0;return s=":"==a?60*Number(o)+Number(u):60*Number(o+a+u),"+"!=i&&i||(s=-s),6e4*(t.getTimezoneOffset()-s)}var c,f,h=(c=t,f=e,new Date(c.toLocaleString("en-US",{timeZone:f}))).getTime()-t.getTime();return h=6e4*Math.ceil(h/6e4)},o=new Date;Object.assign(t,{supportedTimezones:"undefined"!=typeof Intl&&Intl.supportedValuesOf?Intl.supportedValuesOf("timeZone"):[],switchTimezone:function(t){return r=i(o,n=t),this},getTimezoneOffset:function(){return(new Date).getTimezoneOffset()-r/6e4},getTimezone:function(){return n}}),Object.assign(e,{_timezone:null,_offset:0,switchTimezone:function(t){this._timezone=t;var e=this._date||o;return this._offset=i(e,this._timezone),this},getTimezoneOffset:function(){return this._date.getTimezoneOffset()-this._offset/6e4},getTimezone:function(){return this._timezone},isDayLightSavingTime:function(){return this.getTimezoneOffset()<this.clone().set("month",1).getTimezoneOffset()||this.getTimezoneOffset()<this.clone().set("month",6).getTimezoneOffset()}}),e.onInit((function(){this._timezone=n,this._offset=r,arguments.length&&(arguments.length<=0?void 0:arguments[0])&&(d(arguments.length<=0?void 0:arguments[0])||(arguments.length<=0?void 0:arguments[0])instanceof t||1==arguments.length&&l(arguments.length<=0?void 0:arguments[0])||r&&this._date.setTime(this._date.getTime()-r))}));var a=e.set,u=e.toObject;Object.assign(e,{toObject:function(){var t=this.clone();return t._date.setTime(t._date.getTime()+t._offset),u.bind(t)()},set:function(t,e){var n=this._date.getTime();this._date.setTime(n+this._offset);var r=a.bind(this)(t,e),u=r._date||o;return r._offset=i(u,r._timezone),n=r._date.getTime(),r._date.setTime(n-r._offset),r}})},function(t,e){var n=t.getLanguage();e.onInit((function(){for(var e=arguments.length,r=new Array(e),i=0;i<e;i++)r[i]=arguments[i];var o=r.slice(0);if(o.length&&o[0]&&2==o.length&&m(o[0])&&m(o[1])){var u=function(e,r){var i=[],o=r.replace(/Y+|M+|Do|D+|H+|h+|m+|s+|S+|Z+|A|a|X|x|Q|W+/g,(function(t,e){if(n.format[t]){if(["MMM","MMMM"].includes(t))return i.push("month"),"("+n.format[t].join("|")+")";if(["Do"].includes(t))return i.push("day"),"("+n.format[t].join("|")+")";if(["WW","WWW"].includes(t))return i.push("week"),"("+n.format[t].join("|")+")"}else{if(c[t[0]])return i.push(c[t[0]]),"(\\d{1,"+t.length+"})";if(["h","hh"].includes(t))return i.push("hour_12"),"(\\d{1,2})";if("ZZ"==t)return i.push("timezone"),"(-?\\d{2}\\d{2})";if("Z"==t)return i.push("timezone"),"(-?\\d{2}:\\d{2})";if("A"==t)return i.push("am_pm"),"(AM|PM)";if("a"==t)return i.push("am_pm"),"(am|pm)";if("X"==t)return i.push("timestamp"),"(d+)";if("x"==t)return i.push("unix"),"(d+)"}return t})),u={},s=e.match(new RegExp(o));s&&s.slice(1).forEach((function(t,e){var n=i[e];u[n]=t}));var f={};return a.forEach((function(t){+u[t]&&(f[t]=+u[t])})),u.hour_12?(f.hour=+u.hour_12,u.am_pm&&["PM","pm"].includes(u.am_pm)&&(f.hour+=12)):u.timestamp?f=t(u.timestamp).toObject():u.unix&&(f=t(1e3*u.unix).toObject()),f}(o[0],o[1]);Object.keys(u).length?this._date=t(u).toDate():this._date=new Date("")}}))}].forEach(v.extend),v}));
|
package/dist/datex.min.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* datex.js v1.0.
|
|
2
|
+
* datex.js v1.0.16
|
|
3
3
|
* a datetime format library
|
|
4
4
|
* https://passer-by.com/datex/
|
|
5
5
|
*
|
|
@@ -8,6 +8,6 @@
|
|
|
8
8
|
* Released under the MIT License
|
|
9
9
|
* https://github.com/mumuy/datex
|
|
10
10
|
*
|
|
11
|
-
* Created on: 2024-
|
|
11
|
+
* Created on: 2024-12-27
|
|
12
12
|
*/
|
|
13
|
-
function t(e,n){return t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},t(e,n)}function e(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(e=function(){return!!t})()}function n(n,r,i){if(e())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,r);var a=new(n.bind.apply(n,o));return i&&t(a,i.prototype),a}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function i(t){return function(t){if(Array.isArray(t))return r(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return r(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var o=["year","month","day","hour","minute","second","millsecond"],a=[1970,1,1,0,0,0,0],u={year:31536e6,month:2592e6,day:864e5,hour:36e5,minute:6e4,second:1e3,millsecond:1},s={Y:"year",M:"month",D:"day",H:"hour",m:"minute",s:"second",S:"millsecond",W:"week"};function c(t){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},c(t)}function h(t){return null!=t&&("object"==c(t)||"function"==typeof t)}function f(t){return"number"==typeof t&&!isNaN(t)}function m(t){return"string"==typeof t}function l(t){return"function"==typeof t}function g(t){return t instanceof Date}var d=[],p={_date:null,init:function t(){for(var e=arguments.length,r=new Array(e),u=0;u<e;u++)r[u]=arguments[u];var s,c=r.slice(0);if(c.length&&c[0]){if(Object.getPrototypeOf(c[0])==(this instanceof t?this.constructor:void 0))return c[0];if(g(c[0]))this._date=c[0];else{if(s=c[0],Array.isArray(s)?c=a.map((function(t,e){return c[0][e]||t})):h(c[0])&&(c=a.map((function(t,e){return c[0][o[e]]||t}))),1==c.length&&m(c[0])){var l=c[0].match(/(\d{1,4})[\-\/](\d{1,2})[\-\/](\d{1,2})([\sT](\d{1,2})?:(\d{1,2})?(:(\d{1,2}))?(\.(\d{1,3}))?)?/),p=c[0].match(/(\d{1,2})[\-\/](\d{1,2})[\-\/](\d{3,4})([\sT](\d{1,2})?:(\d{1,2})?(:(\d{1,2}))?(\.(\d{1,3}))?)?/),y=c[0].match(/^([12]\d{3})(\d{2})(\d{2})(\d{2})?(\d{2})?(\d{2})?(\d{1,3})?/);l&&!p?c=[1,2,3,5,6,8,10].map((function(t,e){return+(l[t]||a[e])})):p?c=[3,1,2,5,6,8,10].map((function(t,e){return+(p[t]||a[e])})):y&&(c=[1,2,3,4,5,6,7].map((function(t,e){return+(y[t]||a[e])})))}c.length>=3&&c[1]--,this._date=n(Date,i(c)),c.length>=2&&f(c[0])&&c[0]<100&&this._date.setFullYear(c[0])}}else this._date=new Date;var v=this;return d.forEach((function(t){t.bind(v).apply(void 0,r)})),this},onInit:function(t){d.push(t)}};function y(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return n(y.prototype.init,e)}function v(t){var e=function(t,e){if("object"!=c(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=c(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==c(e)?e:e+""}function b(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,v(r.key),r)}}function M(t,e,n){w(t,e),e.set(t,n)}function w(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}function O(t,e){return t.get(S(t,e))}function _(t,e,n){return t.set(S(t,e),n),n}function S(t,e,n){if("function"==typeof t?t===e:t.has(e))return arguments.length<3?e:n;throw new TypeError("Private element is not present on this object")}y.now=Date.now,y.extend=function(t){t(y,p)},y.prototype=p,p.init.prototype=p;var j=new WeakMap,T=new WeakMap,D=new WeakMap,W=new WeakSet,Y=function(){return t=function t(){var e,n;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),w(e=this,n=W),n.add(e),M(this,j,null),M(this,T,null),M(this,D,0);for(var r=this,i=arguments.length,o=new Array(i),a=0;a<i;a++)o[a]=arguments[a];if(2==o.length)h(o[0])&&h(o[1])?(_(j,r,o[0]),_(T,r,o[1]),_(D,r,O(j,r).getTime()-O(T,r).getTime())):f(o[0])&&m(o[1])&&r.change(o[1],o[0]);else if(1==o.length)if(h(o[0]))for(var u in o[0])r.change(u,o[0][u]);else f(o[0])&&_(D,r,O(D,r)+o[0])},e=[{key:"change",value:function(t,e){var n=this;return O(j,n)&&O(T,n)?(O(j,n).change(t,e),_(D,n,O(j,n).getTime()-O(T,n).getTime())):u[t]&&_(D,n,O(D,n)+u[t]*e),n}},{key:"get",value:function(t){var e=this;if(t){if(O(j,e)&&O(T,e)){var n=O(j,e),r=O(T,e),i=O(D,e),o=0;return"month"==t?(o=12*(n.get("year")-1)+n.get("month")-(12*(r.get("year")-1)+r.get("month")))<0&&n.get("day")>r.get("day")?o+=1:o>0&&n.get("day")<r.get("day")&&(o-=1):"year"==t?(o=n.get("year")-r.get("year"))<0&&(n.get("month")>r.get("month")||n.get("month")==r.get("month")&&n.get("day")>r.get("day"))?o+=1:o>0&&(n.get("month")<r.get("month")||n.get("month")==r.get("month")&&n.get("day")<r.get("day"))&&(o-=1):u[t]&&(o=~~(i/u[t])),o}return u[t]&&Math.floor(O(D,e)/u[t])||0}return O(D,e)}},{key:"toObject",value:function(){var t=this;return Object.assign({value:O(D,t)},S(W,t,k).call(t,o))}},{key:"format",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"YYYY-MM-DD HH:mm:ss";if(m(t)){var e=[];t.match(/Y+|M+|D+|H+|m+|s+|S+/g).forEach((function(t){var n=s[t[0]];e.includes(n)||e.push(n)}));var n=S(W,this,k).call(this,e),r={Y:""+n.year,M:""+n.month,D:""+n.day,H:""+n.hour,m:""+n.minute,s:""+n.second,S:""+n.millsecond};return t.replace(/Y+|M+|D+|H+|m+|s+|S+/g,(function(t){if(r[t])return r[t];if(r[t[0]]){var e=r[t[0]]<0,n=Math.abs(r[t[0]]).toString().padStart(t.length,"0");return e?"-"+n:n}return""}))}if(l(t))return t(this.toObject()).toString()||""}}],e&&b(t.prototype,e),n&&b(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n}();function k(t){var e=this,n={};if(O(j,e)&&O(T,e)){var r=O(D,e),i=O(j,e).clone(),o=O(T,e).clone();t.forEach((function(t){n[t]=e.get(t),e.change(t,-n[t])})),_(D,e,r),_(j,e,i),_(T,e,o)}else{var a=O(D,e);t.forEach((function(t){u[t]&&(n[t]=Math.floor(a/u[t])||0,a%=u[t])}))}return n}var A={name:"en-us",format:{MMM:["Jan.","Feb.","Mar.","Apr.","May.","Jun.","Jul.","Aug.","Sept.","Oct.","Nov.","Dec."],MMMM:["January","February","March","April","May","June","July","August","September","October","November","December"],Do:["1st","2nd","3rd","4th","5th","6th","7th","8th","9th","10th","11th","12th","13th","14th","15th","16th","17th","18th","19th","20th","21st","22nd","23rd","24th","25th","26th","27th","28th","29th","30th","31st"],WW:["Sun.","Mon.","Tues.","Wed.","Thur.","Fri.","Sat."],WWW:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},duration:{"past moments":"just now","future moments":"moments later",now:"now"}},L={name:"zh-cn",format:{MMM:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],MMMM:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],Do:["1日","2日","3日","4日","5日","6日","7日","8日","9日","10日","11日","12日","13日","14日","15日","16日","17日","18日","19日","20日","21日","22日","23日","24日","25日","26日","27日","28日","29日","30日","31日"],WW:["周日","周一","周二","周三","周四","周五","周六"],WWW:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]},duration:{"past moments":"刚刚","future moments":"片刻后",now:"现在"}};[function(t,e){Object.assign(e,{toDate:function(){return this._date},toObject:function(){var t=this._date;return{year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate(),hour:t.getHours(),minute:t.getMinutes(),second:t.getSeconds(),millsecond:t.getMilliseconds(),timestamp:t.getTime(),week:t.getDay()}},toArray:function(){var t=this.toObject();return o.map((function(e){return t[e]}))},toString:function(){return this._date.toString()},toISOString:function(){return this._date.toISOString()},getTime:function(){return this._date.getTime()},getUnix:function(){return~~(this._date.getTime()/1e3)},clone:function(){var e=t(this.getTime());return Object.assign(e,structuredClone(this))},isValid:function(){return f(this.getTime())},set:function(t,e){var n=this._date,r=this.toObject();switch(t){case"year":n.setFullYear(e);break;case"month":n.setMonth(e-1);break;case"day":n.setDate(e);break;case"hour":n.setHours(e);break;case"minute":n.setMinutes(e);break;case"second":n.setSeconds(e);break;case"millsecond":n.setMilliseconds(e);break;case"timestamp":n.setTime(e);break;case"week":n.setDate(r.day-r.week+e)}return this},change:function(t,e){var n=this.toObject();return["day","hour","minute","second","millsecond"].includes(t)?this.set("timestamp",n.timestamp+e*u[t]):this.set(t,n[t]+e)},get:function(t){return this.toObject()[t]},format:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"YYYY-MM-DD HH:mm:ss";if(m(t)){var e=this.clone(),n=e._date,r=e.toObject(),i=n.toTimeString().match(/GMT([\+\-])(\d{2})(\d{2})/),o={YYYY:(""+r.year).padStart(4,"0"),YY:(""+r.year%100).padStart(2,"0"),M:""+r.month,D:""+r.day,H:""+r.hour,h:""+r.hour%12,m:""+r.minute,s:""+r.second,S:""+~~(r.millsecond/100),SS:""+~~(r.millsecond/10),SSS:""+r.millsecond,Z:i[1]+i[2]+":"+i[3],ZZ:i[1]+i[2]+i[3],A:["AM","PM"][~~(r.hour/12)],a:["am","pm"][~~(r.hour/12)],X:r.timestamp,x:~~(r.timestamp/1e3),Q:""+~~(r.month/3),W:r.week};return t.replace(/Y+|M+|Do|D+|H+|h+|m+|s+|S+|Z+|A|a|X|x|Q|W+/g,(function(t){return o[t]||o[t[0]].padStart(t.length,"0")||""}))}if(l(t))return t(this.toObject())||""}})},function(t,e){Object.assign(e,{endOf:function(t){return this.startOf(t).change(t,"week"==t?7:1).change("millsecond",-1)},startOf:function(e){var n=this.toObject(),r=o.indexOf(e)+1,u=this.toArray(),s=a.slice(r);return u.splice.apply(u,[r,s.length].concat(i(s))),"timestamp"==e?this.clone():"week"==e?t(n.year,n.month,n.day-n.week,0,0,0,0):t.apply(void 0,i(u))}})},function(t,e){Object.assign(e,{isAfter:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"timestamp";return e=t(e),this.get(n)>e.get(n)},isBefore:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"timestamp";return e=t(e),this.get(n)<e.get(n)},isBetween:function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"timestamp";return e=t(e),n=t(n),this.get(r)>e.get(r)&&this.get(r)<n.get(r)},isSame:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"timestamp";return e=t(e),this.get(n)==e.get(n)}})},function(t,e){Object.assign(t,{duration:function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return n(Y,e)}}),Object.assign(e,{diffWith:function(e,n){if(!(e=t(e)).isValid())return 0;var r=t.duration(this,e);return n?r.get(n):r},fromNow:function(){var e=t(),n=t.duration(this,e).toObject(),r=n.value<0,i="",o=t.getLanguage(),a=this.getLanguageCode(),u=new Intl.RelativeTimeFormat(a);return["year","month","day","hour","minute","second"].forEach((function(t){var e=n[t];!i&&e&&(i=u.format(e,t))})),i||(i=n.value?r?o.duration["past moments"]:o.duration["future moments"]:o.duration.now),i}})},function(t,e){var n,r={};[A,L].forEach((function(t){r[t.name]=t}));var i=(null===globalThis||void 0===globalThis||null===(n=globalThis.navigator)||void 0===n?void 0:n.language.toLowerCase())||"en-us";Object.assign(t,{setLanguage:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t=t.toLowerCase(),r[t]=Object.assign(r[t]||{},e),this},switchLanguage:function(t){return i=t.toLowerCase(),this},getLanguage:function(){return r[i]},getLanguageCode:function(){return i}}),Object.assign(e,{_langMap:{},_lang:null,setLanguage:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t=t.toLowerCase(),this._langMap[t]=Object.assign(this._langMap[t]||{},e),this},switchLanguage:function(t){return this._lang=t.toLowerCase(),this},getLanguage:function(){return this._langMap[this._lang]},getLanguageCode:function(){return this._lang}}),e.onInit((function(){this._langMap=Object.assign(this._langMap,r),this._lang=i}));var o=e.format;Object.assign(e,{format:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"YYYY-MM-DD HH:mm:ss";if(m(e)){var n=this.clone().toObject(),r=t.getLanguage()||this.getLanguage(),i={};for(var a in i.MMM=r.format.MMM[n.month-1],i.MMMM=r.format.MMMM[n.month-1],i.Do=r.format.Do[n.day-1],i.WW=r.format.WW[n.week],i.WWW=r.format.WWW[n.week],i)e=e.replace(a,i[a]||"")}return o.bind(this)(e)}})},function(t,e){var n=Intl.DateTimeFormat().resolvedOptions().timeZone,r=0,i=function(t,e){return new Date(t.toLocaleString("en-US",{timeZone:e}))},o="1970/1/1";Object.assign(t,{supportedTimezones:"undefined"!=typeof Intl&&Intl.supportedValuesOf?Intl.supportedValuesOf("timeZone"):[],switchTimezone:function(t){return n=t,r=i(new Date(o),n).getTime()-Date.parse(o),this},getTimezoneOffset:function(){return(new Date).getTimezoneOffset()-r/6e4},getTimezone:function(){return n}}),Object.assign(e,{_timezone:null,_offset:0,switchTimezone:function(t){return this._timezone=t,this._offset=i(new Date(o),this._timezone).getTime()-Date.parse(o),this},getTimezoneOffset:function(){return this._date.getTimezoneOffset()-this._offset/6e4},getTimezone:function(){return this._timezone}}),e.onInit((function(){this._timezone=n,this._offset=r,arguments.length&&(arguments.length<=0?void 0:arguments[0])&&(g(arguments.length<=0?void 0:arguments[0])||(arguments.length<=0?void 0:arguments[0])instanceof t||1==arguments.length&&f(arguments.length<=0?void 0:arguments[0])||r&&this._date.setTime(this._date.getTime()-r))}));var a=e.format;Object.assign(e,{format:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"YYYY-MM-DD HH:mm:ss",e=this.clone();return e._date.setTime(e._date.getTime()+e._offset),a.bind(e)(t)}})},function(t,e){var n=t.getLanguage();e.onInit((function(){for(var e=arguments.length,r=new Array(e),i=0;i<e;i++)r[i]=arguments[i];var a=r.slice(0);if(a.length&&a[0]&&2==a.length&&m(a[0])&&m(a[1])){var u=function(e,r){var i=[],a=r.replace(/Y+|M+|Do|D+|H+|h+|m+|s+|S+|Z+|A|a|X|x|Q|W+/g,(function(t,e){if(n.format[t]){if(["MMM","MMMM"].includes(t))return i.push("month"),"("+n.format[t].join("|")+")";if(["Do"].includes(t))return i.push("day"),"("+n.format[t].join("|")+")";if(["WW","WWW"].includes(t))return i.push("week"),"("+n.format[t].join("|")+")"}else{if(s[t[0]])return i.push(s[t[0]]),"(\\d{1,"+t.length+"})";if(["h","hh"].includes(t))return i.push("hour_12"),"(\\d{1,2})";if("ZZ"==t)return i.push("timezone"),"(-?\\d{2}\\d{2})";if("Z"==t)return i.push("timezone"),"(-?\\d{2}:\\d{2})";if("A"==t)return i.push("am_pm"),"(AM|PM)";if("a"==t)return i.push("am_pm"),"(am|pm)";if("X"==t)return i.push("timestamp"),"(d+)";if("x"==t)return i.push("unix"),"(d+)"}return t})),u={},c=e.match(new RegExp(a));c&&c.slice(1).forEach((function(t,e){var n=i[e];u[n]=t}));var h={};return o.forEach((function(t){+u[t]&&(h[t]=+u[t])})),u.hour_12?(h.hour=+u.hour_12,u.am_pm&&["PM","pm"].includes(u.am_pm)&&(h.hour+=12)):u.timestamp?h=t(u.timestamp).toObject():u.unix&&(h=t(1e3*u.unix).toObject()),h}(a[0],a[1]);Object.keys(u).length?this._date=t(u).toDate():this._date=new Date("")}}))}].forEach(y.extend);export{y as default};
|
|
13
|
+
function t(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(t=function(){return!!e})()}function e(t,n){return e=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},e(t,n)}function n(n,r,i){if(t())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,r);var a=new(n.bind.apply(n,o));return i&&e(a,i.prototype),a}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function i(t,e){if(t){if("string"==typeof t)return r(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}function o(t){return function(t){if(Array.isArray(t))return r(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||i(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var a=["year","month","day","hour","minute","second","millsecond"],u=[1970,1,1,0,0,0,0],s={year:31536e6,month:2592e6,day:864e5,hour:36e5,minute:6e4,second:1e3,millsecond:1},c={Y:"year",M:"month",D:"day",H:"hour",m:"minute",s:"second",S:"millsecond",W:"week"};function f(t){return f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},f(t)}function h(t){return null!=t&&("object"==f(t)||"function"==typeof t)}function l(t){return"number"==typeof t&&!isNaN(t)}function m(t){return"string"==typeof t}function g(t){return"function"==typeof t}function d(t){return t instanceof Date}var p=[],v={_date:null,parse:function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var i,s=e.slice(0);if(s.length&&s[0]){if(Object.getPrototypeOf(s[0])==Object.getPrototypeOf(this))return this._date=s[0].toDate(),s[0];if(d(s[0]))this._date=s[0];else{if(i=s[0],Array.isArray(i)?s=u.map((function(t,e){return s[0][e]||t})):h(s[0])&&(s=u.map((function(t,e){return s[0][a[e]]||t}))),1==s.length&&m(s[0])){var c=s[0].match(/(\d{1,4})[\-\/](\d{1,2})[\-\/](\d{1,2})([\sT](\d{1,2})?:(\d{1,2})?(:(\d{1,2}))?(\.(\d{1,3}))?)?/),f=s[0].match(/(\d{1,2})[\-\/](\d{1,2})[\-\/](\d{3,4})([\sT](\d{1,2})?:(\d{1,2})?(:(\d{1,2}))?(\.(\d{1,3}))?)?/),g=s[0].match(/^([12]\d{3})(\d{2})(\d{2})(\d{2})?(\d{2})?(\d{2})?(\d{1,3})?/);c&&!f?s=[1,2,3,5,6,8,10].map((function(t,e){return+(c[t]||u[e])})):f?s=[3,1,2,5,6,8,10].map((function(t,e){return+(f[t]||u[e])})):g&&(s=[1,2,3,4,5,6,7].map((function(t,e){return+(g[t]||u[e])})))}s.length>=3&&s[1]--,this._date=n(Date,o(s)),s.length>=2&&l(s[0])&&s[0]<100&&this._date.setFullYear(s[0])}}else this._date=new Date;return this},init:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];this.parse.apply(this,e);var r=this;return p.forEach((function(t){t.bind(r).apply(void 0,e)})),this},onInit:function(t){p.push(t)}};function y(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return n(y.prototype.init,e)}function b(t){var e=function(t,e){if("object"!=f(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=f(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==f(e)?e:e+""}function M(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,b(r.key),r)}}function O(t,e,n){w(t,e),e.set(t,n)}function w(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}function _(t,e){return t.get(j(t,e))}function T(t,e,n){return t.set(j(t,e),n),n}function j(t,e,n){if("function"==typeof t?t===e:t.has(e))return arguments.length<3?e:n;throw new TypeError("Private element is not present on this object")}y.now=Date.now,y.extend=function(t){t(y,v)},y.prototype=v,v.init.prototype=v;var S=new WeakMap,D=new WeakMap,W=new WeakSet,A=function(){return t=function t(){var e,n;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),w(e=this,n=W),n.add(e),O(this,S,null),O(this,D,null);var r=this;r.value=0;for(var i=arguments.length,o=new Array(i),a=0;a<i;a++)o[a]=arguments[a];if(2==o.length)h(o[0])&&h(o[1])?(T(S,r,o[0]),T(D,r,o[1]),r.value=_(S,r).getTime()-_(D,r).getTime()):l(o[0])&&m(o[1])&&r.change(o[1],o[0]);else if(1==o.length)if(h(o[0]))for(var u in o[0])r.change(u,o[0][u]);else l(o[0])&&(r.value+=o[0])},e=[{key:"change",value:function(t,e){var n=this;return _(S,n)&&_(D,n)?(_(S,n).change(t,e),n.value=_(S,n).getTime()-_(D,n).getTime()):s[t]&&(n.value+=s[t]*e),n}},{key:"get",value:function(t){var e=this;if(t){if(_(S,e)&&_(D,e)){var n=_(S,e),r=_(D,e),i=e.value,o=0;return"month"==t?(o=12*(n.get("year")-1)+n.get("month")-(12*(r.get("year")-1)+r.get("month")))<0&&n.get("day")>r.get("day")?o+=1:o>0&&n.get("day")<r.get("day")&&(o-=1):"year"==t?(o=n.get("year")-r.get("year"))<0&&(n.get("month")>r.get("month")||n.get("month")==r.get("month")&&n.get("day")>r.get("day"))?o+=1:o>0&&(n.get("month")<r.get("month")||n.get("month")==r.get("month")&&n.get("day")<r.get("day"))&&(o-=1):s[t]&&(o=~~(i/s[t])),o}return s[t]&&Math.floor(e.value/s[t])||0}return e.value}},{key:"toObject",value:function(){var t=this;return Object.assign({value:t.value},j(W,t,k).call(t,a))}},{key:"format",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"YYYY-MM-DD HH:mm:ss";if(m(t)){var e=[];t.match(/Y+|M+|D+|H+|m+|s+|S+/g).forEach((function(t){var n=c[t[0]];e.includes(n)||e.push(n)}));var n=j(W,this,k).call(this,e),r={Y:""+n.year,M:""+n.month,D:""+n.day,H:""+n.hour,m:""+n.minute,s:""+n.second,S:""+n.millsecond};return t.replace(/Y+|M+|D+|H+|m+|s+|S+/g,(function(t){if(r[t])return r[t];if(r[t[0]]){var e=r[t[0]]<0,n=Math.abs(r[t[0]]).toString().padStart(t.length,"0");return e?"-"+n:n}return""}))}if(g(t))return t(this.toObject()).toString()||""}}],e&&M(t.prototype,e),n&&M(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n}();function k(t){var e=this,n={};if(_(S,e)&&_(D,e)){var r=e.value,i=_(S,e).clone(),o=_(D,e).clone();t.forEach((function(t){n[t]=e.get(t),e.change(t,-n[t])})),e.value=r,T(S,e,i),T(D,e,o)}else{var a=e.value;t.forEach((function(t){s[t]&&(n[t]=Math.floor(a/s[t])||0,a%=s[t])}))}return n}var Y={name:"en-us",format:{MMM:["Jan.","Feb.","Mar.","Apr.","May.","Jun.","Jul.","Aug.","Sept.","Oct.","Nov.","Dec."],MMMM:["January","February","March","April","May","June","July","August","September","October","November","December"],Do:["1st","2nd","3rd","4th","5th","6th","7th","8th","9th","10th","11th","12th","13th","14th","15th","16th","17th","18th","19th","20th","21st","22nd","23rd","24th","25th","26th","27th","28th","29th","30th","31st"],WW:["Sun.","Mon.","Tues.","Wed.","Thur.","Fri.","Sat."],WWW:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},duration:{"past moments":"just now","future moments":"moments later",now:"now"}},z={name:"zh-cn",format:{MMM:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],MMMM:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],Do:["1日","2日","3日","4日","5日","6日","7日","8日","9日","10日","11日","12日","13日","14日","15日","16日","17日","18日","19日","20日","21日","22日","23日","24日","25日","26日","27日","28日","29日","30日","31日"],WW:["周日","周一","周二","周三","周四","周五","周六"],WWW:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]},duration:{"past moments":"刚刚","future moments":"片刻后",now:"现在"}};function L(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var r,i,o,a,u=[],s=!0,c=!1;try{if(o=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(r=o.call(n)).done)&&(u.push(r.value),u.length!==e);s=!0);}catch(t){c=!0,i=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw i}}return u}}(t,e)||i(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}[function(t,e){Object.assign(e,{toDate:function(){return this._date},toObject:function(){var t=this._date;return{year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate(),hour:t.getHours(),minute:t.getMinutes(),second:t.getSeconds(),millsecond:t.getMilliseconds(),timestamp:t.getTime(),week:t.getDay()}},toArray:function(){var t=this.toObject();return a.map((function(e){return t[e]}))},toString:function(){return this._date.toString()},toISOString:function(){return this._date.toISOString()},getTime:function(){return this._date.getTime()},getUnix:function(){return~~(this._date.getTime()/1e3)},clone:function(){var e=t(this.getTime());return Object.assign(e,structuredClone(this))},isValid:function(){return l(this.getTime())},set:function(t,e){var n=this._date,r=this.toObject();switch(t){case"year":n.setFullYear(e);break;case"month":n.setMonth(e-1);break;case"day":n.setDate(e);break;case"hour":n.setHours(e);break;case"minute":n.setMinutes(e);break;case"second":n.setSeconds(e);break;case"millsecond":n.setMilliseconds(e);break;case"timestamp":n.setTime(e);break;case"week":n.setDate(r.day-r.week+e)}return this},change:function(t,e){var n=this.toObject();return["day","hour","minute","second","millsecond"].includes(t)?this.set("timestamp",n.timestamp+e*s[t]):this.set(t,n[t]+e)},get:function(t){return this.toObject()[t]},format:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"YYYY-MM-DD HH:mm:ss";if(m(t)){var e=this._date,n=this.toObject(),r=e.toTimeString().match(/GMT([\+\-])(\d{2})(\d{2})/),i={YYYY:(""+n.year).padStart(4,"0"),YY:(""+n.year%100).padStart(2,"0"),M:""+n.month,D:""+n.day,H:""+n.hour,h:""+n.hour%12,m:""+n.minute,s:""+n.second,S:""+~~(n.millsecond/100),SS:""+~~(n.millsecond/10),SSS:""+n.millsecond,Z:r[1]+r[2]+":"+r[3],ZZ:r[1]+r[2]+r[3],A:["AM","PM"][~~(n.hour/12)],a:["am","pm"][~~(n.hour/12)],X:n.timestamp,x:~~(n.timestamp/1e3),Q:""+~~(n.month/3),W:n.week};return t.replace(/Y+|M+|Do|D+|H+|h+|m+|s+|S+|Z+|A|a|X|x|Q|W+/g,(function(t){return i[t]||i[t[0]].padStart(t.length,"0")||""}))}if(g(t))return t(this.toObject())||""}})},function(t,e){Object.assign(e,{endOf:function(t){return this.startOf(t).change(t,"week"==t?7:1).change("millsecond",-1)},startOf:function(e){var n=this.clone();if("timestamp"==e)return n;if("week"==e){var r=n.toObject();return t(r.year,r.month,r.day-r.week,0,0,0,0)}var i=a.indexOf(e)+1,s=u.slice(i),c=n.toArray();return c.splice.apply(c,[i,s.length].concat(o(s))),t.apply(void 0,o(c))}})},function(t,e){Object.assign(e,{isAfter:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"timestamp";return e=t(e),this.get(n)>e.get(n)},isBefore:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"timestamp";return e=t(e),this.get(n)<e.get(n)},isBetween:function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"timestamp";return e=t(e),n=t(n),this.get(r)>e.get(r)&&this.get(r)<n.get(r)},isSame:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"timestamp";return e=t(e),this.get(n)==e.get(n)}})},function(t,e){Object.assign(t,{duration:function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return n(A,e)}}),Object.assign(e,{diffWith:function(e,n){if(!(e=t(e)).isValid())return 0;var r=t.duration(this,e);return n?r.get(n):r},fromNow:function(){var e=t(),n=t.duration(this,e).toObject(),r=n.value<0,i="",o=t.getLanguage(),a=this.getLanguageCode(),u=new Intl.RelativeTimeFormat(a,{numeric:"auto"});return["year","month","day","hour","minute","second"].forEach((function(t){var e=n[t];!i&&e&&(i=u.format(e,t))})),i||(i=n.value?r?o.duration["past moments"]:o.duration["future moments"]:o.duration.now),i}})},function(t,e){var n,r={};[Y,z].forEach((function(t){r[t.name]=t}));var i=(null===globalThis||void 0===globalThis||null===(n=globalThis.navigator)||void 0===n?void 0:n.language.toLowerCase())||"en-us";Object.assign(t,{setLanguage:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t=t.toLowerCase(),r[t]=Object.assign(r[t]||{},e),this},switchLanguage:function(t){return i=t.toLowerCase(),this},getLanguage:function(){return r[i]},getLanguageCode:function(){return i}}),Object.assign(e,{_langMap:{},_lang:null,setLanguage:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t=t.toLowerCase(),this._langMap[t]=Object.assign(this._langMap[t]||{},e),this},switchLanguage:function(t){return this._lang=t.toLowerCase(),this},getLanguage:function(){return this._langMap[this._lang]},getLanguageCode:function(){return this._lang}}),e.onInit((function(){this._langMap=Object.assign(this._langMap,r),this._lang=i}));var o=e.format;Object.assign(e,{format:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"YYYY-MM-DD HH:mm:ss";if(m(e)){var n=this.clone().toObject(),r=t.getLanguage()||this.getLanguage(),i={};for(var a in i.MMMM=r.format.MMMM[n.month-1],i.MMM=r.format.MMM[n.month-1],i.Do=r.format.Do[n.day-1],i.WWW=r.format.WWW[n.week],i.WW=r.format.WW[n.week],i)e=e.replace(a,i[a]||"")}return o.bind(this)(e)}})},function(t,e){var n=Intl.DateTimeFormat().resolvedOptions().timeZone,r=0,i=function(t,e){var n=e.replace(/\s/g,"").match(/(GMT|UTC)(\+|\-)?(\d{1,2})(\.|:)(\d{1,2})/);if(n){var r=L(n,6);r[0],r[1];var i=r[2],o=r[3],a=r[4],u=r[5],s=0;return s=":"==a?60*Number(o)+Number(u):60*Number(o+a+u),"+"!=i&&i||(s=-s),6e4*(t.getTimezoneOffset()-s)}var c,f,h=(c=t,f=e,new Date(c.toLocaleString("en-US",{timeZone:f}))).getTime()-t.getTime();return h=6e4*Math.ceil(h/6e4)},o=new Date;Object.assign(t,{supportedTimezones:"undefined"!=typeof Intl&&Intl.supportedValuesOf?Intl.supportedValuesOf("timeZone"):[],switchTimezone:function(t){return r=i(o,n=t),this},getTimezoneOffset:function(){return(new Date).getTimezoneOffset()-r/6e4},getTimezone:function(){return n}}),Object.assign(e,{_timezone:null,_offset:0,switchTimezone:function(t){this._timezone=t;var e=this._date||o;return this._offset=i(e,this._timezone),this},getTimezoneOffset:function(){return this._date.getTimezoneOffset()-this._offset/6e4},getTimezone:function(){return this._timezone},isDayLightSavingTime:function(){return this.getTimezoneOffset()<this.clone().set("month",1).getTimezoneOffset()||this.getTimezoneOffset()<this.clone().set("month",6).getTimezoneOffset()}}),e.onInit((function(){this._timezone=n,this._offset=r,arguments.length&&(arguments.length<=0?void 0:arguments[0])&&(d(arguments.length<=0?void 0:arguments[0])||(arguments.length<=0?void 0:arguments[0])instanceof t||1==arguments.length&&l(arguments.length<=0?void 0:arguments[0])||r&&this._date.setTime(this._date.getTime()-r))}));var a=e.set,u=e.toObject;Object.assign(e,{toObject:function(){var t=this.clone();return t._date.setTime(t._date.getTime()+t._offset),u.bind(t)()},set:function(t,e){var n=this._date.getTime();this._date.setTime(n+this._offset);var r=a.bind(this)(t,e),u=r._date||o;return r._offset=i(u,r._timezone),n=r._date.getTime(),r._date.setTime(n-r._offset),r}})},function(t,e){var n=t.getLanguage();e.onInit((function(){for(var e=arguments.length,r=new Array(e),i=0;i<e;i++)r[i]=arguments[i];var o=r.slice(0);if(o.length&&o[0]&&2==o.length&&m(o[0])&&m(o[1])){var u=function(e,r){var i=[],o=r.replace(/Y+|M+|Do|D+|H+|h+|m+|s+|S+|Z+|A|a|X|x|Q|W+/g,(function(t,e){if(n.format[t]){if(["MMM","MMMM"].includes(t))return i.push("month"),"("+n.format[t].join("|")+")";if(["Do"].includes(t))return i.push("day"),"("+n.format[t].join("|")+")";if(["WW","WWW"].includes(t))return i.push("week"),"("+n.format[t].join("|")+")"}else{if(c[t[0]])return i.push(c[t[0]]),"(\\d{1,"+t.length+"})";if(["h","hh"].includes(t))return i.push("hour_12"),"(\\d{1,2})";if("ZZ"==t)return i.push("timezone"),"(-?\\d{2}\\d{2})";if("Z"==t)return i.push("timezone"),"(-?\\d{2}:\\d{2})";if("A"==t)return i.push("am_pm"),"(AM|PM)";if("a"==t)return i.push("am_pm"),"(am|pm)";if("X"==t)return i.push("timestamp"),"(d+)";if("x"==t)return i.push("unix"),"(d+)"}return t})),u={},s=e.match(new RegExp(o));s&&s.slice(1).forEach((function(t,e){var n=i[e];u[n]=t}));var f={};return a.forEach((function(t){+u[t]&&(f[t]=+u[t])})),u.hour_12?(f.hour=+u.hour_12,u.am_pm&&["PM","pm"].includes(u.am_pm)&&(f.hour+=12)):u.timestamp?f=t(u.timestamp).toObject():u.unix&&(f=t(1e3*u.unix).toObject()),f}(o[0],o[1]);Object.keys(u).length?this._date=t(u).toDate():this._date=new Date("")}}))}].forEach(y.extend);export{y as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "datex.js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "a datetime format library",
|
|
5
5
|
"author": "HaoLe Zheng",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,19 +22,24 @@
|
|
|
22
22
|
"bugs": {
|
|
23
23
|
"url": "https://github.com/mumuy/datex/issues"
|
|
24
24
|
},
|
|
25
|
-
"
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=20",
|
|
27
|
+
"yarn": "please-use-npm",
|
|
28
|
+
"npm": ">=8"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
26
31
|
"dist"
|
|
27
32
|
],
|
|
28
33
|
"devDependencies": {
|
|
29
|
-
"@babel/core": "^7.
|
|
30
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
31
|
-
"@babel/preset-env": "^7.
|
|
32
|
-
"@babel/runtime": "^7.
|
|
34
|
+
"@babel/core": "^7.26.0",
|
|
35
|
+
"@babel/plugin-transform-runtime": "^7.25.9",
|
|
36
|
+
"@babel/preset-env": "^7.26.0",
|
|
37
|
+
"@babel/runtime": "^7.26.0",
|
|
33
38
|
"@rollup/plugin-babel": "^6.0.4",
|
|
34
|
-
"@rollup/plugin-node-resolve": "^15.
|
|
39
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
35
40
|
"@rollup/plugin-terser": "^0.4.4",
|
|
36
|
-
"rollup": "^3.29.
|
|
37
|
-
"tape": "^5.
|
|
41
|
+
"rollup": "^3.29.5",
|
|
42
|
+
"tape": "^5.9.0"
|
|
38
43
|
},
|
|
39
44
|
"scripts": {
|
|
40
45
|
"test": "node test/index.js",
|