befly 3.21.2 → 3.22.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.
@@ -0,0 +1,81 @@
1
+ {
2
+ "id": {
3
+ "name": "ID",
4
+ "input": "integer",
5
+ "min": 1,
6
+ "max": null
7
+ },
8
+ "state": {
9
+ "name": "状态",
10
+ "input": "integer",
11
+ "min": 0,
12
+ "max": 2
13
+ },
14
+ "createdAt": {
15
+ "name": "创建时间",
16
+ "input": "number"
17
+ },
18
+ "updatedAt": {
19
+ "name": "更新时间",
20
+ "input": "number"
21
+ },
22
+ "deletedAt": {
23
+ "name": "删除时间",
24
+ "input": "number"
25
+ },
26
+ "userId": {
27
+ "name": "用户ID",
28
+ "input": "integer",
29
+ "min": 1,
30
+ "max": null
31
+ },
32
+ "filePath": {
33
+ "name": "文件路径",
34
+ "input": "string",
35
+ "min": 1,
36
+ "max": 500
37
+ },
38
+ "url": {
39
+ "name": "文件地址",
40
+ "input": "string",
41
+ "min": 1,
42
+ "max": 1000
43
+ },
44
+ "isImage": {
45
+ "name": "是否图片",
46
+ "input": "integer",
47
+ "min": 0,
48
+ "max": 1
49
+ },
50
+ "fileType": {
51
+ "name": "文件类型",
52
+ "input": "enum",
53
+ "check": "image|video|audio|file",
54
+ "min": 4,
55
+ "max": 5
56
+ },
57
+ "fileSize": {
58
+ "name": "文件大小",
59
+ "input": "integer",
60
+ "min": 0,
61
+ "max": null
62
+ },
63
+ "fileKey": {
64
+ "name": "文件标识",
65
+ "input": "string",
66
+ "min": 1,
67
+ "max": 100
68
+ },
69
+ "fileExt": {
70
+ "name": "文件扩展名",
71
+ "input": "string",
72
+ "min": 1,
73
+ "max": 20
74
+ },
75
+ "fileName": {
76
+ "name": "文件名",
77
+ "input": "string",
78
+ "min": 1,
79
+ "max": 200
80
+ }
81
+ }
package/utils/datetime.js CHANGED
@@ -1,38 +1,24 @@
1
- const visitStatsDateFormatter = new Intl.DateTimeFormat("en-CA", {
1
+ const ymdNumberFormatter = new Intl.DateTimeFormat("en-CA", {
2
2
  year: "numeric",
3
3
  month: "2-digit",
4
4
  day: "2-digit"
5
5
  });
6
6
 
7
- export const DAY_MS = 24 * 60 * 60 * 1000;
8
-
9
- function toDate(value = Date.now()) {
10
- if (value instanceof Date) {
11
- return value;
12
- }
13
-
14
- return Reflect.construct(Date, [value]);
15
- }
16
-
17
- function padDatePart(value) {
18
- if (value < 10) {
19
- return `0${value}`;
20
- }
7
+ const monthDirFormatterCache = new Map();
21
8
 
22
- return String(value);
23
- }
9
+ export const DAY_MS = 24 * 60 * 60 * 1000;
24
10
 
25
11
  export function addDays(timestamp = Date.now(), days = 0) {
26
12
  return Number(timestamp || 0) + Number(days || 0) * DAY_MS;
27
13
  }
28
14
 
29
15
  export function getDateYmdNumber(timestamp = Date.now()) {
30
- return Number(visitStatsDateFormatter.format(timestamp).replace(/[^0-9]/g, ""));
16
+ return Number(ymdNumberFormatter.format(timestamp).replace(/[^0-9]/g, ""));
31
17
  }
32
18
 
33
19
  export function getDayStartTime(timestamp = Date.now()) {
34
- const date = toDate(timestamp);
35
- return Reflect.construct(Date, [date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0]).getTime();
20
+ const date = new Date(timestamp);
21
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0).getTime();
36
22
  }
37
23
 
38
24
  export function getDayEndTime(timestamp = Date.now()) {
@@ -49,20 +35,31 @@ export function getTimeBucketStart(timestamp = Date.now(), bucketMs = 0) {
49
35
  return time - (time % bucket);
50
36
  }
51
37
 
38
+ export function getMonthDir(value = Date.now(), timeZone = "Asia/Shanghai") {
39
+ const zone = typeof timeZone === "string" && timeZone.trim().length > 0 ? timeZone.trim() : "Asia/Shanghai";
40
+
41
+ if (!monthDirFormatterCache.has(zone)) {
42
+ monthDirFormatterCache.set(
43
+ zone,
44
+ new Intl.DateTimeFormat("sv-SE", {
45
+ timeZone: zone,
46
+ year: "numeric",
47
+ month: "2-digit"
48
+ })
49
+ );
50
+ }
51
+
52
+ return monthDirFormatterCache.get(zone).format(value).replace("-", "");
53
+ }
54
+
52
55
  export function formatYmdHms(value = Date.now(), format = "dateTime") {
53
- const date = toDate(value);
56
+ const date = new Date(value);
54
57
  const y = date.getFullYear();
55
- const m = date.getMonth() + 1;
56
- const d = date.getDate();
57
- const h = date.getHours();
58
- const mi = date.getMinutes();
59
- const s = date.getSeconds();
60
-
61
- const mm = padDatePart(m);
62
- const dd = padDatePart(d);
63
- const hh = padDatePart(h);
64
- const mii = padDatePart(mi);
65
- const ss = padDatePart(s);
58
+ const mm = String(date.getMonth() + 1).padStart(2, "0");
59
+ const dd = String(date.getDate()).padStart(2, "0");
60
+ const hh = String(date.getHours()).padStart(2, "0");
61
+ const mii = String(date.getMinutes()).padStart(2, "0");
62
+ const ss = String(date.getSeconds()).padStart(2, "0");
66
63
 
67
64
  if (format === "date") {
68
65
  return `${y}-${mm}-${dd}`;