@etsoo/shared 1.2.51 → 1.2.54
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/workflows/main.yml +6 -5
- package/README.md +1 -1
- package/lib/cjs/ActionResult.d.ts +1 -1
- package/lib/cjs/ActionResult.js +3 -3
- package/lib/cjs/ArrayUtils.d.ts +1 -1
- package/lib/cjs/ArrayUtils.js +4 -4
- package/lib/cjs/ColorUtils.d.ts +1 -1
- package/lib/cjs/ColorUtils.js +2 -2
- package/lib/cjs/DataTypes.d.ts +6 -6
- package/lib/cjs/DataTypes.js +50 -51
- package/lib/cjs/DateUtils.d.ts +1 -1
- package/lib/cjs/DateUtils.js +27 -28
- package/lib/cjs/DomUtils.d.ts +3 -3
- package/lib/cjs/DomUtils.js +64 -73
- package/lib/cjs/ExtendUtils.d.ts +1 -1
- package/lib/cjs/ExtendUtils.js +6 -6
- package/lib/cjs/IActionResult.d.ts +15 -2
- package/lib/cjs/NumberUtils.d.ts +1 -1
- package/lib/cjs/NumberUtils.js +9 -9
- package/lib/cjs/StorageUtils.js +2 -2
- package/lib/cjs/Utils.d.ts +4 -4
- package/lib/cjs/Utils.js +58 -62
- package/lib/cjs/index.d.ts +22 -22
- package/lib/cjs/storage/WindowStorage.d.ts +1 -1
- package/lib/cjs/types/ContentDisposition.d.ts +2 -2
- package/lib/cjs/types/ContentDisposition.js +11 -13
- package/lib/cjs/types/EColor.js +5 -7
- package/lib/cjs/types/EHistory.d.ts +3 -3
- package/lib/cjs/types/EHistory.js +4 -4
- package/lib/cjs/types/ErrorData.d.ts +1 -1
- package/lib/cjs/types/EventClass.js +1 -1
- package/lib/mjs/ActionResult.d.ts +1 -1
- package/lib/mjs/ActionResult.js +3 -3
- package/lib/mjs/ArrayUtils.d.ts +1 -1
- package/lib/mjs/ArrayUtils.js +5 -5
- package/lib/mjs/ColorUtils.d.ts +1 -1
- package/lib/mjs/ColorUtils.js +3 -3
- package/lib/mjs/DataTypes.d.ts +6 -6
- package/lib/mjs/DataTypes.js +50 -51
- package/lib/mjs/DateUtils.d.ts +1 -1
- package/lib/mjs/DateUtils.js +27 -28
- package/lib/mjs/DomUtils.d.ts +3 -3
- package/lib/mjs/DomUtils.js +67 -76
- package/lib/mjs/ExtendUtils.d.ts +1 -1
- package/lib/mjs/ExtendUtils.js +6 -6
- package/lib/mjs/IActionResult.d.ts +15 -2
- package/lib/mjs/NumberUtils.d.ts +1 -1
- package/lib/mjs/NumberUtils.js +9 -9
- package/lib/mjs/StorageUtils.js +4 -4
- package/lib/mjs/Utils.d.ts +4 -4
- package/lib/mjs/Utils.js +61 -65
- package/lib/mjs/index.d.ts +22 -22
- package/lib/mjs/index.js +22 -22
- package/lib/mjs/storage/WindowStorage.d.ts +1 -1
- package/lib/mjs/storage/WindowStorage.js +2 -2
- package/lib/mjs/types/ContentDisposition.d.ts +2 -2
- package/lib/mjs/types/ContentDisposition.js +12 -14
- package/lib/mjs/types/EColor.js +5 -7
- package/lib/mjs/types/EHistory.d.ts +3 -3
- package/lib/mjs/types/EHistory.js +5 -5
- package/lib/mjs/types/ErrorData.d.ts +1 -1
- package/lib/mjs/types/EventClass.js +1 -1
- package/package.json +61 -63
- package/src/ActionResult.ts +23 -23
- package/src/ArrayUtils.ts +164 -172
- package/src/ColorUtils.ts +80 -82
- package/src/DataTypes.ts +745 -754
- package/src/DateUtils.ts +266 -268
- package/src/DomUtils.ts +806 -831
- package/src/ExtendUtils.ts +191 -191
- package/src/IActionResult.ts +55 -40
- package/src/Keyboard.ts +258 -258
- package/src/NumberUtils.ts +135 -135
- package/src/StorageUtils.ts +117 -117
- package/src/Utils.ts +908 -930
- package/src/index.ts +22 -22
- package/src/node/Storage.ts +53 -53
- package/src/storage/IStorage.ts +62 -62
- package/src/storage/WindowStorage.ts +140 -140
- package/src/types/ContentDisposition.ts +59 -63
- package/src/types/DataError.ts +15 -15
- package/src/types/DelayedExecutorType.ts +15 -15
- package/src/types/EColor.ts +241 -248
- package/src/types/EHistory.ts +151 -151
- package/src/types/ErrorData.ts +11 -11
- package/src/types/EventClass.ts +220 -220
- package/src/types/FormData.ts +25 -25
- package/src/types/ParsedPath.ts +5 -5
- package/tsconfig.cjs.json +16 -16
- package/tsconfig.json +16 -16
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -29
- package/.prettierignore +0 -5
- package/.prettierrc +0 -6
package/src/DateUtils.ts
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
1
|
declare global {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
interface Date {
|
|
3
|
+
/**
|
|
4
|
+
* Substract date
|
|
5
|
+
* @param input Input date
|
|
6
|
+
*/
|
|
7
|
+
substract(input: Date): TimeSpan;
|
|
8
|
+
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
Date.prototype.substract = function (this: Date, input: Date): TimeSpan {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
12
|
+
// Calculate from miniseconds
|
|
13
|
+
const totalMiniseconds = this.valueOf() - input.valueOf();
|
|
14
|
+
const totalSeconds = totalMiniseconds / 1000.0;
|
|
15
|
+
const totalMinutes = totalSeconds / 60.0;
|
|
16
|
+
const totalHours = totalMinutes / 60.0;
|
|
17
|
+
const totalDays = totalHours / 24.0;
|
|
18
|
+
|
|
19
|
+
// Calcuate days
|
|
20
|
+
const thisYear = this.getFullYear();
|
|
21
|
+
const thisMonth = this.getMonth();
|
|
22
|
+
const inputCopy = new Date(input);
|
|
23
|
+
inputCopy.setFullYear(thisYear);
|
|
24
|
+
inputCopy.setMonth(thisMonth);
|
|
25
|
+
|
|
26
|
+
const diffDays =
|
|
27
|
+
(new Date(this).valueOf() - inputCopy.valueOf()) / 86400000.0;
|
|
28
|
+
const diffMonths =
|
|
29
|
+
diffDays > 0
|
|
30
|
+
? diffDays / DateUtils.getDays(thisYear, thisMonth)
|
|
31
|
+
: diffDays / DateUtils.getDays(thisYear, thisMonth - 1);
|
|
32
|
+
|
|
33
|
+
// Total months
|
|
34
|
+
const totalMonths =
|
|
35
|
+
12 * (thisYear - input.getFullYear()) +
|
|
36
|
+
(thisMonth - input.getMonth()) +
|
|
37
|
+
diffMonths;
|
|
38
|
+
|
|
39
|
+
// Total years
|
|
40
|
+
const totalYears = totalMonths / 12.0;
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
totalMiniseconds,
|
|
44
|
+
totalSeconds,
|
|
45
|
+
totalMinutes,
|
|
46
|
+
totalHours,
|
|
47
|
+
totalDays,
|
|
48
|
+
totalMonths,
|
|
49
|
+
totalYears
|
|
50
|
+
};
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* TimeSpan
|
|
55
55
|
*/
|
|
56
56
|
export interface TimeSpan {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
totalMiniseconds: number;
|
|
58
|
+
totalSeconds: number;
|
|
59
|
+
totalMinutes: number;
|
|
60
|
+
totalHours: number;
|
|
61
|
+
totalDays: number;
|
|
62
|
+
totalMonths: number;
|
|
63
|
+
totalYears: number;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
type DateType = Date | string | null | undefined;
|
|
@@ -68,223 +68,221 @@ type DateType = Date | string | null | undefined;
|
|
|
68
68
|
type DateReturn<T extends DateType, R> = T extends Date ? R : R | undefined;
|
|
69
69
|
|
|
70
70
|
export namespace DateUtils {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Clone as new options with time zone
|
|
143
|
-
const newOpt = { ...opt, ...(timeZone != null && { timeZone }) };
|
|
144
|
-
|
|
145
|
-
// Return format result
|
|
146
|
-
return new Intl.DateTimeFormat(locale, newOpt)
|
|
147
|
-
.format(parsed)
|
|
148
|
-
.replace(/,\s*/g, ' ');
|
|
71
|
+
/**
|
|
72
|
+
* Day format, YYYY-MM-DD
|
|
73
|
+
*/
|
|
74
|
+
export const DayFormat: Intl.DateTimeFormatOptions = {
|
|
75
|
+
year: "numeric",
|
|
76
|
+
month: "2-digit",
|
|
77
|
+
day: "2-digit"
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Minute format, YYYY-MM-DD hh:mm
|
|
82
|
+
*/
|
|
83
|
+
export const MinuteFormat: Intl.DateTimeFormatOptions = {
|
|
84
|
+
...DayFormat,
|
|
85
|
+
hour: "2-digit",
|
|
86
|
+
hourCycle: "h23",
|
|
87
|
+
minute: "2-digit"
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Second format, YYYY-MM-DD hh:mm:ss
|
|
92
|
+
*/
|
|
93
|
+
export const SecondFormat: Intl.DateTimeFormatOptions = {
|
|
94
|
+
...MinuteFormat,
|
|
95
|
+
second: "2-digit"
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Date format options
|
|
100
|
+
*/
|
|
101
|
+
export type FormatOptions = Intl.DateTimeFormatOptions | "d" | "dm" | "ds";
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Format
|
|
105
|
+
* @param input Input date time
|
|
106
|
+
* @param locale Locale
|
|
107
|
+
* @param options Options
|
|
108
|
+
* @param timeZone Time zone
|
|
109
|
+
*/
|
|
110
|
+
export function format<T extends DateType>(
|
|
111
|
+
input: T,
|
|
112
|
+
locale?: string | string[],
|
|
113
|
+
options?: FormatOptions,
|
|
114
|
+
timeZone?: string
|
|
115
|
+
): DateReturn<T, string> {
|
|
116
|
+
// Parse
|
|
117
|
+
const parsed = parse(input);
|
|
118
|
+
|
|
119
|
+
// Null case
|
|
120
|
+
if (parsed == null) return <DateReturn<T, string>>undefined;
|
|
121
|
+
|
|
122
|
+
// Default options
|
|
123
|
+
options ??= DayFormat;
|
|
124
|
+
|
|
125
|
+
// Default options
|
|
126
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat
|
|
127
|
+
let opt: Intl.DateTimeFormatOptions;
|
|
128
|
+
switch (options) {
|
|
129
|
+
case "d":
|
|
130
|
+
opt = DayFormat;
|
|
131
|
+
break;
|
|
132
|
+
case "dm":
|
|
133
|
+
opt = MinuteFormat;
|
|
134
|
+
break;
|
|
135
|
+
case "ds":
|
|
136
|
+
opt = SecondFormat;
|
|
137
|
+
break;
|
|
138
|
+
default:
|
|
139
|
+
opt = options;
|
|
149
140
|
}
|
|
150
141
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
142
|
+
// Clone as new options with time zone
|
|
143
|
+
const newOpt = { ...opt, ...(timeZone != null && { timeZone }) };
|
|
144
|
+
|
|
145
|
+
// Return format result
|
|
146
|
+
return new Intl.DateTimeFormat(locale, newOpt)
|
|
147
|
+
.format(parsed)
|
|
148
|
+
.replace(/,\s*/g, " ");
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Format to 'yyyy-MM-dd' or 'yyyy-MM-ddThh:mm:ss, especially used for date input min/max property
|
|
153
|
+
* @param date Input date
|
|
154
|
+
* @param hasSecondOrType 'undefined' for date only, 'false' for hour:minute only, 'true' for all, or input field type
|
|
155
|
+
*/
|
|
156
|
+
export function formatForInput<T extends DateType>(
|
|
157
|
+
date: T,
|
|
158
|
+
hasSecondOrType?: boolean | string
|
|
159
|
+
): DateReturn<T, string> {
|
|
160
|
+
// Return when null
|
|
161
|
+
if (date == null || date === "") return <DateReturn<T, string>>undefined;
|
|
162
|
+
|
|
163
|
+
// Parse string as date
|
|
164
|
+
const dt: Date = typeof date === "string" ? new Date(date) : date;
|
|
165
|
+
|
|
166
|
+
const hasSecond =
|
|
167
|
+
typeof hasSecondOrType === "string"
|
|
168
|
+
? hasSecondOrType === "date"
|
|
169
|
+
? undefined
|
|
170
|
+
: true
|
|
171
|
+
: hasSecondOrType;
|
|
172
|
+
|
|
173
|
+
// Parts
|
|
174
|
+
const parts = [
|
|
175
|
+
dt.getFullYear(),
|
|
176
|
+
(dt.getMonth() + 1).toString().padStart(2, "0"),
|
|
177
|
+
dt.getDate().toString().padStart(2, "0")
|
|
178
|
+
];
|
|
179
|
+
|
|
180
|
+
// Date
|
|
181
|
+
const d = parts.join("-");
|
|
182
|
+
if (hasSecond == null) return d;
|
|
183
|
+
|
|
184
|
+
const hm = [
|
|
185
|
+
dt.getHours().toString().padStart(2, "0"),
|
|
186
|
+
dt.getMinutes().toString().padStart(2, "0")
|
|
187
|
+
];
|
|
188
|
+
if (hasSecond) hm.push(dt.getSeconds().toString().padStart(2, "0"));
|
|
189
|
+
return `${d}T${hm.join(":")}`;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Get month's days
|
|
194
|
+
* @param year Year
|
|
195
|
+
* @param month Month, starts from 0
|
|
196
|
+
* @returns Days
|
|
197
|
+
*/
|
|
198
|
+
export const getDays = (year: number, month: number) =>
|
|
199
|
+
new Date(year, month + 1, 0).getDate();
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Is the test date expired to now
|
|
203
|
+
* @param testDate Test date
|
|
204
|
+
* @returns Result
|
|
205
|
+
*/
|
|
206
|
+
export function isExpired(testDate?: Date | string | null) {
|
|
207
|
+
if (testDate == null) return false;
|
|
208
|
+
const d = parse(testDate);
|
|
209
|
+
|
|
210
|
+
// Format error
|
|
211
|
+
if (d == null) return false;
|
|
212
|
+
|
|
213
|
+
return d.valueOf() < new Date().valueOf();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Build JSON parser
|
|
218
|
+
* @param keys Date field names
|
|
219
|
+
* @returns JSON parser
|
|
220
|
+
*/
|
|
221
|
+
export const jsonParser = (keys: string[]) => {
|
|
222
|
+
return function (key: string, value: unknown) {
|
|
223
|
+
if (
|
|
224
|
+
typeof value === "string" &&
|
|
225
|
+
value != null &&
|
|
226
|
+
value !== "" &&
|
|
227
|
+
keys.includes(key)
|
|
228
|
+
) {
|
|
229
|
+
const parsedDate = parse(value);
|
|
230
|
+
if (parsedDate != null) return parsedDate;
|
|
231
|
+
}
|
|
232
|
+
return value;
|
|
235
233
|
};
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
return <Date>input;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Two dates are in the same day
|
|
258
|
-
* @param d1 First date
|
|
259
|
-
* @param d2 Second date
|
|
260
|
-
* @returns Result
|
|
261
|
-
*/
|
|
262
|
-
export function sameDay(
|
|
263
|
-
d1?: Date | string | null,
|
|
264
|
-
d2?: Date | string | null
|
|
265
|
-
) {
|
|
266
|
-
d1 = parse(d1);
|
|
267
|
-
d2 = parse(d2);
|
|
268
|
-
if (d1 == null || d2 == null) return false;
|
|
269
|
-
return d1.toDateString() === d2.toDateString();
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Two dates are in the same month
|
|
274
|
-
* @param d1 First date
|
|
275
|
-
* @param d2 Second date
|
|
276
|
-
* @returns Result
|
|
277
|
-
*/
|
|
278
|
-
export function sameMonth(
|
|
279
|
-
d1?: Date | string | null,
|
|
280
|
-
d2?: Date | string | null
|
|
281
|
-
) {
|
|
282
|
-
d1 = parse(d1);
|
|
283
|
-
d2 = parse(d2);
|
|
284
|
-
if (d1 == null || d2 == null) return false;
|
|
285
|
-
return (
|
|
286
|
-
d1.getFullYear() === d2.getFullYear() &&
|
|
287
|
-
d1.getMonth() === d2.getMonth()
|
|
288
|
-
);
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Parse string to date
|
|
238
|
+
* 2021/10/31 or 2021-10-31
|
|
239
|
+
* @param input Input string
|
|
240
|
+
* @returns Date
|
|
241
|
+
*/
|
|
242
|
+
export function parse<T extends DateType>(input: T): DateReturn<T, Date> {
|
|
243
|
+
if (input == null) return <DateReturn<T, Date>>undefined;
|
|
244
|
+
if (typeof input === "string") {
|
|
245
|
+
const f = input[0];
|
|
246
|
+
if (f >= "0" && f <= "9" && /[-\/\s]/g.test(input)) {
|
|
247
|
+
const n = Date.parse(input);
|
|
248
|
+
if (!isNaN(n)) return new Date(n);
|
|
249
|
+
}
|
|
250
|
+
return <DateReturn<T, Date>>undefined;
|
|
289
251
|
}
|
|
252
|
+
return <Date>input;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Two dates are in the same day
|
|
257
|
+
* @param d1 First date
|
|
258
|
+
* @param d2 Second date
|
|
259
|
+
* @returns Result
|
|
260
|
+
*/
|
|
261
|
+
export function sameDay(
|
|
262
|
+
d1?: Date | string | null,
|
|
263
|
+
d2?: Date | string | null
|
|
264
|
+
) {
|
|
265
|
+
d1 = parse(d1);
|
|
266
|
+
d2 = parse(d2);
|
|
267
|
+
if (d1 == null || d2 == null) return false;
|
|
268
|
+
return d1.toDateString() === d2.toDateString();
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Two dates are in the same month
|
|
273
|
+
* @param d1 First date
|
|
274
|
+
* @param d2 Second date
|
|
275
|
+
* @returns Result
|
|
276
|
+
*/
|
|
277
|
+
export function sameMonth(
|
|
278
|
+
d1?: Date | string | null,
|
|
279
|
+
d2?: Date | string | null
|
|
280
|
+
) {
|
|
281
|
+
d1 = parse(d1);
|
|
282
|
+
d2 = parse(d2);
|
|
283
|
+
if (d1 == null || d2 == null) return false;
|
|
284
|
+
return (
|
|
285
|
+
d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth()
|
|
286
|
+
);
|
|
287
|
+
}
|
|
290
288
|
}
|