datex.js 1.0.12 → 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 +3 -3
- package/package.json +13 -14
- package/babel.config.js +0 -13
- package/index.html +0 -1225
- package/rollup.config.mjs +0 -52
- 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/image/word_map.png +0 -0
- package/static/script/timezone.js +0 -432
- package/static/style/index.css +0 -461
- package/static/style/timezone.css +0 -462
- package/test/index.js +0 -17
- package/timezone.html +0 -334
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";function t(e,n){return t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},t(e,n)}function e(n,i,r){return e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}()?Reflect.construct.bind():function(e,n,i){var r=[null];r.push.apply(r,n);var o=new(Function.bind.apply(e,r));return i&&t(o,i.prototype),o},e.apply(null,arguments)}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function i(t){return function(t){if(Array.isArray(t))return n(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 n(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?n(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.")}()}function r(t){return r="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},r(t)}var o=["year","month","day","hour","minute","second","millsecond"],a=[1970,1,1,0,0,0,0],s={day:864e5,hour:36e5,minute:6e4,second:1e3,millsecond:1};var u=[],c={_date:null,init:function(){for(var t=arguments.length,n=new Array(t),s=0;s<t;s++)n[s]=arguments[s];if(n.length){if(Object.getPrototypeOf(n[0])==Object.getPrototypeOf(this))return n[0];if(n[0]instanceof Date)this._date=n[0];else{if(Array.isArray(n[0])?n=a.map((function(t,e){return n[0][e]||t})):null==(d=n[0])||"object"!=r(d)&&"function"!=typeof d||(n=a.map((function(t,e){return n[0][o[e]]||t}))),1==n.length&&"string"==typeof n[0]){var c=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}))?)?/),h=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}))?)?/),f=n[0].match(/^([12]\d{3})(\d{2})(\d{2})(\d{2})?(\d{2})?(\d{2})?(\d{1,3})?/);c&&!h?n=[1,2,3,5,6,8,10].map((function(t,e){return+(c[t]||a[e])})):h?n=[3,1,2,5,6,8,10].map((function(t,e){return+(h[t]||a[e])})):f&&(n=[1,2,3,4,5,6,7].map((function(t,e){return+(f[t]||a[e])})))}n.length>=3&&n[1]--,this._date=e(Date,i(n)),n.length>=2&&!isNaN(n[0])&&n[0]<100&&this._date.setFullYear(n[0])}}else this._date=new Date;var d,g=this;return u.forEach((function(t){t.bind(g).apply(void 0,i(n))})),this},onInit:function(t){u.push(t)}};function h(){for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];return e(h.prototype.init,n)}h.now=Date.now,h.extend=function(t){t(h,c)},h.prototype=c,c.init.prototype=c;var f={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"]},d={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(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=this,n=t(this.getTime());return Object.getOwnPropertyNames(e).forEach((function(t){"_date"!=t&&(n[t]=e[t])})),n},isValid:function(){return!isNaN(this.getTime())},set:function(t,e){var 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:function(t,e){var n=this.toObject();return void 0!==s[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",e=this.clone(),n=e._date,i=e.toObject(),r=n.toTimeString().match(/GMT([\+\-])(\d{2})(\d{2})/),o={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:r[1]+r[2]+":"+r[3],ZZ:r[1]+r[2]+r[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 o[t]||""}))}})},function(t,e){Object.assign(e,{diffWith:function(e,n){if(!(e=t(e)).isValid())return!1;var i=this.getTime()-e.getTime(),r=0;if(n){if(s[n])r=~~(i/s[n]);else if("month"==n){(r=12*(this.get("year")-1)+this.get("month")-(12*(e.get("year")-1)+e.get("month")))<0&&this.get("day")>e.get("day")?r+=1:r>0&&this.get("day")<e.get("day")&&(r-=1)}else"year"==n&&((r=this.get("year")-e.get("year"))<0&&(this.get("month")>e.get("month")||this.get("month")==e.get("month")&&this.get("day")>e.get("day"))?r+=1:r>0&&(this.get("month")<e.get("month")||this.get("month")==e.get("month")&&this.get("day")<e.get("day"))&&(r-=1));return r}var a=this.clone(),u={};return o.forEach((function(t){u[t]=a.diffWith(e,t),a.set(t,e.get(t))})),u},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,s=this.toArray(),u=a.slice(r);return s.splice.apply(s,[r,u.length].concat(i(u))),"timestamp"==e?this.clone():"week"==e?t(n.year,n.month,n.day-n.week,0,0,0,0):t.apply(void 0,i(s))}})},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 i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"timestamp";return e=t(e),n=t(n),this.get(i)>e.get(i)&&this.get(i)<n.get(i)},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){var n={};n["en-us"]=f,n["zh-cn"]=d;var i="en-us";"undefined"!=typeof self&&self.navigator&&(i=self.navigator.language.toLowerCase(),n[i]||(i="en-us")),Object.assign(t,{setLanguage:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t=t.toLowerCase(),n[t]=Object.assign(n[t]||{},e),this},switchLanguage:function(t){return i=t.toLowerCase(),this},getLanguage:function(){return n[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]}}),e.onInit((function(){this._langMap=Object.assign(this._langMap,n),this._lang=i}));var r=e.format;Object.assign(e,{format:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"YYYY-MM-DD HH:mm:ss",n=this.clone().toObject(),i=t.getLanguage()||this.getLanguage(),o={};for(var a in o.MMM=i.MMM[n.month-1],o.MMMM=i.MMMM[n.month-1],o.Do=i.Do[n.day-1],o.WW=i.WW[n.week],o.WWW=i.WWW[n.week],o)e=e.replace(a,o[a]||"");return r.bind(this)(e)}})},function(t,e){var n=Intl.DateTimeFormat().resolvedOptions().timeZone,i=0,r=function(t,e){return new Date(t.toLocaleString("en-US",{timeZone:e}))};Object.assign(t,{supportedTimezones:"undefined"!=typeof Intl&&Intl.supportedValuesOf?Intl.supportedValuesOf("timeZone"):[],switchTimezone:function(t){return n=t,i=r(new Date("1970/1/1"),n).getTime()-new Date("1970/1/1").getTime(),this},getTimezoneOffset:function(){return(new Date).getTimezoneOffset()-i/6e4},getTimezone:function(){return n}}),Object.assign(e,{_timezone:null,_offset:0,switchTimezone:function(t){return this._timezone=t,this._offset=r(new Date("1970/1/1"),this._timezone).getTime()-new Date("1970/1/1").getTime(),this},getTimezoneOffset:function(){return this._date.getTimezoneOffset()-this._offset/6e4},getTimezone:function(){return this._timezone}}),e.onInit((function(){this._timezone=n,this._offset=i,arguments.length&&((arguments.length<=0?void 0:arguments[0])instanceof Date||(arguments.length<=0?void 0:arguments[0])instanceof t||1==arguments.length&&"number"==typeof(arguments.length<=0?void 0:arguments[0])||i&&this._date.setTime(this._date.getTime()-i))}));var o=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),o.bind(e)(t)}})}].forEach(h.extend),h}));
|
|
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}));
|
package/dist/datex.min.mjs
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,n){return t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},t(e,n)}function e(n,r,i){return e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}()?Reflect.construct.bind():function(e,n,r){var i=[null];i.push.apply(i,n);var o=new(Function.bind.apply(e,i));return r&&t(o,r.prototype),o},e.apply(null,arguments)}function n(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 r(t){return function(t){if(Array.isArray(t))return n(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 n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(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.")}()}function i(t){return i="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},i(t)}var o=["year","month","day","hour","minute","second","millsecond"],a=[1970,1,1,0,0,0,0],s={day:864e5,hour:36e5,minute:6e4,second:1e3,millsecond:1};var u=[],c={_date:null,init:function(){for(var t=arguments.length,n=new Array(t),s=0;s<t;s++)n[s]=arguments[s];if(n.length){if(Object.getPrototypeOf(n[0])==Object.getPrototypeOf(this))return n[0];if(n[0]instanceof Date)this._date=n[0];else{if(Array.isArray(n[0])?n=a.map((function(t,e){return n[0][e]||t})):null==(g=n[0])||"object"!=i(g)&&"function"!=typeof g||(n=a.map((function(t,e){return n[0][o[e]]||t}))),1==n.length&&"string"==typeof n[0]){var c=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}))?)?/),h=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}))?)?/),f=n[0].match(/^([12]\d{3})(\d{2})(\d{2})(\d{2})?(\d{2})?(\d{2})?(\d{1,3})?/);c&&!h?n=[1,2,3,5,6,8,10].map((function(t,e){return+(c[t]||a[e])})):h?n=[3,1,2,5,6,8,10].map((function(t,e){return+(h[t]||a[e])})):f&&(n=[1,2,3,4,5,6,7].map((function(t,e){return+(f[t]||a[e])})))}n.length>=3&&n[1]--,this._date=e(Date,r(n)),n.length>=2&&!isNaN(n[0])&&n[0]<100&&this._date.setFullYear(n[0])}}else this._date=new Date;var g,d=this;return u.forEach((function(t){t.bind(d).apply(void 0,r(n))})),this},onInit:function(t){u.push(t)}};function h(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return e(h.prototype.init,n)}h.now=Date.now,h.extend=function(t){t(h,c)},h.prototype=c,c.init.prototype=c;var f={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"]},g={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:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]};[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=this,n=t(this.getTime());return Object.getOwnPropertyNames(e).forEach((function(t){"_date"!=t&&(n[t]=e[t])})),n},isValid:function(){return!isNaN(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 void 0!==s[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",e=this.clone(),n=e._date,r=e.toObject(),i=n.toTimeString().match(/GMT([\+\-])(\d{2})(\d{2})/),o={YYYY:""+r.year,YY:(""+r.year).padStart(2,"0"),MM:(""+r.month).padStart(2,"0"),M:""+r.month,DD:(""+r.day).padStart(2,"0"),D:""+r.day,HH:(""+r.hour).padStart(2,"0"),H:""+r.hour,hh:(""+r.hour%12).padStart(2,"0"),h:""+r.hour%12,mm:(""+r.minute).padStart(2,"0"),m:""+r.minute,ss:(""+r.second).padStart(2,"0"),s:""+r.second,S:""+~~(r.millsecond%1e3/100),SS:""+~~(r.millsecond%1e3/10),SSS:""+r.millsecond%1e3,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+|D+|H+|h+|m+|s+|S+|Z+|A|a|X|x|Q|W+/g,(function(t){return o[t]||""}))}})},function(t,e){Object.assign(e,{diffWith:function(e,n){if(!(e=t(e)).isValid())return!1;var r=this.getTime()-e.getTime(),i=0;if(n){if(s[n])i=~~(r/s[n]);else if("month"==n){(i=12*(this.get("year")-1)+this.get("month")-(12*(e.get("year")-1)+e.get("month")))<0&&this.get("day")>e.get("day")?i+=1:i>0&&this.get("day")<e.get("day")&&(i-=1)}else"year"==n&&((i=this.get("year")-e.get("year"))<0&&(this.get("month")>e.get("month")||this.get("month")==e.get("month")&&this.get("day")>e.get("day"))?i+=1:i>0&&(this.get("month")<e.get("month")||this.get("month")==e.get("month")&&this.get("day")<e.get("day"))&&(i-=1));return i}var a=this.clone(),u={};return o.forEach((function(t){u[t]=a.diffWith(e,t),a.set(t,e.get(t))})),u},endOf:function(t){return this.startOf(t).change(t,"week"==t?7:1).change("millsecond",-1)},startOf:function(e){var n=this.toObject(),i=o.indexOf(e)+1,s=this.toArray(),u=a.slice(i);return s.splice.apply(s,[i,u.length].concat(r(u))),"timestamp"==e?this.clone():"week"==e?t(n.year,n.month,n.day-n.week,0,0,0,0):t.apply(void 0,r(s))}})},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){var n={};n["en-us"]=f,n["zh-cn"]=g;var r="en-us";"undefined"!=typeof self&&self.navigator&&(r=self.navigator.language.toLowerCase(),n[r]||(r="en-us")),Object.assign(t,{setLanguage:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t=t.toLowerCase(),n[t]=Object.assign(n[t]||{},e),this},switchLanguage:function(t){return r=t.toLowerCase(),this},getLanguage:function(){return n[r]}}),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]}}),e.onInit((function(){this._langMap=Object.assign(this._langMap,n),this._lang=r}));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",n=this.clone().toObject(),r=t.getLanguage()||this.getLanguage(),o={};for(var a in o.MMM=r.MMM[n.month-1],o.MMMM=r.MMMM[n.month-1],o.Do=r.Do[n.day-1],o.WW=r.WW[n.week],o.WWW=r.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,i=function(t,e){return new Date(t.toLocaleString("en-US",{timeZone:e}))};Object.assign(t,{supportedTimezones:"undefined"!=typeof Intl&&Intl.supportedValuesOf?Intl.supportedValuesOf("timeZone"):[],switchTimezone:function(t){return n=t,r=i(new Date("1970/1/1"),n).getTime()-new Date("1970/1/1").getTime(),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("1970/1/1"),this._timezone).getTime()-new Date("1970/1/1").getTime(),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])instanceof Date||(arguments.length<=0?void 0:arguments[0])instanceof t||1==arguments.length&&"number"==typeof(arguments.length<=0?void 0:arguments[0])||r&&this._date.setTime(this._date.getTime()-r))}));var o=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),o.bind(e)(t)}})}].forEach(h.extend);export{h as default};
|
|
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",
|
|
@@ -22,20 +22,19 @@
|
|
|
22
22
|
"bugs": {
|
|
23
23
|
"url": "https://github.com/mumuy/datex/issues"
|
|
24
24
|
},
|
|
25
|
+
"files":[
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
25
28
|
"devDependencies": {
|
|
26
|
-
"@babel/core": "^7.
|
|
27
|
-
"@babel/plugin-
|
|
28
|
-
"@babel/
|
|
29
|
-
"@babel/
|
|
30
|
-
"@
|
|
31
|
-
"@
|
|
32
|
-
"@rollup/plugin-
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"acorn-import-assertions": "^1.9.0",
|
|
36
|
-
"rollup": "^3.26.3",
|
|
37
|
-
"rollup-plugin-import-assert": "^3.0.1",
|
|
38
|
-
"tape": "^5.6.3"
|
|
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"
|
|
39
38
|
},
|
|
40
39
|
"scripts": {
|
|
41
40
|
"test": "node test/index.js",
|
package/babel.config.js
DELETED