datex.js 1.0.11 → 1.0.15
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 +13 -0
- package/package.json +21 -7
- package/gulpfile.js +0 -37
- package/index.html +0 -1205
- package/src/datex.js +0 -17
- package/src/module/factory.js +0 -20
- package/src/module/method/base.js +0 -135
- package/src/module/method/compare.js +0 -22
- package/src/module/method/compute.js +0 -64
- package/src/module/method/language.js +0 -72
- package/src/module/method/locale/en-us.js +0 -7
- package/src/module/method/locale/zh-cn.js +0 -7
- package/src/module/method/map/period.js +0 -9
- package/src/module/method/timezone.js +0 -60
- package/src/module/prototype.js +0 -63
- package/static/image/bg.svg +0 -54
- package/static/style/index.css +0 -459
- package/test/index.js +0 -17
package/dist/datex.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* datex.js v1.0.
|
|
2
|
+
* datex.js v1.0.15
|
|
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:
|
|
11
|
+
* Created on: 2024-07-08
|
|
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";const t=["year","month","day","hour","minute","second","millsecond"],e=[1970,1,1,0,0,0,0],n={day:864e5,hour:36e5,minute:6e4,second:1e3,millsecond:1};let i=[];var s={_date:null,init:function(...n){if(n.length){if(n[0].__proto__==this.__proto__)return n[0];if(n[0]instanceof Date)this._date=n[0];else{if(Array.isArray(n[0])?n=e.map(((t,e)=>n[0][e]||t)):null==(s=n[0])||"object"!=typeof s&&"function"!=typeof s||(n=e.map(((e,i)=>n[0][t[i]]||e))),1==n.length&&"string"==typeof n[0]){let t=n[0].match(/(\d{1,4})[\-\/](\d{1,2})[\-\/](\d{1,2})([\sT](\d{1,2})?:(\d{1,2})?(:(\d{1,2}))?(\.(\d{1,3}))?)?/),i=n[0].match(/(\d{1,2})[\-\/](\d{1,2})[\-\/](\d{3,4})([\sT](\d{1,2})?:(\d{1,2})?(:(\d{1,2}))?(\.(\d{1,3}))?)?/),s=n[0].match(/^([12]\d{3})(\d{2})(\d{2})(\d{2})?(\d{2})?(\d{2})?(\d{1,3})?/);t&&!i?n=[1,2,3,5,6,8,10].map((function(n,i){return+(t[n]||e[i])})):i?n=[3,1,2,5,6,8,10].map((function(t,n){return+(i[t]||e[n])})):s&&(n=[1,2,3,4,5,6,7].map((function(t,n){return+(s[t]||e[n])})))}n.length>=3&&n[1]--,this._date=new Date(...n),n.length>=2&&!isNaN(n[0])&&n[0]<100&&this._date.setFullYear(n[0])}}else this._date=new Date;var s;let a=this;return i.forEach((function(t){t.bind(a)(...n)})),this},onInit:function(t){i.push(t)}};function a(...t){return new a.prototype.init(...t)}a.now=Date.now,a.extend=function(t){t(a,s)},a.prototype=s,s.init.prototype=s;var o={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"]},r={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:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]};return[function(e,i){Object.assign(i,{toDate(){return this._date},toObject(){let 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(){let e=this.toObject();return t.map((t=>e[t]))},toString(){return this._date.toString()},toISOString(){return this._date.toISOString()},getTime(){return this._date.getTime()},getUnix(){return~~(this._date.getTime()/1e3)},clone(){let t=this,n=e(this.getTime());return Object.getOwnPropertyNames(t).forEach((function(e){"_date"!=e&&(n[e]=t[e])})),n},isValid(){return!isNaN(this.getTime())},set(t,e){let n=this._date,i=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(i.day-i.week+e)}return this},change(t,e){let i=this.toObject();return void 0!==n[t]?this.set("timestamp",i.timestamp+e*n[t]):this.set(t,i[t]+e)},get(t){return this.toObject()[t]},format(t="YYYY-MM-DD HH:mm:ss"){let e=this.clone(),n=e._date,i=e.toObject(),s=n.toTimeString().match(/GMT([\+\-])(\d{2})(\d{2})/),a={YYYY:""+i.year,YY:(""+i.year).padStart(2,"0"),MM:(""+i.month).padStart(2,"0"),M:""+i.month,DD:(""+i.day).padStart(2,"0"),D:""+i.day,HH:(""+i.hour).padStart(2,"0"),H:""+i.hour,hh:(""+i.hour%12).padStart(2,"0"),h:""+i.hour%12,mm:(""+i.minute).padStart(2,"0"),m:""+i.minute,ss:(""+i.second).padStart(2,"0"),s:""+i.second,S:""+~~(i.millsecond%1e3/100),SS:""+~~(i.millsecond%1e3/10),SSS:""+i.millsecond%1e3,Z:s[1]+s[2]+":"+s[3],ZZ:s[1]+s[2]+s[3],A:["AM","PM"][~~(i.hour/12)],a:["am","pm"][~~(i.hour/12)],X:i.timestamp,x:~~(i.timestamp/1e3),Q:""+~~(i.month/3),W:i.week};return t.replace(/Y+|M+|D+|H+|h+|m+|s+|S+|Z+|A|a|X|x|Q|W+/g,(function(t){return a[t]||""}))}})},function(i,s){Object.assign(s,{diffWith(e,s){if(!(e=i(e)).isValid())return!1;let a=this.getTime()-e.getTime(),o=0;if(s){if(n[s])o=~~(a/n[s]);else if("month"==s){o=12*(this.get("year")-1)+this.get("month")-(12*(e.get("year")-1)+e.get("month")),o<0&&this.get("day")>e.get("day")?o+=1:o>0&&this.get("day")<e.get("day")&&(o-=1)}else"year"==s&&(o=this.get("year")-e.get("year"),o<0&&(this.get("month")>e.get("month")||this.get("month")==e.get("month")&&this.get("day")>e.get("day"))?o+=1:o>0&&(this.get("month")<e.get("month")||this.get("month")==e.get("month")&&this.get("day")<e.get("day"))&&(o-=1));return o}{let n=this.clone(),i={};return t.forEach((function(t){i[t]=n.diffWith(e,t),n.set(t,e.get(t))})),i}},endOf(t){return this.startOf(t).change(t,"week"==t?7:1).change("millsecond",-1)},startOf(n){let s=this.toObject(),a=null,o=t.indexOf(n)+1,r=this.toArray(),h=e.slice(o);return r.splice(o,h.length,...h),a="timestamp"==n?this.clone():"week"==n?i(s.year,s.month,s.day-s.week,0,0,0,0):i(...r),a}})},function(t,e){Object.assign(e,{isAfter(e,n="timestamp"){return e=t(e),this.get(n)>e.get(n)},isBefore(e,n="timestamp"){return e=t(e),this.get(n)<e.get(n)},isBetween(e,n,i="timestamp"){return e=t(e),n=t(n),this.get(i)>e.get(i)&&this.get(i)<n.get(i)},isSame(e,n="timestamp"){return e=t(e),this.get(n)==e.get(n)}})},function(t,e){let n={};n["en-us"]=o,n["zh-cn"]=r;let i="en-us";"undefined"!=typeof self&&self.navigator&&(i=self.navigator.language.toLowerCase(),n[i]||(i="en-us")),Object.assign(t,{setLanguage(t,e={}){return t=t.toLowerCase(),n[t]=Object.assign(n[t]||{},e),this},switchLanguage(t){return i=t.toLowerCase(),this},getLanguage:()=>n[i]}),Object.assign(e,{_langMap:{},_lang:null,setLanguage(t,e={}){return t=t.toLowerCase(),this._langMap[t]=Object.assign(this._langMap[t]||{},e),this},switchLanguage(t){return this._lang=t.toLowerCase(),this},getLanguage(){return this._langMap[this._lang]}}),e.onInit((function(){this._langMap=Object.assign(this._langMap,n),this._lang=i}));let s=e.format;Object.assign(e,{format(e="YYYY-MM-DD HH:mm:ss"){let n=this.clone().toObject(),i=t.getLanguage()||this.getLanguage(),a={};a.MMM=i.MMM[n.month-1],a.MMMM=i.MMMM[n.month-1],a.Do=i.Do[n.day-1],a.WW=i.WW[n.week],a.WWW=i.WWW[n.week];for(let t in a)e=e.replace(t,a[t]||"");return s.bind(this)(e)}})},function(t,e){let n=Intl.DateTimeFormat().resolvedOptions().timeZone,i=0;const s=(t,e)=>new Date(t.toLocaleString("en-US",{timeZone:e}));Object.assign(t,{supportedTimezones:"undefined"!=typeof Intl&&Intl.supportedValuesOf?Intl.supportedValuesOf("timeZone"):[],switchTimezone(t){return n=t,i=s(new Date("1970/1/1"),n).getTime()-new Date("1970/1/1").getTime(),this},getTimezoneOffset:()=>(new Date).getTimezoneOffset()-i/6e4,getTimezone:()=>n}),Object.assign(e,{_timezone:null,_offset:0,switchTimezone(t){return this._timezone=t,this._offset=s(new Date("1970/1/1"),this._timezone).getTime()-new Date("1970/1/1").getTime(),this},getTimezoneOffset(){return this._date.getTimezoneOffset()-this._offset/6e4},getTimezone(){return this._timezone}}),e.onInit((function(...e){this._timezone=n,this._offset=i,e.length&&(e[0]instanceof Date||e[0]instanceof t||1==e.length&&"number"==typeof e[0]||i&&this._date.setTime(this._date.getTime()-i))}));let a=e.format;Object.assign(e,{format(t="YYYY-MM-DD HH:mm:ss"){let e=this.clone();return e._date.setTime(e._date.getTime()+e._offset),a.bind(e)(t)}})}].forEach(a.extend),a}));
|
|
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}));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* datex.js v1.0.15
|
|
3
|
+
* a datetime format library
|
|
4
|
+
* https://passer-by.com/datex/
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2022-present, HaoLe Zheng
|
|
7
|
+
*
|
|
8
|
+
* Released under the MIT License
|
|
9
|
+
* https://github.com/mumuy/datex
|
|
10
|
+
*
|
|
11
|
+
* Created on: 2024-07-08
|
|
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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "datex.js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
4
4
|
"description": "a datetime format library",
|
|
5
5
|
"author": "HaoLe Zheng",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,7 +9,12 @@
|
|
|
9
9
|
"format",
|
|
10
10
|
"时间格式化"
|
|
11
11
|
],
|
|
12
|
-
"main": "dist/datex.min.js",
|
|
12
|
+
"main": "./dist/datex.min.js",
|
|
13
|
+
"module": "./dist/datex.min.mjs",
|
|
14
|
+
"exports": {
|
|
15
|
+
"default": "./dist/datex.min.js",
|
|
16
|
+
"import": "./dist/datex.min.mjs"
|
|
17
|
+
},
|
|
13
18
|
"repository": {
|
|
14
19
|
"type": "git",
|
|
15
20
|
"url": "git+https://github.com/mumuy/datex.git"
|
|
@@ -17,15 +22,24 @@
|
|
|
17
22
|
"bugs": {
|
|
18
23
|
"url": "https://github.com/mumuy/datex/issues"
|
|
19
24
|
},
|
|
25
|
+
"files":[
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
20
28
|
"devDependencies": {
|
|
21
|
-
"@
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
29
|
+
"@babel/core": "^7.24.4",
|
|
30
|
+
"@babel/plugin-transform-runtime": "^7.24.3",
|
|
31
|
+
"@babel/preset-env": "^7.24.4",
|
|
32
|
+
"@babel/runtime": "^7.24.4",
|
|
33
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
34
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
35
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
36
|
+
"rollup": "^3.29.4",
|
|
37
|
+
"tape": "^5.7.5"
|
|
25
38
|
},
|
|
26
39
|
"scripts": {
|
|
27
40
|
"test": "node test/index.js",
|
|
28
|
-
"build": "
|
|
41
|
+
"build": "rollup -c && npm run test",
|
|
42
|
+
"watch": "rollup -wc"
|
|
29
43
|
},
|
|
30
44
|
"homepage": "https://passer-by.com/datex/",
|
|
31
45
|
"directories": {
|
package/gulpfile.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const gulp = require('gulp');
|
|
2
|
-
const rollup = require('rollup');
|
|
3
|
-
const terser = require('@rollup/plugin-terser');
|
|
4
|
-
const pkg = require('./package');
|
|
5
|
-
|
|
6
|
-
// copyright
|
|
7
|
-
var repository = pkg.repository.url.replace(/(.+)(:\/\/.+)\.git$/,'https$2');
|
|
8
|
-
var now = new Date();
|
|
9
|
-
var date = (new Date(now.getTime()-now.getTimezoneOffset()*60000)).toISOString().substr(0,10);
|
|
10
|
-
var banner = `/*!
|
|
11
|
-
* ${pkg.name} v${pkg.version}
|
|
12
|
-
* ${pkg.description}
|
|
13
|
-
* ${pkg.homepage}
|
|
14
|
-
*
|
|
15
|
-
* Copyright (c) 2022-present, ${pkg.author}
|
|
16
|
-
*
|
|
17
|
-
* Released under the ${pkg.license} License
|
|
18
|
-
* ${repository}
|
|
19
|
-
*
|
|
20
|
-
* Created on: ${date}
|
|
21
|
-
*/`;
|
|
22
|
-
|
|
23
|
-
gulp.task('default', () => {
|
|
24
|
-
return rollup.rollup({
|
|
25
|
-
input: './src/datex.js',
|
|
26
|
-
plugins: [
|
|
27
|
-
terser()
|
|
28
|
-
]
|
|
29
|
-
}).then(bundle => {
|
|
30
|
-
return bundle.write({
|
|
31
|
-
file: './dist/datex.min.js',
|
|
32
|
-
format: 'umd',
|
|
33
|
-
name: 'datex',
|
|
34
|
-
banner
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
});
|