datex.js 1.0.2 → 1.0.3
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/package.json +1 -1
- package/src/datex.js +7 -1
package/dist/datex.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* datex.js v1.0.
|
|
2
|
+
* datex.js v1.0.3
|
|
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: 2023-04-
|
|
11
|
+
* Created on: 2023-04-14
|
|
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";let t={"en-US":{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"],W:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],w:["Sun.","Mon.","Tues.","Wed.","Thur.","Fri.","Sat."]},"zh-CN":{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日"],W:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],w:["周日","周一","周二","周三","周四","周五","周六"]}},e=t["en-US"];"undefined"!=typeof self&&self.navigator&&(e=t[self.navigator.language]);const n=["year","month","day","hour","minute","second","millsecond"],r=[1970,1,1,0,0,0,0];function a(...t){return new a.prototype.init(...t)}function i(t){return t instanceof a?t:a(t)}return a.prototype={_date:null,init:function(...t){
|
|
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";let t={"en-US":{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"],W:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],w:["Sun.","Mon.","Tues.","Wed.","Thur.","Fri.","Sat."]},"zh-CN":{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日"],W:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],w:["周日","周一","周二","周三","周四","周五","周六"]}},e=t["en-US"];"undefined"!=typeof self&&self.navigator&&(e=t[self.navigator.language]);const n=["year","month","day","hour","minute","second","millsecond"],r=[1970,1,1,0,0,0,0];function a(...t){return new a.prototype.init(...t)}function i(t){return t instanceof a?t:a(t)}return a.prototype={_date:null,init:function(...t){if(t.length)if(Array.isArray(t[0])?t=r.map(((e,n)=>t[0][n]||e)):null==(e=t[0])||"object"!=typeof e&&"function"!=typeof e||(t=r.map(((e,r)=>t[0][n[r]]||e))),t.length>=3&&t[1]--,"number"==typeof t[0]&&t[0]<100){let e=new Date(...t).setFullYear(t[0]);this._date=new Date(e)}else this._date=new Date(...t);else this._date=new Date;var e;return this},getTime(){return this._date.getTime()},getUnix(){return~~(this._date.getTime()/1e3)},clone(){return a(this.getTime())},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 t=this.toObject();return n.map((e=>t[e]))},toString(){return this._date.toString()},toISOString(){return this._date.toISOString()},set(t,e){let 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},get(t){return this.toObject()[t]},change(t,e){let n=this.toObject();return this.set(t,n[t]+e)},format(t="YYYY-MM-DD HH:mm:ss"){let n=this._date,r=this.toObject(),a=n.toTimeString().match(/GMT([\+\-])(\d{2})(\d{2})/),i={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:a[1]+a[2]+":"+a[3],ZZ:a[1]+a[2]+a[3],A:["AM","PM"][~~(r.hour/12)],a:["am","pm"][~~(r.hour/12)],X:~~(r.timestamp/1e3),x:r.timestamp,Q:""+~~(r.month/3)};return i.MMM=e.MMM[r.month-1],i.MMMM=e.MMMM[r.month-1],i.Do=e.Do[r.day-1],i.W=e.W[r.week],i.w=e.w[r.week],t.replace(/Y+|M+|D+|H+|h+|m+|s+|S+|Z+|Do|A|a|X|x|Q|W|w/g,(function(t){return i[t]||""}))},startOf(t){let e=this.toObject(),i=null,s=n.indexOf(t)+1,o=this.toArray(),h=r.slice(s);return o.splice(s,h.length,...h),i="timestamp"==t?this.clone():"week"==t?a(e.year,e.month,e.day-e.week,0,0,0,0):a(...o),i},endOf(t){return this.startOf(t).change(t,"week"==t?7:1).change("millsecond",-1)},diffWith(t,e){if(!(t=i(t)).isValid())return!1;let r={day:864e5,hour:36e5,minute:6e4,second:1e3,millsecond:1},a=this.getTime()-t.getTime(),s=0;if(e){if(r[e])s=~~(a/r[e]);else if("month"==e){s=12*(this.get("year")-1)+this.get("month")-(12*(t.get("year")-1)+t.get("month")),s<0&&this.get("day")>t.get("day")?s+=1:s>0&&this.get("day")<t.get("day")&&(s-=1)}else"year"==e&&(s=this.get("year")-t.get("year"),s<0&&(this.get("month")>t.get("month")||this.get("month")==t.get("month")&&this.get("day")>t.get("day"))?s+=1:s>0&&(this.get("month")<t.get("month")||this.get("month")==t.get("month")&&this.get("day")<t.get("day"))&&(s-=1));return s}{let e=this.clone(),r={};return n.forEach((function(n){r[n]=e.diffWith(t,n),e.set(n,t.get(n))})),r}},isBefore(t,e="timestamp"){return t=i(t),this.get(e)<t.get(e)},isAfter(t,e="timestamp"){return t=i(t),this.get(e)>t.get(e)},isSame(t,e="timestamp"){return t=i(t),this.get(e)==t.get(e)},isBetween(t,e,n="timestamp"){return t=i(t),e=i(e),this.get(n)>t.get(n)&&this.get(n)<e.get(n)},isValid(){return!isNaN(this.getTime())}},a.prototype.init.prototype=a.prototype,a}));
|
package/package.json
CHANGED
package/src/datex.js
CHANGED
|
@@ -44,7 +44,13 @@ datex.prototype = {
|
|
|
44
44
|
if(argu.length>=3){
|
|
45
45
|
argu[1]--;
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
if(typeof argu[0]=='number'&&argu[0]<100){
|
|
48
|
+
let t = new Date(...argu).setFullYear(argu[0]);
|
|
49
|
+
this._date = new Date(t);
|
|
50
|
+
}else{
|
|
51
|
+
this._date = new Date(...argu);
|
|
52
|
+
}
|
|
53
|
+
|
|
48
54
|
}
|
|
49
55
|
return this;
|
|
50
56
|
},
|