@oipage/core.js 1.0.0-alpha.0 → 1.0.0-alpha.1
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/.github/FUNDING.yml +11 -11
- package/AUTHORS.txt +6 -6
- package/CHANGELOG +5 -4
- package/LICENSE +20 -20
- package/README.md +49 -33
- package/dist/core.js +144 -5
- package/dist/core.min.js +6 -2
- package/package.json +34 -30
- package/src/Dater/index.js +61 -0
- package/src/Dater/tool.js +25 -0
- package/src/index.js +1 -1
- package/types/Dater.ts +31 -0
- package/types/index.d.ts +3 -3
- package/src/Timer/index.js +0 -7
- package/types/Timer.d.ts +0 -8
package/.github/FUNDING.yml
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
# These are supported funding model platforms
|
|
2
|
-
|
|
3
|
-
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
|
4
|
-
patreon: # Replace with a single Patreon username
|
|
5
|
-
open_collective: # Replace with a single Open Collective username
|
|
6
|
-
ko_fi: # Replace with a single Ko-fi username
|
|
7
|
-
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
|
8
|
-
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
|
9
|
-
liberapay: # Replace with a single Liberapay username
|
|
10
|
-
issuehunt: # Replace with a single IssueHunt username
|
|
11
|
-
otechie: # Replace with a single Otechie username
|
|
1
|
+
# These are supported funding model platforms
|
|
2
|
+
|
|
3
|
+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
|
4
|
+
patreon: # Replace with a single Patreon username
|
|
5
|
+
open_collective: # Replace with a single Open Collective username
|
|
6
|
+
ko_fi: # Replace with a single Ko-fi username
|
|
7
|
+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
|
8
|
+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
|
9
|
+
liberapay: # Replace with a single Liberapay username
|
|
10
|
+
issuehunt: # Replace with a single IssueHunt username
|
|
11
|
+
otechie: # Replace with a single Otechie username
|
|
12
12
|
custom: ['https://zxl20070701.github.io/notebook/home.html']
|
package/AUTHORS.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Authors ordered by first contribution.
|
|
2
|
-
|
|
3
|
-
zxl20070701 <1904314465@qq.com> <https://github.com/zxl20070701>
|
|
4
|
-
|
|
5
|
-
-----------------------------------------------------
|
|
6
|
-
We thank all of them for their contributions!
|
|
1
|
+
Authors ordered by first contribution.
|
|
2
|
+
|
|
3
|
+
zxl20070701 <1904314465@qq.com> <https://github.com/zxl20070701>
|
|
4
|
+
|
|
5
|
+
-----------------------------------------------------
|
|
6
|
+
We thank all of them for their contributions!
|
package/CHANGELOG
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
v1.0.0:
|
|
2
|
-
date:
|
|
3
|
-
changes:
|
|
4
|
-
- 初始化版本
|
|
1
|
+
v1.0.0:
|
|
2
|
+
date:
|
|
3
|
+
changes:
|
|
4
|
+
- 初始化版本
|
|
5
|
+
1、Dater 日期
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) zxl20070701 走一步,再走一步
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) zxl20070701 走一步,再走一步
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,34 +1,50 @@
|
|
|
1
|
-
# [@oipage/core.js](https://github.com/oi-contrib/oipage-corejs)
|
|
2
|
-
包括日期、时间、浮点运算等常用的一些业务API
|
|
3
|
-
|
|
4
|
-
<p>
|
|
5
|
-
<a href="https://zxl20070701.github.io/toolbox/#/npm-download?packages=@oipage/core.js&interval=7">
|
|
6
|
-
<img src="https://img.shields.io/npm/dm/@oipage/core.js.svg" alt="downloads">
|
|
7
|
-
</a>
|
|
8
|
-
<a href="https://www.npmjs.com/package/@oipage/core.js">
|
|
9
|
-
<img src="https://img.shields.io/npm/v/@oipage/core.js.svg" alt="npm">
|
|
10
|
-
</a>
|
|
11
|
-
<a href="https://github.com/oi-contrib/oipage-corejs/issues">
|
|
12
|
-
<img src="https://img.shields.io/github/issues/oi-contrib/oipage-corejs" alt="issue">
|
|
13
|
-
</a>
|
|
14
|
-
<a href="https://github.com/oi-contrib/oipage-corejs" target='_blank'>
|
|
15
|
-
<img alt="GitHub repo stars" src="https://img.shields.io/github/stars/oi-contrib/oipage-corejs?style=social">
|
|
16
|
-
</a>
|
|
17
|
-
<a href="https://github.com/oi-contrib/oipage-corejs">
|
|
18
|
-
<img src="https://img.shields.io/github/forks/oi-contrib/oipage-corejs" alt="forks">
|
|
19
|
-
</a>
|
|
20
|
-
<a href="https://gitee.com/oi-contrib/oipage-corejs" target='_blank'>
|
|
21
|
-
<img alt="Gitee repo stars" src="https://gitee.com/oi-contrib/oipage-corejs/badge/star.svg">
|
|
22
|
-
</a>
|
|
23
|
-
<a href="https://gitee.com/oi-contrib/oipage-corejs">
|
|
24
|
-
<img src="https://gitee.com/oi-contrib/oipage-corejs/badge/fork.svg" alt="forks">
|
|
25
|
-
</a>
|
|
26
|
-
</p>
|
|
27
|
-
|
|
28
|
-
<img src="https://nodei.co/npm/@oipage/core.js.png?downloads=true&downloadRank=true&stars=true" alt="NPM">
|
|
29
|
-
|
|
30
|
-
##
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
# [@oipage/core.js](https://github.com/oi-contrib/oipage-corejs)
|
|
2
|
+
包括日期、时间、浮点运算等常用的一些业务API
|
|
3
|
+
|
|
4
|
+
<p>
|
|
5
|
+
<a href="https://zxl20070701.github.io/toolbox/#/npm-download?packages=@oipage/core.js&interval=7">
|
|
6
|
+
<img src="https://img.shields.io/npm/dm/@oipage/core.js.svg" alt="downloads">
|
|
7
|
+
</a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/@oipage/core.js">
|
|
9
|
+
<img src="https://img.shields.io/npm/v/@oipage/core.js.svg" alt="npm">
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/oi-contrib/oipage-corejs/issues">
|
|
12
|
+
<img src="https://img.shields.io/github/issues/oi-contrib/oipage-corejs" alt="issue">
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://github.com/oi-contrib/oipage-corejs" target='_blank'>
|
|
15
|
+
<img alt="GitHub repo stars" src="https://img.shields.io/github/stars/oi-contrib/oipage-corejs?style=social">
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://github.com/oi-contrib/oipage-corejs">
|
|
18
|
+
<img src="https://img.shields.io/github/forks/oi-contrib/oipage-corejs" alt="forks">
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://gitee.com/oi-contrib/oipage-corejs" target='_blank'>
|
|
21
|
+
<img alt="Gitee repo stars" src="https://gitee.com/oi-contrib/oipage-corejs/badge/star.svg">
|
|
22
|
+
</a>
|
|
23
|
+
<a href="https://gitee.com/oi-contrib/oipage-corejs">
|
|
24
|
+
<img src="https://gitee.com/oi-contrib/oipage-corejs/badge/fork.svg" alt="forks">
|
|
25
|
+
</a>
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
<img src="https://nodei.co/npm/@oipage/core.js.png?downloads=true&downloadRank=true&stars=true" alt="NPM">
|
|
29
|
+
|
|
30
|
+
## 如何使用?
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
npm install --save @oipage/core.js
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
然后直接引入需要的工具对象使用即可,比如Timer:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import { Dater } from "@oipage/core.js"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
更多具体的工具对象清单如下:
|
|
43
|
+
|
|
44
|
+
- [Dater 日期](./docs/Dater.md)
|
|
45
|
+
|
|
46
|
+
## 版权
|
|
47
|
+
|
|
48
|
+
MIT License
|
|
49
|
+
|
|
34
50
|
Copyright (c) [zxl20070701](https://zxl20070701.github.io/notebook/home.html) 走一步,再走一步
|
package/dist/core.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @oipage/corejs v1.0.0-alpha.
|
|
2
|
+
* @oipage/corejs v1.0.0-alpha.1
|
|
3
3
|
* git+https://github.com/oi-contrib/oipage-corejs.git
|
|
4
4
|
*/
|
|
5
5
|
(function (global, factory) {
|
|
@@ -8,14 +8,153 @@
|
|
|
8
8
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.corejs = {}));
|
|
9
9
|
})(this, (function (exports) { 'use strict';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
/*!
|
|
12
|
+
* format of OIPage v1.4.1
|
|
13
|
+
* git+https://github.com/oi-contrib/OIPage.git
|
|
14
|
+
*/
|
|
12
15
|
|
|
16
|
+
|
|
17
|
+
function dateFormat(input, option) {
|
|
18
|
+
option = option || option;
|
|
19
|
+
var dateObj;
|
|
20
|
+
|
|
21
|
+
// 如果无值,就用当前日期
|
|
22
|
+
if (!input) {
|
|
23
|
+
dateObj = new Date();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 日期对象
|
|
27
|
+
else if (typeof input == 'object' && input.constructor === Date) {
|
|
28
|
+
dateObj = input;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 否则就尝试创建日期对象
|
|
32
|
+
else if (!option.inputFormat) {
|
|
33
|
+
dateObj = new Date(input);
|
|
34
|
+
if (dateObj + "" == "Invalid Date") {
|
|
35
|
+
console.error("非法的日期格式:" + input, dateObj);
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 年、月、日、时、分、秒
|
|
41
|
+
var single = {
|
|
42
|
+
yyyy: 0, MM: 0, dd: 0, HH: 0, mm: 0, ss: 0
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// 如果获取了日期实例
|
|
46
|
+
if (dateObj) {
|
|
47
|
+
|
|
48
|
+
single.yyyy = dateObj.getFullYear();
|
|
49
|
+
single.MM = dateObj.getMonth() + 1;
|
|
50
|
+
single.dd = dateObj.getDate();
|
|
51
|
+
|
|
52
|
+
single.HH = dateObj.getHours();
|
|
53
|
+
single.mm = dateObj.getMinutes();
|
|
54
|
+
single.ss = dateObj.getSeconds();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 否则只能借助 inputFormat 来解析
|
|
58
|
+
else {
|
|
59
|
+
var inputFormat = option.inputFormat + "", valIndex = 0;
|
|
60
|
+
for (var index = 0; index < inputFormat.length; index++) {
|
|
61
|
+
|
|
62
|
+
// 年
|
|
63
|
+
if (inputFormat.substring(index, index + 4) == "yyyy") {
|
|
64
|
+
single.yyyy = +input.substring(valIndex, valIndex + 4);
|
|
65
|
+
|
|
66
|
+
valIndex += 4;
|
|
67
|
+
index += 3;
|
|
68
|
+
} else {
|
|
69
|
+
var curFlag = inputFormat.substring(index, index + 2);
|
|
70
|
+
if (["MM", "dd", "HH", "mm", "ss"].indexOf(curFlag) > -1) {
|
|
71
|
+
var valContent = input[valIndex];
|
|
72
|
+
if (/\d/.test(input[valIndex + 1])) {
|
|
73
|
+
valContent += input[valIndex + 1];
|
|
74
|
+
valIndex += 2;
|
|
75
|
+
} else {
|
|
76
|
+
valIndex += 1;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
(single)[curFlag] = +valContent;
|
|
80
|
+
index += 1;
|
|
81
|
+
} else {
|
|
82
|
+
valIndex += 1;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (single.MM < 10) single.MM = "0" + single.MM;
|
|
89
|
+
if (single.dd < 10) single.dd = "0" + single.dd;
|
|
90
|
+
if (single.HH < 10) single.HH = "0" + single.HH;
|
|
91
|
+
if (single.mm < 10) single.mm = "0" + single.mm;
|
|
92
|
+
if (single.ss < 10) single.ss = "0" + single.ss;
|
|
93
|
+
|
|
94
|
+
var format = option.format || "yyyy/MM/dd";
|
|
95
|
+
return format.replace("yyyy", single.yyyy).replace("MM", single.MM).replace("dd", single.dd).replace("HH", single.HH).replace("mm", single.mm).replace("ss", single.ss);
|
|
13
96
|
}
|
|
14
97
|
|
|
15
|
-
|
|
16
|
-
|
|
98
|
+
function Dater(date, format = {}) {
|
|
99
|
+
this.inputFormat = format.input || "yyyy/MM/dd";
|
|
100
|
+
this.outputFormat = format.output || "yyyy/MM/dd";
|
|
101
|
+
|
|
102
|
+
// 字符串
|
|
103
|
+
if (date && typeof date === "string") {
|
|
104
|
+
let temp = dateFormat(date, {
|
|
105
|
+
inputFormat: this.inputFormat
|
|
106
|
+
}).split("/");
|
|
107
|
+
|
|
108
|
+
this.year = +temp[0];
|
|
109
|
+
this.month = +temp[1];
|
|
110
|
+
this.day = +temp[2];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
else {
|
|
114
|
+
// 不是Date对象
|
|
115
|
+
if (!(date && typeof date === "object" && date.constructor === Date)) date = new Date();
|
|
116
|
+
|
|
117
|
+
this.year = date.getFullYear();
|
|
118
|
+
this.month = date.getMonth() + 1;
|
|
119
|
+
this.day = date.getDate();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
Dater.prototype.valueOf = function () {
|
|
124
|
+
return dateFormat(`${this.year}/${this.month}/${this.day}`, {
|
|
125
|
+
format: this.outputFormat
|
|
126
|
+
})
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
Dater.prototype.addYear = function (year) {
|
|
130
|
+
this.year += year;
|
|
131
|
+
return this
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
Dater.prototype.addMonth = function (month) {
|
|
135
|
+
let month1 = month % 12; // 零碎的月份
|
|
136
|
+
this.year += (month - month1) / 12; // 整齐的年份
|
|
137
|
+
|
|
138
|
+
if (month1 > 0) {
|
|
139
|
+
let month2 = 12 - this.month; // 新增月份剩余空间
|
|
140
|
+
if (month2 >= month1) {
|
|
141
|
+
this.month += month1;
|
|
142
|
+
} else {
|
|
143
|
+
this.year += 1;
|
|
144
|
+
this.month = month1 - month2;
|
|
145
|
+
}
|
|
146
|
+
} else if (month1 < 0) {
|
|
147
|
+
if (this.month + month1 > 0) {
|
|
148
|
+
this.month += month1;
|
|
149
|
+
} else {
|
|
150
|
+
this.year -= 1;
|
|
151
|
+
this.month += 12 + month1;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return this
|
|
17
156
|
};
|
|
18
157
|
|
|
19
|
-
exports.
|
|
158
|
+
exports.Dater = Dater;
|
|
20
159
|
|
|
21
160
|
}));
|
package/dist/core.min.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @oipage/corejs v1.0.0-alpha.
|
|
2
|
+
* @oipage/corejs v1.0.0-alpha.1
|
|
3
3
|
* git+https://github.com/oi-contrib/oipage-corejs.git
|
|
4
4
|
*/
|
|
5
|
-
!function(e
|
|
5
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).corejs={})}(this,function(t){"use strict";
|
|
6
|
+
/*!
|
|
7
|
+
* format of OIPage v1.4.1
|
|
8
|
+
* git+https://github.com/oi-contrib/OIPage.git
|
|
9
|
+
*/function e(t,e){var s;if(e=e||e,t){if("object"==typeof t&&t.constructor===Date)s=t;else if(!e.inputFormat&&(s=new Date(t))+""=="Invalid Date")return console.error("非法的日期格式:"+t,s),""}else s=new Date;var o={yyyy:0,MM:0,dd:0,HH:0,mm:0,ss:0};if(s)o.yyyy=s.getFullYear(),o.MM=s.getMonth()+1,o.dd=s.getDate(),o.HH=s.getHours(),o.mm=s.getMinutes(),o.ss=s.getSeconds();else for(var i=e.inputFormat+"",r=0,n=0;n<i.length;n++)if("yyyy"==i.substring(n,n+4))o.yyyy=+t.substring(r,r+4),r+=4,n+=3;else{var y=i.substring(n,n+2);if(["MM","dd","HH","mm","ss"].indexOf(y)>-1){var a=t[r];/\d/.test(t[r+1])?(a+=t[r+1],r+=2):r+=1,o[y]=+a,n+=1}else r+=1}return o.MM<10&&(o.MM="0"+o.MM),o.dd<10&&(o.dd="0"+o.dd),o.HH<10&&(o.HH="0"+o.HH),o.mm<10&&(o.mm="0"+o.mm),o.ss<10&&(o.ss="0"+o.ss),(e.format||"yyyy/MM/dd").replace("yyyy",o.yyyy).replace("MM",o.MM).replace("dd",o.dd).replace("HH",o.HH).replace("mm",o.mm).replace("ss",o.ss)}function s(t,s={}){if(this.inputFormat=s.input||"yyyy/MM/dd",this.outputFormat=s.output||"yyyy/MM/dd",t&&"string"==typeof t){let s=e(t,{inputFormat:this.inputFormat}).split("/");this.year=+s[0],this.month=+s[1],this.day=+s[2]}else t&&"object"==typeof t&&t.constructor===Date||(t=new Date),this.year=t.getFullYear(),this.month=t.getMonth()+1,this.day=t.getDate()}s.prototype.valueOf=function(){return e(`${this.year}/${this.month}/${this.day}`,{format:this.outputFormat})},s.prototype.addYear=function(t){return this.year+=t,this},s.prototype.addMonth=function(t){let e=t%12;if(this.year+=(t-e)/12,e>0){let t=12-this.month;t>=e?this.month+=e:(this.year+=1,this.month=e-t)}else e<0&&(this.month+e>0?this.month+=e:(this.year-=1,this.month+=12+e));return this},t.Dater=s});
|
package/package.json
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@oipage/core.js",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
4
|
-
"description": "包括日期、时间、浮点运算等常用的一些业务API",
|
|
5
|
-
"main": "./dist/core.js",
|
|
6
|
-
"typings": "./types/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"start": "npm install && npm run dev",
|
|
9
|
-
"dev": "oipage-cli run \"rollup --config ./rollup.config.js -w\" \"oipage-cli serve -p 20000\"",
|
|
10
|
-
"build": "rollup --config ./rollup.config.js && terser ./dist/core.js --compress --mangle --output ./dist/core.min.js"
|
|
11
|
-
},
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/oi-contrib/oipage-corejs.git"
|
|
15
|
-
},
|
|
16
|
-
"author": {
|
|
17
|
-
"name": "zxl20070701",
|
|
18
|
-
"url": "https://zxl20070701.github.io/notebook/home.html"
|
|
19
|
-
},
|
|
20
|
-
"keywords": [
|
|
21
|
-
"oipage",
|
|
22
|
-
"core",
|
|
23
|
-
"javascript"
|
|
24
|
-
],
|
|
25
|
-
"license": "MIT",
|
|
26
|
-
"devDependencies": {
|
|
27
|
-
"rollup": "^
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@oipage/core.js",
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
4
|
+
"description": "包括日期、时间、浮点运算等常用的一些业务API",
|
|
5
|
+
"main": "./dist/core.js",
|
|
6
|
+
"typings": "./types/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"start": "npm install && npm run dev",
|
|
9
|
+
"dev": "oipage-cli run \"rollup --config ./rollup.config.js -w\" \"oipage-cli serve -p 20000\"",
|
|
10
|
+
"build": "rollup --config ./rollup.config.js && terser ./dist/core.js --compress --mangle --output ./dist/core.min.js"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/oi-contrib/oipage-corejs.git"
|
|
15
|
+
},
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "zxl20070701",
|
|
18
|
+
"url": "https://zxl20070701.github.io/notebook/home.html"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"oipage",
|
|
22
|
+
"core",
|
|
23
|
+
"javascript"
|
|
24
|
+
],
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
28
|
+
"rollup": "^4.6.1",
|
|
29
|
+
"terser": "^5.17.1"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"oipage": "^1.4.1"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { dateFormat } from "oipage/web/format"
|
|
2
|
+
|
|
3
|
+
export function Dater(date, format = {}) {
|
|
4
|
+
this.inputFormat = format.input || "yyyy/MM/dd"
|
|
5
|
+
this.outputFormat = format.output || "yyyy/MM/dd"
|
|
6
|
+
|
|
7
|
+
// 字符串
|
|
8
|
+
if (date && typeof date === "string") {
|
|
9
|
+
let temp = dateFormat(date, {
|
|
10
|
+
inputFormat: this.inputFormat
|
|
11
|
+
}).split("/")
|
|
12
|
+
|
|
13
|
+
this.year = +temp[0]
|
|
14
|
+
this.month = +temp[1]
|
|
15
|
+
this.day = +temp[2]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
else {
|
|
19
|
+
// 不是Date对象
|
|
20
|
+
if (!(date && typeof date === "object" && date.constructor === Date)) date = new Date()
|
|
21
|
+
|
|
22
|
+
this.year = date.getFullYear()
|
|
23
|
+
this.month = date.getMonth() + 1
|
|
24
|
+
this.day = date.getDate()
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
Dater.prototype.valueOf = function () {
|
|
29
|
+
return dateFormat(`${this.year}/${this.month}/${this.day}`, {
|
|
30
|
+
format: this.outputFormat
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
Dater.prototype.addYear = function (year) {
|
|
35
|
+
this.year += year
|
|
36
|
+
return this
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
Dater.prototype.addMonth = function (month) {
|
|
40
|
+
let month1 = month % 12 // 零碎的月份
|
|
41
|
+
this.year += (month - month1) / 12 // 整齐的年份
|
|
42
|
+
|
|
43
|
+
if (month1 > 0) {
|
|
44
|
+
let month2 = 12 - this.month // 新增月份剩余空间
|
|
45
|
+
if (month2 >= month1) {
|
|
46
|
+
this.month += month1
|
|
47
|
+
} else {
|
|
48
|
+
this.year += 1
|
|
49
|
+
this.month = month1 - month2
|
|
50
|
+
}
|
|
51
|
+
} else if (month1 < 0) {
|
|
52
|
+
if (this.month + month1 > 0) {
|
|
53
|
+
this.month += month1
|
|
54
|
+
} else {
|
|
55
|
+
this.year -= 1
|
|
56
|
+
this.month += 12 + month1
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return this
|
|
61
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// 计算某年多少天
|
|
2
|
+
export let calcYearDays = function () {
|
|
3
|
+
if ((year % 4 != 0) || (year % 100 == 0 && year % 400 != 0)) {
|
|
4
|
+
return 365
|
|
5
|
+
} else {
|
|
6
|
+
return 366
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// 计算某月多少天
|
|
11
|
+
export let calcMonthDays = function (year, month) {
|
|
12
|
+
|
|
13
|
+
if (month == 2) {
|
|
14
|
+
|
|
15
|
+
if ((year % 4 != 0) || (year % 100 == 0 && year % 400 != 0)) {
|
|
16
|
+
return 28
|
|
17
|
+
} else {
|
|
18
|
+
return 29
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
} else {
|
|
22
|
+
return [31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./Dater/index.js"
|
package/types/Dater.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export default interface DaterType {
|
|
2
|
+
new(date?: string | Date, format?: {
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 输入格式
|
|
6
|
+
*/
|
|
7
|
+
input?: "string"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 输出格式
|
|
11
|
+
*/
|
|
12
|
+
outout?: "string"
|
|
13
|
+
}): this
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 按照format.outout格式返回当前维护的日期
|
|
17
|
+
*/
|
|
18
|
+
valueOf(): string
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 新增year年后的日期(如果year为负数,就是减少)
|
|
22
|
+
* @param year
|
|
23
|
+
*/
|
|
24
|
+
addYear(year: number): this
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 新增month月后的日期(如果month为负数,就是减少)
|
|
28
|
+
* @param month
|
|
29
|
+
*/
|
|
30
|
+
addMonth(month: number): this
|
|
31
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export let
|
|
1
|
+
import DaterType from "./Dater"
|
|
2
|
+
|
|
3
|
+
export let Dater: DaterType
|
package/src/Timer/index.js
DELETED