datex.js 1.0.11 → 1.0.12
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/babel.config.js +13 -0
- package/dist/datex.min.js +2 -2
- package/dist/datex.min.mjs +13 -0
- package/index.html +22 -2
- package/package.json +20 -5
- package/rollup.config.mjs +52 -0
- package/src/module/prototype.js +1 -1
- package/static/image/word_map.png +0 -0
- package/static/script/timezone.js +432 -0
- package/static/style/index.css +2 -0
- package/static/style/timezone.css +462 -0
- package/timezone.html +334 -0
- package/gulpfile.js +0 -37
package/babel.config.js
ADDED
package/dist/datex.min.js
CHANGED
|
@@ -8,6 +8,6 @@
|
|
|
8
8
|
* Released under the MIT License
|
|
9
9
|
* https://github.com/mumuy/datex
|
|
10
10
|
*
|
|
11
|
-
* Created on: 2023-
|
|
11
|
+
* Created on: 2023-10-27
|
|
12
12
|
*/
|
|
13
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).datex=e()}(this,(function(){"use strict";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(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}));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* datex.js v1.0.11
|
|
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: 2023-10-27
|
|
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};
|
package/index.html
CHANGED
|
@@ -198,6 +198,12 @@
|
|
|
198
198
|
<span class="subtitle">now()</span>
|
|
199
199
|
</a>
|
|
200
200
|
</li>
|
|
201
|
+
<li>
|
|
202
|
+
<a href="#hash28">
|
|
203
|
+
<span class="title">插件扩展</span>
|
|
204
|
+
<span class="subtitle">extend()</span>
|
|
205
|
+
</a>
|
|
206
|
+
</li>
|
|
201
207
|
</ul>
|
|
202
208
|
</div>
|
|
203
209
|
</div>
|
|
@@ -217,7 +223,11 @@
|
|
|
217
223
|
<div class="hd">
|
|
218
224
|
<h1>datex时间格式化工具<span class="tag">开源算法</span></h1>
|
|
219
225
|
<p>极度轻巧的时间格式化处理工具,适用于多数网页时间应用场景</p>
|
|
220
|
-
<p
|
|
226
|
+
<p>
|
|
227
|
+
<a class="btn" href="https://passer-by.com/datex/dist/datex.min.js" target="_blank">获取脚本</a>
|
|
228
|
+
<a class="btn btn-green" href="https://passer-by.com/datex/timezone.html" target="_blank">世界时间</a>
|
|
229
|
+
<a class="btn btn-orange" href="https://passer-by.com/calendar/" target="_blank">中华万年历</a>
|
|
230
|
+
</p>
|
|
221
231
|
</div>
|
|
222
232
|
<div class="bd">
|
|
223
233
|
<div id="hash0" class="box">
|
|
@@ -1167,6 +1177,16 @@
|
|
|
1167
1177
|
<p>运行:datex.now()</p>
|
|
1168
1178
|
</div>
|
|
1169
1179
|
</div>
|
|
1180
|
+
<div id="hash28" class="box">
|
|
1181
|
+
<div class="c-hd">
|
|
1182
|
+
<p class="title">插件扩展</p>
|
|
1183
|
+
<p class="subtitle">extend()</p>
|
|
1184
|
+
</div>
|
|
1185
|
+
<div class="c-bd">
|
|
1186
|
+
<p>全局设置</p>
|
|
1187
|
+
<p>运行:datex.extend(pluginsLoader)</p>
|
|
1188
|
+
</div>
|
|
1189
|
+
</div>
|
|
1170
1190
|
</div>
|
|
1171
1191
|
</div>
|
|
1172
1192
|
</div>
|
|
@@ -1184,6 +1204,7 @@
|
|
|
1184
1204
|
</div>
|
|
1185
1205
|
</div>
|
|
1186
1206
|
</div>
|
|
1207
|
+
<script type="text/javascript" src="https://passer-by.com/public/script/projects.js"></script>
|
|
1187
1208
|
<div class="mod-foot">
|
|
1188
1209
|
<div class="inner">
|
|
1189
1210
|
<div class="bd">
|
|
@@ -1191,7 +1212,6 @@
|
|
|
1191
1212
|
</div>
|
|
1192
1213
|
</div>
|
|
1193
1214
|
</div>
|
|
1194
|
-
<script type="text/javascript" src="https://passer-by.com/public/script/projects.js"></script>
|
|
1195
1215
|
</div>
|
|
1196
1216
|
</div>
|
|
1197
1217
|
<script type="text/javascript" src="https://jquerywidget.com/public/script/jquery.min.js"></script>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "datex.js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
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"
|
|
@@ -18,14 +23,24 @@
|
|
|
18
23
|
"url": "https://github.com/mumuy/datex/issues"
|
|
19
24
|
},
|
|
20
25
|
"devDependencies": {
|
|
26
|
+
"@babel/core": "^7.23.2",
|
|
27
|
+
"@babel/plugin-syntax-import-attributes": "^7.22.5",
|
|
28
|
+
"@babel/plugin-transform-class-properties": "^7.22.5",
|
|
29
|
+
"@babel/plugin-transform-runtime": "^7.23.2",
|
|
30
|
+
"@babel/preset-env": "^7.23.2",
|
|
31
|
+
"@babel/runtime": "^7.23.2",
|
|
32
|
+
"@rollup/plugin-babel": "^6.0.3",
|
|
33
|
+
"@rollup/plugin-node-resolve": "^15.1.0",
|
|
21
34
|
"@rollup/plugin-terser": "^0.4.1",
|
|
22
|
-
"
|
|
23
|
-
"rollup": "^3.
|
|
35
|
+
"acorn-import-assertions": "^1.9.0",
|
|
36
|
+
"rollup": "^3.26.3",
|
|
37
|
+
"rollup-plugin-import-assert": "^3.0.1",
|
|
24
38
|
"tape": "^5.6.3"
|
|
25
39
|
},
|
|
26
40
|
"scripts": {
|
|
27
41
|
"test": "node test/index.js",
|
|
28
|
-
"build": "
|
|
42
|
+
"build": "rollup -c && npm run test",
|
|
43
|
+
"watch": "rollup -wc"
|
|
29
44
|
},
|
|
30
45
|
"homepage": "https://passer-by.com/datex/",
|
|
31
46
|
"directories": {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import resolve from '@rollup/plugin-node-resolve'; // 使用node_modules包
|
|
2
|
+
import terser from '@rollup/plugin-terser'; // 代码压缩
|
|
3
|
+
import babel from '@rollup/plugin-babel'; // ECMAScript兼容
|
|
4
|
+
import {importAssertionsPlugin} from 'rollup-plugin-import-assert';
|
|
5
|
+
import {importAssertions} from 'acorn-import-assertions';
|
|
6
|
+
import pkg from './package.json' assert { type:'json' }; // 获取package信息
|
|
7
|
+
|
|
8
|
+
// 版权信息
|
|
9
|
+
const repository = pkg.repository.url.replace(/(.+)(:\/\/.+)\.git$/,'https$2');
|
|
10
|
+
const now = new Date();
|
|
11
|
+
const date = (new Date(now.getTime()-now.getTimezoneOffset()*60000)).toISOString().substr(0,10);
|
|
12
|
+
const banner = `/*!
|
|
13
|
+
* ${pkg.name} v${pkg.version}
|
|
14
|
+
* ${pkg.description}
|
|
15
|
+
* ${pkg.homepage}
|
|
16
|
+
*
|
|
17
|
+
* Copyright (c) 2022-present, ${pkg.author}
|
|
18
|
+
*
|
|
19
|
+
* Released under the ${pkg.license} License
|
|
20
|
+
* ${repository}
|
|
21
|
+
*
|
|
22
|
+
* Created on: ${date}
|
|
23
|
+
*/`;
|
|
24
|
+
|
|
25
|
+
const commonPlugins = [
|
|
26
|
+
resolve(),
|
|
27
|
+
importAssertionsPlugin(),
|
|
28
|
+
terser(),
|
|
29
|
+
babel({
|
|
30
|
+
babelHelpers: 'runtime',
|
|
31
|
+
exclude:'node_modules/**'
|
|
32
|
+
})
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
export default [{
|
|
36
|
+
input: './src/datex.js',
|
|
37
|
+
output:[{
|
|
38
|
+
file: pkg.main,
|
|
39
|
+
format: 'umd',
|
|
40
|
+
name: 'datex',
|
|
41
|
+
banner
|
|
42
|
+
},{
|
|
43
|
+
file: pkg.module,
|
|
44
|
+
format: 'es',
|
|
45
|
+
banner
|
|
46
|
+
}],
|
|
47
|
+
acornInjectPlugins: [ importAssertions ],
|
|
48
|
+
plugins: commonPlugins,
|
|
49
|
+
watch: {
|
|
50
|
+
exclude: 'node_modules/**'
|
|
51
|
+
}
|
|
52
|
+
}];
|
package/src/module/prototype.js
CHANGED
|
Binary file
|