mat-date 1.3.43 → 1.3.77
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/README.md +1 -1
- package/dist/DateUtil.js +258 -1
- package/dist/index.js +17 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
JS DATEUTIL
|
|
1
|
+
JS USEABLE DATEUTIL HELPER LIB
|
package/dist/DateUtil.js
CHANGED
|
@@ -1 +1,258 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MDateUtil = void 0;
|
|
4
|
+
const padItem = (value, len = 2) => value.toString().padStart(len, '0');
|
|
5
|
+
class MDateUtil {
|
|
6
|
+
val = new Date();
|
|
7
|
+
static glCode = undefined;
|
|
8
|
+
code = undefined;
|
|
9
|
+
get localCode() {
|
|
10
|
+
return this.code;
|
|
11
|
+
}
|
|
12
|
+
static new() {
|
|
13
|
+
return new MDateUtil().setCode(MDateUtil.glCode);
|
|
14
|
+
}
|
|
15
|
+
static setCode(code) {
|
|
16
|
+
MDateUtil.glCode = code;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
static seperator() {
|
|
20
|
+
return new Date().toLocaleDateString(MDateUtil.glCode).replace(/\d/g, "").split('')[0];
|
|
21
|
+
}
|
|
22
|
+
copy() {
|
|
23
|
+
return MDateUtil.new().setTime(this.toTime());
|
|
24
|
+
}
|
|
25
|
+
setCode(code) {
|
|
26
|
+
this.code = code;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
seperator() {
|
|
30
|
+
return new Date().toLocaleDateString(this.code).replace(/\d/g, "").split('')[0];
|
|
31
|
+
}
|
|
32
|
+
year() {
|
|
33
|
+
return this.val.getFullYear();
|
|
34
|
+
}
|
|
35
|
+
month() {
|
|
36
|
+
return this.val.getMonth() + 1;
|
|
37
|
+
}
|
|
38
|
+
monthUtc() {
|
|
39
|
+
return this.val.getMonth();
|
|
40
|
+
}
|
|
41
|
+
day() {
|
|
42
|
+
return this.val.getDate();
|
|
43
|
+
}
|
|
44
|
+
hours() {
|
|
45
|
+
return this.val.getHours();
|
|
46
|
+
}
|
|
47
|
+
min() {
|
|
48
|
+
return this.val.getMinutes();
|
|
49
|
+
}
|
|
50
|
+
sec() {
|
|
51
|
+
return this.val.getSeconds();
|
|
52
|
+
}
|
|
53
|
+
dayOfWeek() {
|
|
54
|
+
const value = this.val.getDay();
|
|
55
|
+
return value ? value : 7;
|
|
56
|
+
}
|
|
57
|
+
dayOfWeekUtc() {
|
|
58
|
+
return this.val.getDay();
|
|
59
|
+
}
|
|
60
|
+
setYear(value) {
|
|
61
|
+
this.val.setFullYear(value);
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
setMonth(value) {
|
|
65
|
+
this.val.setMonth(value - 1);
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
setMonthUtc(value) {
|
|
69
|
+
this.val.setMonth(value);
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
setDay(value) {
|
|
73
|
+
this.val.setDate(value);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
setHour(value) {
|
|
77
|
+
this.val.setHours(value);
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
setMin(value) {
|
|
81
|
+
this.val.setMinutes(value);
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
setSeconds(value) {
|
|
85
|
+
this.val.setSeconds(value);
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
setMilliseconds(value) {
|
|
89
|
+
this.val.setMilliseconds(value);
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
setIsoDate(value) {
|
|
93
|
+
this.val = new Date(value);
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
setTime(value) {
|
|
97
|
+
this.val = new Date(value);
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
setDate(value) {
|
|
101
|
+
this.val = new Date(value);
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
setDateInputValue(value) {
|
|
105
|
+
this.val = new Date(value);
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
toIsoDate() {
|
|
109
|
+
return this.val.toISOString();
|
|
110
|
+
}
|
|
111
|
+
toTime() {
|
|
112
|
+
return this.val.getTime();
|
|
113
|
+
}
|
|
114
|
+
toDate() {
|
|
115
|
+
return this.val;
|
|
116
|
+
}
|
|
117
|
+
toDateMounthInput() {
|
|
118
|
+
return `${this.year()}-${padItem(this.month())}`;
|
|
119
|
+
}
|
|
120
|
+
toDateInput() {
|
|
121
|
+
return `${this.year()}-${padItem(this.month())}-${padItem(this.day())}`;
|
|
122
|
+
}
|
|
123
|
+
toTimeInput() {
|
|
124
|
+
return this.strTime();
|
|
125
|
+
}
|
|
126
|
+
toDateTimeInput() {
|
|
127
|
+
return `${this.toDateInput()} ${this.toTimeInput()}`;
|
|
128
|
+
}
|
|
129
|
+
strDate() {
|
|
130
|
+
return this.val.toLocaleDateString(this.code, { month: '2-digit', day: '2-digit', year: 'numeric' });
|
|
131
|
+
}
|
|
132
|
+
strDateLocal(options) {
|
|
133
|
+
return this.val.toLocaleDateString(this.code, options);
|
|
134
|
+
}
|
|
135
|
+
strTime() {
|
|
136
|
+
return `${padItem(this.hours())}:${padItem(this.min())}:${padItem(this.sec())}`;
|
|
137
|
+
}
|
|
138
|
+
strTimeLocale(options) {
|
|
139
|
+
return this.val.toLocaleTimeString(this.code, options);
|
|
140
|
+
}
|
|
141
|
+
strHHmm() {
|
|
142
|
+
return `${padItem(this.hours())}:${padItem(this.min())}`;
|
|
143
|
+
}
|
|
144
|
+
str() {
|
|
145
|
+
return `${this.strDate()} ${this.strTime()}`;
|
|
146
|
+
}
|
|
147
|
+
strLocal(options) {
|
|
148
|
+
return this.val.toLocaleString(this.code, options);
|
|
149
|
+
}
|
|
150
|
+
addDay(value) {
|
|
151
|
+
this.val = new Date(this.val.setHours(this.val.getHours() + value * 24));
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
addHours(value) {
|
|
155
|
+
this.val = new Date(this.val.setHours(this.val.getHours() + value));
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
addMins(value) {
|
|
159
|
+
this.val = new Date(this.val.setMinutes(this.val.getMinutes() + value));
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
startOfDay() {
|
|
163
|
+
this.setHour(0);
|
|
164
|
+
this.setMin(0);
|
|
165
|
+
this.setSeconds(0);
|
|
166
|
+
this.setMilliseconds(0);
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
copyByStartOfDay() {
|
|
170
|
+
return this.copy().startOfDay();
|
|
171
|
+
}
|
|
172
|
+
endOfDay() {
|
|
173
|
+
this.setHour(23);
|
|
174
|
+
this.setMin(59);
|
|
175
|
+
this.setSeconds(59);
|
|
176
|
+
this.setMilliseconds(999);
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
copyByEndOfDay() {
|
|
180
|
+
return this.copy().endOfDay();
|
|
181
|
+
}
|
|
182
|
+
startOfMonth() {
|
|
183
|
+
this.setDay(1);
|
|
184
|
+
this.startOfDay();
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
copyByStartOfMonth() {
|
|
188
|
+
return this.copy().startOfMonth();
|
|
189
|
+
}
|
|
190
|
+
endOfMonth() {
|
|
191
|
+
this.setDate(this.val).startOfMonth().setMonth(this.month() + 1).startOfMonth().addDay(-1).endOfDay();
|
|
192
|
+
return this;
|
|
193
|
+
}
|
|
194
|
+
copyByEndOfMonth() {
|
|
195
|
+
return this.copy().endOfMonth();
|
|
196
|
+
}
|
|
197
|
+
static diffDays(before, after) {
|
|
198
|
+
try {
|
|
199
|
+
const beforeVal = parse(before);
|
|
200
|
+
const afterVal = parse(after);
|
|
201
|
+
return (Math.abs(beforeVal - afterVal) / 36e5) / 24;
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
throw new Error('UNKNOWN');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
static diffHours(before, after) {
|
|
208
|
+
try {
|
|
209
|
+
const beforeVal = parse(before);
|
|
210
|
+
const afterVal = parse(after);
|
|
211
|
+
return Math.abs(beforeVal - afterVal) / 36e5;
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
throw new Error('UNKNOWN');
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
static diffMins(before, after) {
|
|
218
|
+
try {
|
|
219
|
+
const beforeVal = parse(before);
|
|
220
|
+
const afterVal = parse(after);
|
|
221
|
+
return (Math.abs(beforeVal - afterVal) / 1000) / 60;
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
throw new Error('UNKNOWN');
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
static diffSecs(before, after) {
|
|
228
|
+
try {
|
|
229
|
+
const beforeVal = parse(before);
|
|
230
|
+
const afterVal = parse(after);
|
|
231
|
+
return (Math.abs(beforeVal - afterVal) / 1000);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
throw new Error('UNKNOWN');
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
exports.MDateUtil = MDateUtil;
|
|
239
|
+
function parse(before) {
|
|
240
|
+
try {
|
|
241
|
+
if (before instanceof MDateUtil) {
|
|
242
|
+
return before.toTime();
|
|
243
|
+
}
|
|
244
|
+
if (before instanceof Date) {
|
|
245
|
+
return before.getTime();
|
|
246
|
+
}
|
|
247
|
+
if (typeof before === 'number') {
|
|
248
|
+
return before;
|
|
249
|
+
}
|
|
250
|
+
if (typeof before === 'string') {
|
|
251
|
+
return new Date(before).getTime();
|
|
252
|
+
}
|
|
253
|
+
return 0;
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
throw new Error('ERROR');
|
|
257
|
+
}
|
|
258
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./DateUtil"), exports);
|