uview-plus 3.3.32 → 3.3.33
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/changelog.md +3 -0
- package/libs/function/test.js +36 -4
- package/package.json +1 -1
package/changelog.md
CHANGED
package/libs/function/test.js
CHANGED
|
@@ -22,12 +22,44 @@ export function url(value) {
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* 验证日期格式
|
|
25
|
+
* @param {number | string} value yyyy-mm-dd hh:mm:ss 或 时间戳
|
|
25
26
|
*/
|
|
26
27
|
export function date(value) {
|
|
27
|
-
if (!value) return false
|
|
28
|
-
//
|
|
29
|
-
if (
|
|
30
|
-
|
|
28
|
+
if (!value) return false;
|
|
29
|
+
// number类型,判断是否是时间戳
|
|
30
|
+
if (typeof value === "number") {
|
|
31
|
+
// len === 10 秒级时间戳 len === 13 毫秒级时间戳
|
|
32
|
+
if (value.toString().length !== 10 && value.toString().length !== 13) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return !isNaN(new Date(value).getTime());
|
|
36
|
+
}
|
|
37
|
+
if (typeof value === "string") {
|
|
38
|
+
// 是否为string类型时间戳
|
|
39
|
+
const numV = Number(value);
|
|
40
|
+
if (!isNaN(numV)) {
|
|
41
|
+
if (
|
|
42
|
+
numV.toString().length === 10 ||
|
|
43
|
+
numV.toString().length === 13
|
|
44
|
+
) {
|
|
45
|
+
return !isNaN(new Date(numV).getTime());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// 非时间戳,且长度在yyyy-mm-dd 至 yyyy-mm-dd hh:mm:ss 之间
|
|
49
|
+
if (value.length < 10 || value.length > 19) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
const dateRegex =
|
|
53
|
+
/^\d{4}[-\/]\d{2}[-\/]\d{2}( \d{1,2}:\d{2}(:\d{2})?)?$/;
|
|
54
|
+
if (!dateRegex.test(value)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
// 检查是否为有效日期
|
|
58
|
+
const dateValue = new Date(value);
|
|
59
|
+
return !isNaN(dateValue.getTime());
|
|
60
|
+
}
|
|
61
|
+
// 非number和string类型,不做校验
|
|
62
|
+
return false;
|
|
31
63
|
}
|
|
32
64
|
|
|
33
65
|
/**
|