@fctc/widget-logic 5.3.7-beta.15 → 5.3.7-beta.17
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/hooks.js +3 -299
- package/dist/hooks.mjs +3 -292
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +88 -370
- package/dist/index.mjs +91 -366
- package/dist/types.d.mts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils.d.mts +1 -3
- package/dist/utils.d.ts +1 -3
- package/dist/utils.js +1 -297
- package/dist/utils.mjs +1 -286
- package/dist/widget.d.mts +26 -22
- package/dist/widget.d.ts +26 -22
- package/dist/widget.js +170 -446
- package/dist/widget.mjs +160 -428
- package/package.json +1 -1
package/dist/types.d.mts
CHANGED
package/dist/types.d.ts
CHANGED
package/dist/utils.d.mts
CHANGED
|
@@ -18,6 +18,4 @@ declare function setStorageItemAsync(key: StorageKey, value: string | null): Pro
|
|
|
18
18
|
declare function useStorageState(key: StorageKey): UseStateHook<string>;
|
|
19
19
|
declare const guessTypeFromUrl: (url: string) => any;
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export { STORAGES, countSum, guessTypeFromUrl, isObjectEmpty, languages, mergeButtons, setStorageItemAsync, useStorageState, validateAndParseDate };
|
|
21
|
+
export { STORAGES, countSum, guessTypeFromUrl, isObjectEmpty, languages, mergeButtons, setStorageItemAsync, useStorageState };
|
package/dist/utils.d.ts
CHANGED
|
@@ -18,6 +18,4 @@ declare function setStorageItemAsync(key: StorageKey, value: string | null): Pro
|
|
|
18
18
|
declare function useStorageState(key: StorageKey): UseStateHook<string>;
|
|
19
19
|
declare const guessTypeFromUrl: (url: string) => any;
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export { STORAGES, countSum, guessTypeFromUrl, isObjectEmpty, languages, mergeButtons, setStorageItemAsync, useStorageState, validateAndParseDate };
|
|
21
|
+
export { STORAGES, countSum, guessTypeFromUrl, isObjectEmpty, languages, mergeButtons, setStorageItemAsync, useStorageState };
|
package/dist/utils.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -18,14 +16,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
18
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
20
|
|
|
31
21
|
// src/utils.ts
|
|
@@ -38,8 +28,7 @@ __export(utils_exports, {
|
|
|
38
28
|
languages: () => languages,
|
|
39
29
|
mergeButtons: () => mergeButtons,
|
|
40
30
|
setStorageItemAsync: () => setStorageItemAsync,
|
|
41
|
-
useStorageState: () => useStorageState
|
|
42
|
-
validateAndParseDate: () => validateAndParseDate
|
|
31
|
+
useStorageState: () => useStorageState
|
|
43
32
|
});
|
|
44
33
|
module.exports = __toCommonJS(utils_exports);
|
|
45
34
|
|
|
@@ -135,290 +124,6 @@ var guessTypeFromUrl = (url) => {
|
|
|
135
124
|
return map[ext] || null;
|
|
136
125
|
};
|
|
137
126
|
|
|
138
|
-
// src/utils/format-date.ts
|
|
139
|
-
var import_moment = __toESM(require("moment"));
|
|
140
|
-
var validateAndParseDate = (input, isDateTime = false) => {
|
|
141
|
-
if (!input || typeof input !== "string") return null;
|
|
142
|
-
const cleanInput = input.replace(/[^0-9-\/:\s]/g, "");
|
|
143
|
-
const dateFormat = "YYYY-MM-DD";
|
|
144
|
-
const dateTimeFormat = "YYYY-MM-DD HH:mm:ss";
|
|
145
|
-
const currentDay = (0, import_moment.default)().format("DD");
|
|
146
|
-
const currentMonth = (0, import_moment.default)().format("MM");
|
|
147
|
-
const currentYear = (0, import_moment.default)().format("YYYY");
|
|
148
|
-
const defaultTime = "00:00:00";
|
|
149
|
-
const maxYear = parseInt(currentYear) + 10;
|
|
150
|
-
const isValidDate = (day, month, year) => {
|
|
151
|
-
const date = (0, import_moment.default)(`${day}-${month}-${year}`, "DD-MM-YYYY", true);
|
|
152
|
-
return date.isValid();
|
|
153
|
-
};
|
|
154
|
-
const isValidTime = (hour, minute = "00", second = "00") => {
|
|
155
|
-
const h = parseInt(hour, 10);
|
|
156
|
-
const m = parseInt(minute, 10);
|
|
157
|
-
const s = parseInt(second, 10);
|
|
158
|
-
return h >= 0 && h <= 23 && m >= 0 && m <= 59 && s >= 0 && s <= 59;
|
|
159
|
-
};
|
|
160
|
-
const formatOutput = (day, month, year, time = defaultTime) => {
|
|
161
|
-
let result = (0, import_moment.default)(
|
|
162
|
-
`${day}-${month}-${year} ${time}`,
|
|
163
|
-
"DD-MM-YYYY HH:mm:ss"
|
|
164
|
-
);
|
|
165
|
-
if (!result.isValid()) return null;
|
|
166
|
-
if (isDateTime) {
|
|
167
|
-
result = result.subtract(7, "hours");
|
|
168
|
-
return result.format(dateTimeFormat);
|
|
169
|
-
}
|
|
170
|
-
return result.format(dateFormat);
|
|
171
|
-
};
|
|
172
|
-
if (isDateTime && input.match(
|
|
173
|
-
/^\d{1,2}[\/-]\d{1,2}[\/-]\d{2,4}\s+\d{1,2}(:\d{1,2}(:\d{1,2})?)?$/
|
|
174
|
-
)) {
|
|
175
|
-
const [datePart, timePart] = input.split(/\s+/);
|
|
176
|
-
const dateParts = datePart.split(/[\/-]/);
|
|
177
|
-
const timeParts = timePart.split(":");
|
|
178
|
-
const day = dateParts[0].padStart(2, "0");
|
|
179
|
-
const month = dateParts[1].padStart(2, "0");
|
|
180
|
-
const year = dateParts[2].length <= 2 ? `20${dateParts[2].padStart(2, "0")}` : dateParts[2].padStart(4, "0");
|
|
181
|
-
const hour = timeParts[0].padStart(2, "0");
|
|
182
|
-
const minute = timeParts[1] ? timeParts[1].padStart(2, "0") : "00";
|
|
183
|
-
const second = timeParts[2] ? timeParts[2].padStart(2, "0") : "00";
|
|
184
|
-
if (isValidDate(day, month, year) && isValidTime(hour, minute, second)) {
|
|
185
|
-
let result = (0, import_moment.default)(
|
|
186
|
-
`${day}-${month}-${year} ${hour}:${minute}:${second}`,
|
|
187
|
-
"DD-MM-YYYY HH:mm:ss"
|
|
188
|
-
);
|
|
189
|
-
if (!result.isValid()) return null;
|
|
190
|
-
result = result.subtract(7, "hours");
|
|
191
|
-
return result.format(dateTimeFormat);
|
|
192
|
-
}
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
if (cleanInput.match(/^\d{4}-\d{2}-\d{2}$/)) {
|
|
196
|
-
const [year, month, day] = cleanInput.split("-");
|
|
197
|
-
if (isValidDate(day, month, year)) {
|
|
198
|
-
return formatOutput(day, month, year);
|
|
199
|
-
}
|
|
200
|
-
return null;
|
|
201
|
-
}
|
|
202
|
-
if (cleanInput.match(/^\d{1,2}\/\d{1,2}\/\d{2,4}$/)) {
|
|
203
|
-
const [day, month, year] = cleanInput.split("/");
|
|
204
|
-
const paddedDay = day.padStart(2, "0");
|
|
205
|
-
const paddedMonth = month.padStart(2, "0");
|
|
206
|
-
const fullYear = year.length <= 2 ? `20${year.padStart(2, "0")}` : year.padStart(4, "0");
|
|
207
|
-
if (isValidDate(paddedDay, paddedMonth, fullYear)) {
|
|
208
|
-
return formatOutput(paddedDay, paddedMonth, fullYear);
|
|
209
|
-
}
|
|
210
|
-
return null;
|
|
211
|
-
}
|
|
212
|
-
if (cleanInput.match(/^\d{1,2}-\d{1,2}-\d{2,4}$/)) {
|
|
213
|
-
const [day, month, year] = cleanInput.split("-");
|
|
214
|
-
const paddedDay = day.padStart(2, "0");
|
|
215
|
-
const paddedMonth = month.padStart(2, "0");
|
|
216
|
-
const fullYear = year.length <= 2 ? `20${year.padStart(2, "0")}` : year.padStart(4, "0");
|
|
217
|
-
if (isValidDate(paddedDay, paddedMonth, fullYear)) {
|
|
218
|
-
return formatOutput(paddedDay, paddedMonth, fullYear);
|
|
219
|
-
}
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
if (cleanInput.match(/^\d{1,2}[\/-]\d{1,2}$/)) {
|
|
223
|
-
const [day, month] = cleanInput.split(/[\/-]/);
|
|
224
|
-
const paddedDay = day.padStart(2, "0");
|
|
225
|
-
const paddedMonth = month.padStart(2, "0");
|
|
226
|
-
if (isValidDate(paddedDay, paddedMonth, currentYear)) {
|
|
227
|
-
return formatOutput(paddedDay, paddedMonth, currentYear);
|
|
228
|
-
}
|
|
229
|
-
return null;
|
|
230
|
-
}
|
|
231
|
-
if (cleanInput.match(/^\d{4}$/)) {
|
|
232
|
-
const num = parseInt(cleanInput, 10);
|
|
233
|
-
if (num >= 2e3 && num <= maxYear) {
|
|
234
|
-
if (isValidDate(currentDay, currentMonth, num.toString())) {
|
|
235
|
-
return formatOutput(currentDay, currentMonth, num.toString());
|
|
236
|
-
}
|
|
237
|
-
return null;
|
|
238
|
-
}
|
|
239
|
-
const day = cleanInput.slice(0, 2);
|
|
240
|
-
const month = cleanInput.slice(2, 4);
|
|
241
|
-
if (isValidDate(day, month, currentYear)) {
|
|
242
|
-
return formatOutput(day, month, currentYear);
|
|
243
|
-
}
|
|
244
|
-
return null;
|
|
245
|
-
}
|
|
246
|
-
if (cleanInput.startsWith("-") && /^\-\d+$/.test(cleanInput)) {
|
|
247
|
-
const daysToSubtract = Math.abs(parseInt(cleanInput, 10));
|
|
248
|
-
let result = (0, import_moment.default)().subtract(daysToSubtract, "days");
|
|
249
|
-
if (isDateTime) {
|
|
250
|
-
result = result.subtract(7, "hours");
|
|
251
|
-
}
|
|
252
|
-
if (result.isValid()) {
|
|
253
|
-
return isDateTime ? result.format(dateTimeFormat) : result.format(dateFormat);
|
|
254
|
-
}
|
|
255
|
-
return null;
|
|
256
|
-
}
|
|
257
|
-
if (input.match(/^\d{1,2}[^0-9-\/]+\d{1,2}[^0-9-\/]+\d{2,4}.*$/)) {
|
|
258
|
-
const parts = input.split(/[^0-9-\/]+/).filter(Boolean);
|
|
259
|
-
const day = parts[0].padStart(2, "0");
|
|
260
|
-
const month = parts[1].padStart(2, "0");
|
|
261
|
-
let year = parts[2];
|
|
262
|
-
year = year.length === 2 ? `20${year}` : year.padStart(4, "0");
|
|
263
|
-
if (isValidDate(day, month, year)) {
|
|
264
|
-
return formatOutput(day, month, year);
|
|
265
|
-
}
|
|
266
|
-
return null;
|
|
267
|
-
}
|
|
268
|
-
if (isDateTime) {
|
|
269
|
-
if (cleanInput.length === 9) {
|
|
270
|
-
const day = cleanInput.slice(0, 2);
|
|
271
|
-
const month = cleanInput.slice(2, 4);
|
|
272
|
-
const year = cleanInput.slice(4, 8);
|
|
273
|
-
const hour = cleanInput.slice(8, 9).padStart(2, "0");
|
|
274
|
-
if (isValidDate(day, month, year) && isValidTime(hour)) {
|
|
275
|
-
let result = (0, import_moment.default)(
|
|
276
|
-
`${day}-${month}-${year} ${hour}:00:00`,
|
|
277
|
-
"DD-MM-YYYY HH:mm:ss"
|
|
278
|
-
);
|
|
279
|
-
if (!result.isValid()) return null;
|
|
280
|
-
result = result.subtract(7, "hours");
|
|
281
|
-
return result.format(dateTimeFormat);
|
|
282
|
-
}
|
|
283
|
-
return null;
|
|
284
|
-
}
|
|
285
|
-
if (cleanInput.length === 10) {
|
|
286
|
-
const day = cleanInput.slice(0, 2);
|
|
287
|
-
const month = cleanInput.slice(2, 4);
|
|
288
|
-
const year = cleanInput.slice(4, 8);
|
|
289
|
-
const hour = cleanInput.slice(8, 10);
|
|
290
|
-
if (isValidDate(day, month, year) && isValidTime(hour)) {
|
|
291
|
-
let result = (0, import_moment.default)(
|
|
292
|
-
`${day}-${month}-${year} ${hour}:00:00`,
|
|
293
|
-
"DD-MM-YYYY HH:mm:ss"
|
|
294
|
-
);
|
|
295
|
-
if (!result.isValid()) return null;
|
|
296
|
-
result = result.subtract(7, "hours");
|
|
297
|
-
return result.format(dateTimeFormat);
|
|
298
|
-
}
|
|
299
|
-
return null;
|
|
300
|
-
}
|
|
301
|
-
if (cleanInput.length === 11) {
|
|
302
|
-
const day = cleanInput.slice(0, 2);
|
|
303
|
-
const month = cleanInput.slice(2, 4);
|
|
304
|
-
const year = cleanInput.slice(4, 8);
|
|
305
|
-
const hour = cleanInput.slice(8, 10);
|
|
306
|
-
const minute = cleanInput.slice(10, 11).padStart(2, "0");
|
|
307
|
-
if (isValidDate(day, month, year) && isValidTime(hour, minute)) {
|
|
308
|
-
let result = (0, import_moment.default)(
|
|
309
|
-
`${day}-${month}-${year} ${hour}:${minute}:00`,
|
|
310
|
-
"DD-MM-YYYY HH:mm:ss"
|
|
311
|
-
);
|
|
312
|
-
if (!result.isValid()) return null;
|
|
313
|
-
result = result.subtract(7, "hours");
|
|
314
|
-
return result.format(dateTimeFormat);
|
|
315
|
-
}
|
|
316
|
-
return null;
|
|
317
|
-
}
|
|
318
|
-
if (cleanInput.length === 12) {
|
|
319
|
-
const day = cleanInput.slice(0, 2);
|
|
320
|
-
const month = cleanInput.slice(2, 4);
|
|
321
|
-
const year = cleanInput.slice(4, 8);
|
|
322
|
-
const hour = cleanInput.slice(8, 10);
|
|
323
|
-
const minute = cleanInput.slice(10, 12);
|
|
324
|
-
if (isValidDate(day, month, year) && isValidTime(hour, minute)) {
|
|
325
|
-
let result = (0, import_moment.default)(
|
|
326
|
-
`${day}-${month}-${year} ${hour}:${minute}:00`,
|
|
327
|
-
"DD-MM-YYYY HH:mm:ss"
|
|
328
|
-
);
|
|
329
|
-
if (!result.isValid()) return null;
|
|
330
|
-
result = result.subtract(7, "hours");
|
|
331
|
-
return result.format(dateTimeFormat);
|
|
332
|
-
}
|
|
333
|
-
return null;
|
|
334
|
-
}
|
|
335
|
-
if (cleanInput.length === 13) {
|
|
336
|
-
const day = cleanInput.slice(0, 2);
|
|
337
|
-
const month = cleanInput.slice(2, 4);
|
|
338
|
-
const year = cleanInput.slice(4, 8);
|
|
339
|
-
const hour = cleanInput.slice(8, 10);
|
|
340
|
-
const minute = cleanInput.slice(10, 12);
|
|
341
|
-
const second = cleanInput.slice(12, 13).padStart(2, "0");
|
|
342
|
-
if (isValidDate(day, month, year) && isValidTime(hour, minute, second)) {
|
|
343
|
-
let result = (0, import_moment.default)(
|
|
344
|
-
`${day}-${month}-${year} ${hour}:${minute}:${second}`,
|
|
345
|
-
"DD-MM-YYYY HH:mm:ss"
|
|
346
|
-
);
|
|
347
|
-
if (!result.isValid()) return null;
|
|
348
|
-
result = result.subtract(7, "hours");
|
|
349
|
-
return result.format(dateTimeFormat);
|
|
350
|
-
}
|
|
351
|
-
return null;
|
|
352
|
-
}
|
|
353
|
-
if (cleanInput.length === 14) {
|
|
354
|
-
const day = cleanInput.slice(0, 2);
|
|
355
|
-
const month = cleanInput.slice(2, 4);
|
|
356
|
-
const year = cleanInput.slice(4, 8);
|
|
357
|
-
const hour = cleanInput.slice(8, 10);
|
|
358
|
-
const minute = cleanInput.slice(10, 12);
|
|
359
|
-
const second = cleanInput.slice(12, 14);
|
|
360
|
-
if (isValidDate(day, month, year) && isValidTime(hour, minute, second)) {
|
|
361
|
-
let result = (0, import_moment.default)(
|
|
362
|
-
`${day}-${month}-${year} ${hour}:${minute}:${second}`,
|
|
363
|
-
"DD-MM-YYYY HH:mm:ss"
|
|
364
|
-
);
|
|
365
|
-
if (!result.isValid()) return null;
|
|
366
|
-
result = result.subtract(7, "hours");
|
|
367
|
-
return result.format(dateTimeFormat);
|
|
368
|
-
}
|
|
369
|
-
return null;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
const len = cleanInput.length;
|
|
373
|
-
if (len === 1 || len === 2) {
|
|
374
|
-
const paddedDay = cleanInput.padStart(2, "0");
|
|
375
|
-
if (isValidDate(paddedDay, currentMonth, currentYear)) {
|
|
376
|
-
return formatOutput(paddedDay, currentMonth, currentYear);
|
|
377
|
-
}
|
|
378
|
-
return null;
|
|
379
|
-
}
|
|
380
|
-
if (len === 3) {
|
|
381
|
-
const day = cleanInput.slice(0, 2);
|
|
382
|
-
const month = cleanInput.slice(2, 3).padStart(2, "0");
|
|
383
|
-
if (isValidDate(day, month, currentYear)) {
|
|
384
|
-
return formatOutput(day, month, currentYear);
|
|
385
|
-
}
|
|
386
|
-
return null;
|
|
387
|
-
}
|
|
388
|
-
if (len === 6) {
|
|
389
|
-
const day = cleanInput.slice(0, 2);
|
|
390
|
-
const month = cleanInput.slice(2, 4);
|
|
391
|
-
let year = cleanInput.slice(4, 6);
|
|
392
|
-
year = `20${year}`;
|
|
393
|
-
if (parseInt(month) > 12) {
|
|
394
|
-
if (isValidDate(day, currentMonth, currentYear)) {
|
|
395
|
-
return formatOutput(day, currentMonth, currentYear);
|
|
396
|
-
}
|
|
397
|
-
return null;
|
|
398
|
-
}
|
|
399
|
-
if (isValidDate(day, month, year)) {
|
|
400
|
-
return formatOutput(day, month, year);
|
|
401
|
-
}
|
|
402
|
-
return null;
|
|
403
|
-
}
|
|
404
|
-
if (len === 7) {
|
|
405
|
-
return null;
|
|
406
|
-
}
|
|
407
|
-
if (len === 8) {
|
|
408
|
-
const day = cleanInput.slice(0, 2);
|
|
409
|
-
const month = cleanInput.slice(2, 4);
|
|
410
|
-
const year = cleanInput.slice(4, 8);
|
|
411
|
-
if (isValidDate(day, month, year)) {
|
|
412
|
-
return formatOutput(day, month, year);
|
|
413
|
-
}
|
|
414
|
-
return null;
|
|
415
|
-
}
|
|
416
|
-
if (len > 8 && !isDateTime) {
|
|
417
|
-
return null;
|
|
418
|
-
}
|
|
419
|
-
return null;
|
|
420
|
-
};
|
|
421
|
-
|
|
422
127
|
// src/utils.ts
|
|
423
128
|
__reExport(utils_exports, require("@fctc/interface-logic/utils"), module.exports);
|
|
424
129
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -431,6 +136,5 @@ __reExport(utils_exports, require("@fctc/interface-logic/utils"), module.exports
|
|
|
431
136
|
mergeButtons,
|
|
432
137
|
setStorageItemAsync,
|
|
433
138
|
useStorageState,
|
|
434
|
-
validateAndParseDate,
|
|
435
139
|
...require("@fctc/interface-logic/utils")
|
|
436
140
|
});
|
package/dist/utils.mjs
CHANGED
|
@@ -90,290 +90,6 @@ var guessTypeFromUrl = (url) => {
|
|
|
90
90
|
return map[ext] || null;
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
// src/utils/format-date.ts
|
|
94
|
-
import moment from "moment";
|
|
95
|
-
var validateAndParseDate = (input, isDateTime = false) => {
|
|
96
|
-
if (!input || typeof input !== "string") return null;
|
|
97
|
-
const cleanInput = input.replace(/[^0-9-\/:\s]/g, "");
|
|
98
|
-
const dateFormat = "YYYY-MM-DD";
|
|
99
|
-
const dateTimeFormat = "YYYY-MM-DD HH:mm:ss";
|
|
100
|
-
const currentDay = moment().format("DD");
|
|
101
|
-
const currentMonth = moment().format("MM");
|
|
102
|
-
const currentYear = moment().format("YYYY");
|
|
103
|
-
const defaultTime = "00:00:00";
|
|
104
|
-
const maxYear = parseInt(currentYear) + 10;
|
|
105
|
-
const isValidDate = (day, month, year) => {
|
|
106
|
-
const date = moment(`${day}-${month}-${year}`, "DD-MM-YYYY", true);
|
|
107
|
-
return date.isValid();
|
|
108
|
-
};
|
|
109
|
-
const isValidTime = (hour, minute = "00", second = "00") => {
|
|
110
|
-
const h = parseInt(hour, 10);
|
|
111
|
-
const m = parseInt(minute, 10);
|
|
112
|
-
const s = parseInt(second, 10);
|
|
113
|
-
return h >= 0 && h <= 23 && m >= 0 && m <= 59 && s >= 0 && s <= 59;
|
|
114
|
-
};
|
|
115
|
-
const formatOutput = (day, month, year, time = defaultTime) => {
|
|
116
|
-
let result = moment(
|
|
117
|
-
`${day}-${month}-${year} ${time}`,
|
|
118
|
-
"DD-MM-YYYY HH:mm:ss"
|
|
119
|
-
);
|
|
120
|
-
if (!result.isValid()) return null;
|
|
121
|
-
if (isDateTime) {
|
|
122
|
-
result = result.subtract(7, "hours");
|
|
123
|
-
return result.format(dateTimeFormat);
|
|
124
|
-
}
|
|
125
|
-
return result.format(dateFormat);
|
|
126
|
-
};
|
|
127
|
-
if (isDateTime && input.match(
|
|
128
|
-
/^\d{1,2}[\/-]\d{1,2}[\/-]\d{2,4}\s+\d{1,2}(:\d{1,2}(:\d{1,2})?)?$/
|
|
129
|
-
)) {
|
|
130
|
-
const [datePart, timePart] = input.split(/\s+/);
|
|
131
|
-
const dateParts = datePart.split(/[\/-]/);
|
|
132
|
-
const timeParts = timePart.split(":");
|
|
133
|
-
const day = dateParts[0].padStart(2, "0");
|
|
134
|
-
const month = dateParts[1].padStart(2, "0");
|
|
135
|
-
const year = dateParts[2].length <= 2 ? `20${dateParts[2].padStart(2, "0")}` : dateParts[2].padStart(4, "0");
|
|
136
|
-
const hour = timeParts[0].padStart(2, "0");
|
|
137
|
-
const minute = timeParts[1] ? timeParts[1].padStart(2, "0") : "00";
|
|
138
|
-
const second = timeParts[2] ? timeParts[2].padStart(2, "0") : "00";
|
|
139
|
-
if (isValidDate(day, month, year) && isValidTime(hour, minute, second)) {
|
|
140
|
-
let result = moment(
|
|
141
|
-
`${day}-${month}-${year} ${hour}:${minute}:${second}`,
|
|
142
|
-
"DD-MM-YYYY HH:mm:ss"
|
|
143
|
-
);
|
|
144
|
-
if (!result.isValid()) return null;
|
|
145
|
-
result = result.subtract(7, "hours");
|
|
146
|
-
return result.format(dateTimeFormat);
|
|
147
|
-
}
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
if (cleanInput.match(/^\d{4}-\d{2}-\d{2}$/)) {
|
|
151
|
-
const [year, month, day] = cleanInput.split("-");
|
|
152
|
-
if (isValidDate(day, month, year)) {
|
|
153
|
-
return formatOutput(day, month, year);
|
|
154
|
-
}
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
if (cleanInput.match(/^\d{1,2}\/\d{1,2}\/\d{2,4}$/)) {
|
|
158
|
-
const [day, month, year] = cleanInput.split("/");
|
|
159
|
-
const paddedDay = day.padStart(2, "0");
|
|
160
|
-
const paddedMonth = month.padStart(2, "0");
|
|
161
|
-
const fullYear = year.length <= 2 ? `20${year.padStart(2, "0")}` : year.padStart(4, "0");
|
|
162
|
-
if (isValidDate(paddedDay, paddedMonth, fullYear)) {
|
|
163
|
-
return formatOutput(paddedDay, paddedMonth, fullYear);
|
|
164
|
-
}
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
if (cleanInput.match(/^\d{1,2}-\d{1,2}-\d{2,4}$/)) {
|
|
168
|
-
const [day, month, year] = cleanInput.split("-");
|
|
169
|
-
const paddedDay = day.padStart(2, "0");
|
|
170
|
-
const paddedMonth = month.padStart(2, "0");
|
|
171
|
-
const fullYear = year.length <= 2 ? `20${year.padStart(2, "0")}` : year.padStart(4, "0");
|
|
172
|
-
if (isValidDate(paddedDay, paddedMonth, fullYear)) {
|
|
173
|
-
return formatOutput(paddedDay, paddedMonth, fullYear);
|
|
174
|
-
}
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
if (cleanInput.match(/^\d{1,2}[\/-]\d{1,2}$/)) {
|
|
178
|
-
const [day, month] = cleanInput.split(/[\/-]/);
|
|
179
|
-
const paddedDay = day.padStart(2, "0");
|
|
180
|
-
const paddedMonth = month.padStart(2, "0");
|
|
181
|
-
if (isValidDate(paddedDay, paddedMonth, currentYear)) {
|
|
182
|
-
return formatOutput(paddedDay, paddedMonth, currentYear);
|
|
183
|
-
}
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
if (cleanInput.match(/^\d{4}$/)) {
|
|
187
|
-
const num = parseInt(cleanInput, 10);
|
|
188
|
-
if (num >= 2e3 && num <= maxYear) {
|
|
189
|
-
if (isValidDate(currentDay, currentMonth, num.toString())) {
|
|
190
|
-
return formatOutput(currentDay, currentMonth, num.toString());
|
|
191
|
-
}
|
|
192
|
-
return null;
|
|
193
|
-
}
|
|
194
|
-
const day = cleanInput.slice(0, 2);
|
|
195
|
-
const month = cleanInput.slice(2, 4);
|
|
196
|
-
if (isValidDate(day, month, currentYear)) {
|
|
197
|
-
return formatOutput(day, month, currentYear);
|
|
198
|
-
}
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
if (cleanInput.startsWith("-") && /^\-\d+$/.test(cleanInput)) {
|
|
202
|
-
const daysToSubtract = Math.abs(parseInt(cleanInput, 10));
|
|
203
|
-
let result = moment().subtract(daysToSubtract, "days");
|
|
204
|
-
if (isDateTime) {
|
|
205
|
-
result = result.subtract(7, "hours");
|
|
206
|
-
}
|
|
207
|
-
if (result.isValid()) {
|
|
208
|
-
return isDateTime ? result.format(dateTimeFormat) : result.format(dateFormat);
|
|
209
|
-
}
|
|
210
|
-
return null;
|
|
211
|
-
}
|
|
212
|
-
if (input.match(/^\d{1,2}[^0-9-\/]+\d{1,2}[^0-9-\/]+\d{2,4}.*$/)) {
|
|
213
|
-
const parts = input.split(/[^0-9-\/]+/).filter(Boolean);
|
|
214
|
-
const day = parts[0].padStart(2, "0");
|
|
215
|
-
const month = parts[1].padStart(2, "0");
|
|
216
|
-
let year = parts[2];
|
|
217
|
-
year = year.length === 2 ? `20${year}` : year.padStart(4, "0");
|
|
218
|
-
if (isValidDate(day, month, year)) {
|
|
219
|
-
return formatOutput(day, month, year);
|
|
220
|
-
}
|
|
221
|
-
return null;
|
|
222
|
-
}
|
|
223
|
-
if (isDateTime) {
|
|
224
|
-
if (cleanInput.length === 9) {
|
|
225
|
-
const day = cleanInput.slice(0, 2);
|
|
226
|
-
const month = cleanInput.slice(2, 4);
|
|
227
|
-
const year = cleanInput.slice(4, 8);
|
|
228
|
-
const hour = cleanInput.slice(8, 9).padStart(2, "0");
|
|
229
|
-
if (isValidDate(day, month, year) && isValidTime(hour)) {
|
|
230
|
-
let result = moment(
|
|
231
|
-
`${day}-${month}-${year} ${hour}:00:00`,
|
|
232
|
-
"DD-MM-YYYY HH:mm:ss"
|
|
233
|
-
);
|
|
234
|
-
if (!result.isValid()) return null;
|
|
235
|
-
result = result.subtract(7, "hours");
|
|
236
|
-
return result.format(dateTimeFormat);
|
|
237
|
-
}
|
|
238
|
-
return null;
|
|
239
|
-
}
|
|
240
|
-
if (cleanInput.length === 10) {
|
|
241
|
-
const day = cleanInput.slice(0, 2);
|
|
242
|
-
const month = cleanInput.slice(2, 4);
|
|
243
|
-
const year = cleanInput.slice(4, 8);
|
|
244
|
-
const hour = cleanInput.slice(8, 10);
|
|
245
|
-
if (isValidDate(day, month, year) && isValidTime(hour)) {
|
|
246
|
-
let result = moment(
|
|
247
|
-
`${day}-${month}-${year} ${hour}:00:00`,
|
|
248
|
-
"DD-MM-YYYY HH:mm:ss"
|
|
249
|
-
);
|
|
250
|
-
if (!result.isValid()) return null;
|
|
251
|
-
result = result.subtract(7, "hours");
|
|
252
|
-
return result.format(dateTimeFormat);
|
|
253
|
-
}
|
|
254
|
-
return null;
|
|
255
|
-
}
|
|
256
|
-
if (cleanInput.length === 11) {
|
|
257
|
-
const day = cleanInput.slice(0, 2);
|
|
258
|
-
const month = cleanInput.slice(2, 4);
|
|
259
|
-
const year = cleanInput.slice(4, 8);
|
|
260
|
-
const hour = cleanInput.slice(8, 10);
|
|
261
|
-
const minute = cleanInput.slice(10, 11).padStart(2, "0");
|
|
262
|
-
if (isValidDate(day, month, year) && isValidTime(hour, minute)) {
|
|
263
|
-
let result = moment(
|
|
264
|
-
`${day}-${month}-${year} ${hour}:${minute}:00`,
|
|
265
|
-
"DD-MM-YYYY HH:mm:ss"
|
|
266
|
-
);
|
|
267
|
-
if (!result.isValid()) return null;
|
|
268
|
-
result = result.subtract(7, "hours");
|
|
269
|
-
return result.format(dateTimeFormat);
|
|
270
|
-
}
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
if (cleanInput.length === 12) {
|
|
274
|
-
const day = cleanInput.slice(0, 2);
|
|
275
|
-
const month = cleanInput.slice(2, 4);
|
|
276
|
-
const year = cleanInput.slice(4, 8);
|
|
277
|
-
const hour = cleanInput.slice(8, 10);
|
|
278
|
-
const minute = cleanInput.slice(10, 12);
|
|
279
|
-
if (isValidDate(day, month, year) && isValidTime(hour, minute)) {
|
|
280
|
-
let result = moment(
|
|
281
|
-
`${day}-${month}-${year} ${hour}:${minute}:00`,
|
|
282
|
-
"DD-MM-YYYY HH:mm:ss"
|
|
283
|
-
);
|
|
284
|
-
if (!result.isValid()) return null;
|
|
285
|
-
result = result.subtract(7, "hours");
|
|
286
|
-
return result.format(dateTimeFormat);
|
|
287
|
-
}
|
|
288
|
-
return null;
|
|
289
|
-
}
|
|
290
|
-
if (cleanInput.length === 13) {
|
|
291
|
-
const day = cleanInput.slice(0, 2);
|
|
292
|
-
const month = cleanInput.slice(2, 4);
|
|
293
|
-
const year = cleanInput.slice(4, 8);
|
|
294
|
-
const hour = cleanInput.slice(8, 10);
|
|
295
|
-
const minute = cleanInput.slice(10, 12);
|
|
296
|
-
const second = cleanInput.slice(12, 13).padStart(2, "0");
|
|
297
|
-
if (isValidDate(day, month, year) && isValidTime(hour, minute, second)) {
|
|
298
|
-
let result = moment(
|
|
299
|
-
`${day}-${month}-${year} ${hour}:${minute}:${second}`,
|
|
300
|
-
"DD-MM-YYYY HH:mm:ss"
|
|
301
|
-
);
|
|
302
|
-
if (!result.isValid()) return null;
|
|
303
|
-
result = result.subtract(7, "hours");
|
|
304
|
-
return result.format(dateTimeFormat);
|
|
305
|
-
}
|
|
306
|
-
return null;
|
|
307
|
-
}
|
|
308
|
-
if (cleanInput.length === 14) {
|
|
309
|
-
const day = cleanInput.slice(0, 2);
|
|
310
|
-
const month = cleanInput.slice(2, 4);
|
|
311
|
-
const year = cleanInput.slice(4, 8);
|
|
312
|
-
const hour = cleanInput.slice(8, 10);
|
|
313
|
-
const minute = cleanInput.slice(10, 12);
|
|
314
|
-
const second = cleanInput.slice(12, 14);
|
|
315
|
-
if (isValidDate(day, month, year) && isValidTime(hour, minute, second)) {
|
|
316
|
-
let result = moment(
|
|
317
|
-
`${day}-${month}-${year} ${hour}:${minute}:${second}`,
|
|
318
|
-
"DD-MM-YYYY HH:mm:ss"
|
|
319
|
-
);
|
|
320
|
-
if (!result.isValid()) return null;
|
|
321
|
-
result = result.subtract(7, "hours");
|
|
322
|
-
return result.format(dateTimeFormat);
|
|
323
|
-
}
|
|
324
|
-
return null;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
const len = cleanInput.length;
|
|
328
|
-
if (len === 1 || len === 2) {
|
|
329
|
-
const paddedDay = cleanInput.padStart(2, "0");
|
|
330
|
-
if (isValidDate(paddedDay, currentMonth, currentYear)) {
|
|
331
|
-
return formatOutput(paddedDay, currentMonth, currentYear);
|
|
332
|
-
}
|
|
333
|
-
return null;
|
|
334
|
-
}
|
|
335
|
-
if (len === 3) {
|
|
336
|
-
const day = cleanInput.slice(0, 2);
|
|
337
|
-
const month = cleanInput.slice(2, 3).padStart(2, "0");
|
|
338
|
-
if (isValidDate(day, month, currentYear)) {
|
|
339
|
-
return formatOutput(day, month, currentYear);
|
|
340
|
-
}
|
|
341
|
-
return null;
|
|
342
|
-
}
|
|
343
|
-
if (len === 6) {
|
|
344
|
-
const day = cleanInput.slice(0, 2);
|
|
345
|
-
const month = cleanInput.slice(2, 4);
|
|
346
|
-
let year = cleanInput.slice(4, 6);
|
|
347
|
-
year = `20${year}`;
|
|
348
|
-
if (parseInt(month) > 12) {
|
|
349
|
-
if (isValidDate(day, currentMonth, currentYear)) {
|
|
350
|
-
return formatOutput(day, currentMonth, currentYear);
|
|
351
|
-
}
|
|
352
|
-
return null;
|
|
353
|
-
}
|
|
354
|
-
if (isValidDate(day, month, year)) {
|
|
355
|
-
return formatOutput(day, month, year);
|
|
356
|
-
}
|
|
357
|
-
return null;
|
|
358
|
-
}
|
|
359
|
-
if (len === 7) {
|
|
360
|
-
return null;
|
|
361
|
-
}
|
|
362
|
-
if (len === 8) {
|
|
363
|
-
const day = cleanInput.slice(0, 2);
|
|
364
|
-
const month = cleanInput.slice(2, 4);
|
|
365
|
-
const year = cleanInput.slice(4, 8);
|
|
366
|
-
if (isValidDate(day, month, year)) {
|
|
367
|
-
return formatOutput(day, month, year);
|
|
368
|
-
}
|
|
369
|
-
return null;
|
|
370
|
-
}
|
|
371
|
-
if (len > 8 && !isDateTime) {
|
|
372
|
-
return null;
|
|
373
|
-
}
|
|
374
|
-
return null;
|
|
375
|
-
};
|
|
376
|
-
|
|
377
93
|
// src/utils.ts
|
|
378
94
|
export * from "@fctc/interface-logic/utils";
|
|
379
95
|
export {
|
|
@@ -384,6 +100,5 @@ export {
|
|
|
384
100
|
languages,
|
|
385
101
|
mergeButtons,
|
|
386
102
|
setStorageItemAsync,
|
|
387
|
-
useStorageState
|
|
388
|
-
validateAndParseDate
|
|
103
|
+
useStorageState
|
|
389
104
|
};
|