datex.js 1.0.12 → 1.0.16

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/rollup.config.mjs DELETED
@@ -1,52 +0,0 @@
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/datex.js DELETED
@@ -1,17 +0,0 @@
1
- import datex from './module/factory';
2
- import baseLoader from './module/method/base';
3
- import computeLoader from './module/method/compute';
4
- import compareLoader from './module/method/compare';
5
- import languageLoader from './module/method/language';
6
- import timezoneLoader from './module/method/timezone';
7
-
8
- // 功能加载
9
- [
10
- baseLoader,
11
- computeLoader,
12
- compareLoader,
13
- languageLoader,
14
- timezoneLoader
15
- ].forEach(datex.extend);
16
-
17
- export default datex;
@@ -1,20 +0,0 @@
1
- import prototype from './prototype';
2
-
3
- // 构造器
4
- function datex(...argu){
5
- return new datex.prototype.init(...argu);
6
- }
7
-
8
- // 当前时间
9
- datex.now = Date.now;
10
-
11
- // 原型加载方法
12
- datex.extend = function(loader){
13
- loader(datex,prototype);
14
- };
15
-
16
- // 初始化 - 类似于jQuery
17
- datex.prototype = prototype;
18
- prototype.init.prototype = prototype;
19
-
20
- export default datex;
@@ -1,135 +0,0 @@
1
- import {periodKey,periodTime} from './map/period';
2
-
3
- export default function(datex,proto){
4
-
5
- Object.assign(proto,{
6
- toDate(){
7
- return this._date;
8
- },
9
- toObject(){
10
- let _ = this._date;
11
- return {
12
- 'year':_.getFullYear(),
13
- 'month':_.getMonth()+1,
14
- 'day':_.getDate(),
15
- 'hour':_.getHours(),
16
- 'minute':_.getMinutes(),
17
- 'second':_.getSeconds(),
18
- 'millsecond':_.getMilliseconds(),
19
- 'timestamp':_.getTime(),
20
- 'week':_.getDay()
21
- };
22
- },
23
- toArray(){
24
- let $ = this.toObject();
25
- return periodKey.map(name=>$[name]);
26
- },
27
- toString(){
28
- return this._date.toString();
29
- },
30
- toISOString(){
31
- return this._date.toISOString();
32
- },
33
- getTime(){
34
- return this._date.getTime();
35
- },
36
- getUnix(){
37
- return ~~(this._date.getTime()/1000);
38
- },
39
- clone(){
40
- let that = this;
41
- let clone = datex(this.getTime());
42
- Object.getOwnPropertyNames(that).forEach(function(name){
43
- if(name!='_date'){
44
- clone[name] = that[name];
45
- }
46
- });
47
- return clone;
48
- },
49
- isValid(){
50
- return !isNaN(this.getTime());
51
- },
52
- set(unit,value){
53
- let _ = this._date;
54
- let $ = this.toObject();
55
- switch (unit) {
56
- case 'year':
57
- _.setFullYear(value);
58
- break;
59
- case 'month':
60
- _.setMonth(value-1);
61
- break;
62
- case 'day':
63
- _.setDate(value);
64
- break;
65
- case 'hour':
66
- _.setHours(value);
67
- break;
68
- case 'minute':
69
- _.setMinutes(value);
70
- break;
71
- case 'second':
72
- _.setSeconds(value);
73
- break;
74
- case 'millsecond':
75
- _.setMilliseconds(value);
76
- break;
77
- case 'timestamp':
78
- _.setTime(value);
79
- break;
80
- case 'week':
81
- _.setDate($.day-$.week+value);
82
- break;
83
- }
84
- return this;
85
- },
86
- change(unit,value){
87
- let $ = this.toObject();
88
- if(typeof periodTime[unit]!='undefined'){
89
- return this.set('timestamp',$['timestamp']+value*periodTime[unit]);
90
- }else{
91
- return this.set(unit,$[unit]+value);
92
- }
93
- },
94
- get(unit){
95
- let $ = this.toObject();
96
- return $[unit];
97
- },
98
- format(pattern = 'YYYY-MM-DD HH:mm:ss'){
99
- let that = this.clone();
100
- let _ = that._date;
101
- let $ = that.toObject();
102
- let match = _.toTimeString().match(/GMT([\+\-])(\d{2})(\d{2})/);
103
- let map = {
104
- 'YYYY':''+$.year,
105
- 'YY':(''+$.year).padStart(2,'0'),
106
- 'MM':(''+$.month).padStart(2,'0'),
107
- 'M':''+$.month,
108
- 'DD':(''+$.day).padStart(2,'0'),
109
- 'D':''+$.day,
110
- 'HH':(''+$.hour).padStart(2,'0'),
111
- 'H':''+$.hour,
112
- 'hh':(''+($.hour%12)).padStart(2,'0'),
113
- 'h':''+($.hour%12),
114
- 'mm':(''+$.minute).padStart(2,'0'),
115
- 'm':''+$.minute,
116
- 'ss':(''+$.second).padStart(2,'0'),
117
- 's':''+$.second,
118
- 'S':''+(~~(($.millsecond%1000)/100)),
119
- 'SS':''+(~~(($.millsecond%1000)/10)),
120
- 'SSS':''+($.millsecond%1000),
121
- 'Z':match[1]+match[2]+':'+match[3],
122
- 'ZZ':match[1]+match[2]+match[3],
123
- 'A':['AM','PM'][~~($.hour/12)],
124
- 'a':['am','pm'][~~($.hour/12)],
125
- 'X':$.timestamp,
126
- 'x':~~($.timestamp/1000),
127
- 'Q':''+(~~($.month/3)),
128
- 'W':$.week
129
- };
130
- return pattern.replace(/Y+|M+|D+|H+|h+|m+|s+|S+|Z+|A|a|X|x|Q|W+/g,function(key){
131
- return map[key]||'';
132
- });
133
- }
134
- });
135
- };
@@ -1,22 +0,0 @@
1
- export default function(datex,proto){
2
-
3
- Object.assign(proto,{
4
- isAfter(that,unit = 'timestamp'){
5
- that = datex(that);
6
- return this.get(unit)>that.get(unit);
7
- },
8
- isBefore(that,unit = 'timestamp'){
9
- that = datex(that);
10
- return this.get(unit)<that.get(unit);
11
- },
12
- isBetween(startDate,endDate,unit = 'timestamp'){
13
- startDate = datex(startDate);
14
- endDate = datex(endDate);
15
- return this.get(unit)>startDate.get(unit)&&this.get(unit)<endDate.get(unit);
16
- },
17
- isSame(that,unit = 'timestamp'){
18
- that = datex(that);
19
- return this.get(unit)==that.get(unit);
20
- }
21
- });
22
- };
@@ -1,64 +0,0 @@
1
- import {periodKey,periodValue,periodTime} from './map/period';
2
-
3
- export default function(datex,proto){
4
-
5
- Object.assign(proto,{
6
- diffWith(that,unit){
7
- that = datex(that);
8
- if(!that.isValid()){
9
- return false;
10
- }
11
- let timestamp = this.getTime()-that.getTime();
12
- let value = 0;
13
- if(unit){
14
- if(periodTime[unit]){
15
- value = ~~(timestamp/periodTime[unit]);
16
- }else if(unit=='month'){
17
- let this_month = 12*(this.get('year')-1)+this.get('month');
18
- let that_month = 12*(that.get('year')-1)+that.get('month');
19
- value = this_month -that_month;
20
- if(value<0&&this.get('day')>that.get('day')){
21
- value+=1;
22
- }else if(value>0&&this.get('day')<that.get('day')){
23
- value-=1;
24
- }
25
- }else if(unit=='year'){
26
- value = this.get('year') - that.get('year');
27
- if(value<0&&(this.get('month')>that.get('month')||this.get('month')==that.get('month')&&this.get('day')>that.get('day'))){
28
- value+=1;
29
- }else if(value>0&&(this.get('month')<that.get('month')||this.get('month')==that.get('month')&&this.get('day')<that.get('day'))){
30
- value-=1;
31
- }
32
- }
33
- return value;
34
- }else{
35
- let clone = this.clone();
36
- let hash = {};
37
- periodKey.forEach(function(unit){
38
- hash[unit] = clone.diffWith(that,unit);
39
- clone.set(unit,that.get(unit));
40
- });
41
- return hash;
42
- }
43
- },
44
- endOf(unit){
45
- return this.startOf(unit).change(unit,unit=='week'?7:1).change('millsecond',-1);
46
- },
47
- startOf(unit){
48
- let $ = this.toObject();
49
- let that = null;
50
- let index = periodKey.indexOf(unit)+1;
51
- let dateSet = this.toArray();
52
- let initSet = periodValue.slice(index);
53
- dateSet.splice(index,initSet.length,...initSet);
54
- if(unit=='timestamp'){
55
- that = this.clone();
56
- }else if(unit=='week'){
57
- that = datex($.year,$.month,$.day-$.week,0,0,0,0);
58
- }else{
59
- that = datex(...dateSet);
60
- }
61
- return that;
62
- }
63
- });
64
- };
@@ -1,72 +0,0 @@
1
- import en_us from './locale/en-us';
2
- import zh_cn from './locale/zh-cn';
3
-
4
- export default function(datex,proto){
5
- let _langMap = {};
6
- _langMap['en-us'] = en_us;
7
- _langMap['zh-cn'] = zh_cn;
8
- let _lang = 'en-us';
9
- if(typeof self!='undefined'&&self.navigator){
10
- _lang = self.navigator.language.toLowerCase();
11
- if (!_langMap[_lang]) {
12
- _lang = 'en-us';
13
- }
14
- }
15
-
16
- Object.assign(datex,{
17
- setLanguage(lang,data={}){
18
- lang = lang.toLowerCase();
19
- _langMap[lang] = Object.assign(_langMap[lang]||{},data);
20
- return this;
21
- },
22
- switchLanguage(lang){
23
- _lang = lang.toLowerCase();
24
- return this;
25
- },
26
- getLanguage(){
27
- return _langMap[_lang];
28
- }
29
- });
30
-
31
- Object.assign(proto,{
32
- _langMap:{},
33
- _lang:null,
34
- setLanguage(lang,data={}){
35
- lang = lang.toLowerCase();
36
- this._langMap[lang] = Object.assign(this._langMap[lang]||{},data);
37
- return this;
38
- },
39
- switchLanguage(lang){
40
- this._lang = lang.toLowerCase();
41
- return this;
42
- },
43
- getLanguage(){
44
- return this._langMap[this._lang];
45
- }
46
- });
47
-
48
- proto.onInit(function(){
49
- this._langMap = Object.assign(this._langMap,_langMap);
50
- this._lang = _lang;
51
- });
52
-
53
- // 重写
54
- let format = proto.format;
55
- Object.assign(proto,{
56
- format(pattern = 'YYYY-MM-DD HH:mm:ss'){
57
- let that = this.clone();
58
- let $ = that.toObject();
59
- let language = datex.getLanguage()||this.getLanguage();
60
- let map = {};
61
- map['MMM'] = language['MMM'][$.month-1];
62
- map['MMMM'] = language['MMMM'][$.month-1];
63
- map['Do'] = language['Do'][$.day-1];
64
- map['WW'] = language['WW'][$.week];
65
- map['WWW'] = language['WWW'][$.week];
66
- for (let key in map) {
67
- pattern = pattern.replace(key,map[key]||'');
68
- }
69
- return format.bind(this)(pattern);
70
- }
71
- });
72
- };
@@ -1,7 +0,0 @@
1
- export default {
2
- 'MMM':['Jan.','Feb.','Mar.','Apr.','May.','Jun.','Jul.','Aug.','Sept.','Oct.','Nov.','Dec.'],
3
- 'MMMM':['January','February','March','April','May','June','July','August','September','October','November','December'],
4
- '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'],
5
- 'WW':['Sun.','Mon.','Tues.','Wed.','Thur.','Fri.','Sat.'],
6
- 'WWW':['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
7
- };
@@ -1,7 +0,0 @@
1
- export default {
2
- 'MMM':['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
3
- 'MMMM':['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
4
- '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日'],
5
- 'WW':['周日','周一','周二','周三','周四','周五','周六'],
6
- 'WWW':['星期日','星期一','星期二','星期三','星期四','星期五','星期六'],
7
- };
@@ -1,9 +0,0 @@
1
- export const periodKey = ['year','month','day','hour','minute','second','millsecond'];
2
- export const periodValue = [1970,1,1,0,0,0,0];
3
- export const periodTime = {
4
- 'day':8.64e7,
5
- 'hour':3.6e6,
6
- 'minute':6e4,
7
- 'second':1000,
8
- 'millsecond':1
9
- };
@@ -1,60 +0,0 @@
1
- export default function(datex,proto){
2
- let _timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
3
- let _offset = 0;
4
-
5
- const convertTimeZone = (date, timeZone) => {return new Date(date.toLocaleString('en-US', { timeZone }))};
6
-
7
- Object.assign(datex,{
8
- supportedTimezones:(typeof Intl!='undefined'&&Intl.supportedValuesOf?Intl.supportedValuesOf('timeZone'):[]),
9
- switchTimezone(timeZone){
10
- _timezone = timeZone;
11
- _offset = convertTimeZone(new Date('1970/1/1'),_timezone).getTime() - (new Date('1970/1/1')).getTime();
12
- return this;
13
- },
14
- getTimezoneOffset(){
15
- return (new Date).getTimezoneOffset() - _offset/60000;
16
- },
17
- getTimezone(){
18
- return _timezone;
19
- }
20
- });
21
-
22
- Object.assign(proto,{
23
- _timezone:null,
24
- _offset:0,
25
- switchTimezone(timezone){
26
- this._timezone = timezone;
27
- this._offset = convertTimeZone(new Date('1970/1/1'),this._timezone).getTime() - (new Date('1970/1/1')).getTime();
28
- return this;
29
- },
30
- getTimezoneOffset(){
31
- return this._date.getTimezoneOffset() - this._offset/60000;
32
- },
33
- getTimezone(){
34
- return this._timezone;
35
- }
36
- });
37
-
38
- proto.onInit(function(...argu){
39
- this._timezone = _timezone;
40
- this._offset = _offset;
41
- if(argu.length){
42
- if(argu[0] instanceof Date){
43
- }else if(argu[0] instanceof datex){
44
- }else if(argu.length==1&&typeof argu[0]=='number'){
45
- }else if(_offset){
46
- this._date.setTime(this._date.getTime()-_offset);
47
- }
48
- }
49
- });
50
-
51
- // 重写
52
- let format = proto.format;
53
- Object.assign(proto,{
54
- format(pattern = 'YYYY-MM-DD HH:mm:ss'){
55
- let that = this.clone();
56
- that._date.setTime(that._date.getTime()+that._offset);
57
- return format.bind(that)(pattern);
58
- }
59
- });
60
- };
@@ -1,63 +0,0 @@
1
- import {periodKey,periodValue} from './method/map/period';
2
-
3
- function isObject(value){
4
- return value != null && (typeof value == 'object' || typeof value == 'function');
5
- }
6
-
7
- let taskQueue = [];
8
-
9
- export default {
10
- _date:null,
11
- init:function(...argu){
12
- if(argu.length){
13
-
14
- if(Object.getPrototypeOf(argu[0])==Object.getPrototypeOf(this)){
15
- return argu[0];
16
- }else if(argu[0] instanceof Date){
17
- this._date = argu[0];
18
- }else{
19
- if(Array.isArray(argu[0])){
20
- argu = periodValue.map((value,index)=>(argu[0][index]||value));
21
- }else if(isObject(argu[0])){
22
- argu = periodValue.map((value,index)=>(argu[0][periodKey[index]]||value));
23
- }
24
- if(argu.length==1&&typeof argu[0]=='string'){
25
- let matchs1 = argu[0].match(/(\d{1,4})[\-\/](\d{1,2})[\-\/](\d{1,2})([\sT](\d{1,2})?:(\d{1,2})?(:(\d{1,2}))?(\.(\d{1,3}))?)?/);
26
- let matchs2 = argu[0].match(/(\d{1,2})[\-\/](\d{1,2})[\-\/](\d{3,4})([\sT](\d{1,2})?:(\d{1,2})?(:(\d{1,2}))?(\.(\d{1,3}))?)?/);
27
- let matchs3 = argu[0].match(/^([12]\d{3})(\d{2})(\d{2})(\d{2})?(\d{2})?(\d{2})?(\d{1,3})?/);
28
- if(matchs1&&!matchs2){
29
- argu = [1,2,3,5,6,8,10].map(function(i,index){
30
- return +(matchs1[i]||periodValue[index]);
31
- });
32
- }else if(matchs2){
33
- argu = [3,1,2,5,6,8,10].map(function(i,index){
34
- return +(matchs2[i]||periodValue[index]);
35
- });
36
- }else if(matchs3){
37
- argu = [1,2,3,4,5,6,7].map(function(i,index){
38
- return +(matchs3[i]||periodValue[index]);
39
- });
40
- }
41
- }
42
- if(argu.length>=3){
43
- argu[1]--;
44
- }
45
- this._date = new Date(...argu);
46
- if(argu.length>=2&&!isNaN(argu[0])&&argu[0]<100){
47
- this._date.setFullYear(argu[0]);
48
- }
49
- }
50
- }else{
51
- this._date = new Date();
52
- }
53
-
54
- let _ = this;
55
- taskQueue.forEach(function(task){
56
- task.bind(_)(...argu);
57
- });
58
- return this;
59
- },
60
- onInit:function(callback){
61
- taskQueue.push(callback);
62
- }
63
- };
@@ -1,54 +0,0 @@
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
- </svg>
Binary file