datex.js 1.0.3 → 1.0.4

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 CHANGED
@@ -1,13 +1,13 @@
1
- /*!
2
- * datex.js v1.0.3
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-04-14
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){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}));
1
+ /*!
2
+ * datex.js v1.0.3
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-04-14
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){var e;return t.length?(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]--,this._date=new Date(...t),t.length>=2&&!isNaN(t[0])&&t[0]<100&&this._date.setFullYear(t[0])):this._date=new Date,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,h=this.toArray(),o=r.slice(s);return h.splice(s,o.length,...o),i="timestamp"==t?this.clone():"week"==t?a(e.year,e.month,e.day-e.week,0,0,0,0):a(...h),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/index.html CHANGED
@@ -245,7 +245,7 @@
245
245
  <p class="subtitle">toObject()</p>
246
246
  </div>
247
247
  <div class="c-bd">
248
- <p>运行:datex().toDate()</p>
248
+ <p>运行:datex().toObject()</p>
249
249
  <p>返回:
250
250
  <code></code></p><pre><code>{
251
251
  year:2022,
@@ -427,6 +427,16 @@
427
427
  <td>am / pm</td>
428
428
  <td>上午 下午 小写</td>
429
429
  </tr>
430
+ <tr>
431
+ <td>W</td>
432
+ <td>星期一</td>
433
+ <td>星期X</td>
434
+ </tr>
435
+ <tr>
436
+ <td>w</td>
437
+ <td>周一</td>
438
+ <td>周x</td>
439
+ </tr>
430
440
  <tr>
431
441
  <td>Do</td>
432
442
  <td>1st... 31st</td>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datex.js",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "a datetime format library",
5
5
  "author": "HaoLe Zheng",
6
6
  "license": "MIT",
package/src/datex.js CHANGED
@@ -44,13 +44,10 @@ datex.prototype = {
44
44
  if(argu.length>=3){
45
45
  argu[1]--;
46
46
  }
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);
47
+ this._date = new Date(...argu);
48
+ if(argu.length>=2&&!isNaN(argu[0])&&argu[0]<100){
49
+ this._date.setFullYear(argu[0]);
52
50
  }
53
-
54
51
  }
55
52
  return this;
56
53
  },
@@ -1,54 +1,54 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <svg width="1440px" height="448px" viewBox="0 0 1440 448" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
- <!-- Generator: Sketch 59.1 (86144) - https://sketch.com -->
4
- <title>编组 5备份</title>
5
- <desc>Created with Sketch.</desc>
6
- <defs>
7
- <linearGradient x1="-5.68700053%" y1="45.5298642%" x2="84.7892757%" y2="53.934985%" id="linearGradient-1">
8
- <stop stop-color="#FBFCFD" offset="0%"></stop>
9
- <stop stop-color="#F8FCFF" offset="100%"></stop>
10
- </linearGradient>
11
- <radialGradient cx="49.4552285%" cy="50%" fx="49.4552285%" fy="50%" r="94.8348304%" gradientTransform="translate(0.494552,0.500000),scale(0.311111,1.000000),rotate(90.000000),translate(-0.494552,-0.500000)" id="radialGradient-2">
12
- <stop stop-color="#FFFFFF" stop-opacity="0.5" offset="0%"></stop>
13
- <stop stop-color="#EDF6FF" stop-opacity="0.578179633" offset="100%"></stop>
14
- </radialGradient>
15
- <rect id="path-3" x="0" y="0" width="1440" height="448"></rect>
16
- <linearGradient x1="72.8463444%" y1="12.5451885%" x2="72.8463444%" y2="295.836589%" id="linearGradient-5">
17
- <stop stop-color="#FFFFFF" stop-opacity="0" offset="0%"></stop>
18
- <stop stop-color="#9FD7FF" stop-opacity="0.383058348" offset="100%"></stop>
19
- </linearGradient>
20
- <linearGradient x1="16.6159843%" y1="49.1386719%" x2="5.85340543%" y2="50.8613281%" id="linearGradient-6">
21
- <stop stop-color="#FFFFFF" stop-opacity="0" offset="0%"></stop>
22
- <stop stop-color="#F2F7FC" offset="100%"></stop>
23
- </linearGradient>
24
- <rect id="path-7" x="0" y="259" width="1440" height="189"></rect>
25
- <linearGradient x1="54.7550093%" y1="16.6478641%" x2="54.7550093%" y2="112.331979%" id="linearGradient-8">
26
- <stop stop-color="#FFFFFF" stop-opacity="0" offset="0%"></stop>
27
- <stop stop-color="#D2ECFF" stop-opacity="0.225387893" offset="100%"></stop>
28
- </linearGradient>
29
- </defs>
30
- <g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
31
- <g id="导航方案备份">
32
- <g id="编组-5备份">
33
- <g id="路径备份">
34
- <g id="蒙版">
35
- <g transform="translate(0.000000, 0.000000)">
36
- <mask id="mask-4" fill="white">
37
- <use xlink:href="#path-3"></use>
38
- </mask>
39
- <g>
40
- <use fill="url(#linearGradient-1)" xlink:href="#path-3"></use>
41
- <use fill="url(#radialGradient-2)" xlink:href="#path-3"></use>
42
- </g>
43
- <g id="矩形备份-32" mask="url(#mask-4)">
44
- <use fill="url(#linearGradient-5)" xlink:href="#path-7"></use>
45
- <use fill="url(#linearGradient-6)" xlink:href="#path-7"></use>
46
- </g>
47
- <rect id="矩形" fill="url(#linearGradient-8)" mask="url(#mask-4)" x="0" y="166" width="1440" height="282"></rect>
48
- </g>
49
- </g>
50
- </g>
51
- </g>
52
- </g>
53
- </g>
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="1440px" height="448px" viewBox="0 0 1440 448" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <!-- Generator: Sketch 59.1 (86144) - https://sketch.com -->
4
+ <title>编组 5备份</title>
5
+ <desc>Created with Sketch.</desc>
6
+ <defs>
7
+ <linearGradient x1="-5.68700053%" y1="45.5298642%" x2="84.7892757%" y2="53.934985%" id="linearGradient-1">
8
+ <stop stop-color="#FBFCFD" offset="0%"></stop>
9
+ <stop stop-color="#F8FCFF" offset="100%"></stop>
10
+ </linearGradient>
11
+ <radialGradient cx="49.4552285%" cy="50%" fx="49.4552285%" fy="50%" r="94.8348304%" gradientTransform="translate(0.494552,0.500000),scale(0.311111,1.000000),rotate(90.000000),translate(-0.494552,-0.500000)" id="radialGradient-2">
12
+ <stop stop-color="#FFFFFF" stop-opacity="0.5" offset="0%"></stop>
13
+ <stop stop-color="#EDF6FF" stop-opacity="0.578179633" offset="100%"></stop>
14
+ </radialGradient>
15
+ <rect id="path-3" x="0" y="0" width="1440" height="448"></rect>
16
+ <linearGradient x1="72.8463444%" y1="12.5451885%" x2="72.8463444%" y2="295.836589%" id="linearGradient-5">
17
+ <stop stop-color="#FFFFFF" stop-opacity="0" offset="0%"></stop>
18
+ <stop stop-color="#9FD7FF" stop-opacity="0.383058348" offset="100%"></stop>
19
+ </linearGradient>
20
+ <linearGradient x1="16.6159843%" y1="49.1386719%" x2="5.85340543%" y2="50.8613281%" id="linearGradient-6">
21
+ <stop stop-color="#FFFFFF" stop-opacity="0" offset="0%"></stop>
22
+ <stop stop-color="#F2F7FC" offset="100%"></stop>
23
+ </linearGradient>
24
+ <rect id="path-7" x="0" y="259" width="1440" height="189"></rect>
25
+ <linearGradient x1="54.7550093%" y1="16.6478641%" x2="54.7550093%" y2="112.331979%" id="linearGradient-8">
26
+ <stop stop-color="#FFFFFF" stop-opacity="0" offset="0%"></stop>
27
+ <stop stop-color="#D2ECFF" stop-opacity="0.225387893" offset="100%"></stop>
28
+ </linearGradient>
29
+ </defs>
30
+ <g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
31
+ <g id="导航方案备份">
32
+ <g id="编组-5备份">
33
+ <g id="路径备份">
34
+ <g id="蒙版">
35
+ <g transform="translate(0.000000, 0.000000)">
36
+ <mask id="mask-4" fill="white">
37
+ <use xlink:href="#path-3"></use>
38
+ </mask>
39
+ <g>
40
+ <use fill="url(#linearGradient-1)" xlink:href="#path-3"></use>
41
+ <use fill="url(#radialGradient-2)" xlink:href="#path-3"></use>
42
+ </g>
43
+ <g id="矩形备份-32" mask="url(#mask-4)">
44
+ <use fill="url(#linearGradient-5)" xlink:href="#path-7"></use>
45
+ <use fill="url(#linearGradient-6)" xlink:href="#path-7"></use>
46
+ </g>
47
+ <rect id="矩形" fill="url(#linearGradient-8)" mask="url(#mask-4)" x="0" y="166" width="1440" height="282"></rect>
48
+ </g>
49
+ </g>
50
+ </g>
51
+ </g>
52
+ </g>
53
+ </g>
54
54
  </svg>