@pisell/utils 1.0.71 → 1.0.73
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/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
- package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +11 -0
- package/es/arrayUtils.d.ts +4 -1
- package/es/arrayUtils.js +15 -24
- package/es/common/stateHelper.d.ts +6 -2
- package/es/common/stateHelper.js +22 -24
- package/es/common/types.d.ts +13 -10
- package/es/componentStorage.d.ts +27 -25
- package/es/componentStorage.js +94 -130
- package/es/constants/index.js +7 -9
- package/es/date.d.ts +6 -3
- package/es/date.js +36 -53
- package/es/document.d.ts +6 -3
- package/es/document.js +43 -67
- package/es/escPosPrinter/EscPosPrinter.js +353 -490
- package/es/escPosPrinter/index.d.ts +9 -9
- package/es/escPosPrinter/index.js +37 -52
- package/es/format.d.ts +12 -11
- package/es/format.js +90 -116
- package/es/image.d.ts +13 -10
- package/es/image.js +48 -60
- package/es/index.d.ts +38 -23
- package/es/index.js +39 -34
- package/es/jsBridge/index.d.ts +8 -4
- package/es/jsBridge/index.js +57 -56
- package/es/jsBridge/regDeviceApi.js +107 -149
- package/es/jsBridge/types.d.ts +95 -115
- package/es/locales.d.ts +11 -8
- package/es/locales.js +77 -96
- package/es/log.d.ts +11 -6
- package/es/log.js +37 -59
- package/es/miniRedux.d.ts +20 -13
- package/es/miniRedux.js +42 -78
- package/es/number-input/hooks/useNumberInputState.d.ts +6 -2
- package/es/number-input/hooks/useNumberInputState.js +71 -128
- package/es/number-input/types.d.ts +88 -88
- package/es/number-input/utils/formatter.d.ts +13 -10
- package/es/number-input/utils/formatter.js +51 -77
- package/es/number-input/utils/validation.d.ts +7 -2
- package/es/number-input/utils/validation.js +51 -66
- package/es/otherUtils.d.ts +12 -9
- package/es/otherUtils.js +71 -129
- package/es/platform.d.ts +17 -9
- package/es/platform.js +78 -85
- package/es/select/hooks/useDebouncedSearch.d.ts +4 -1
- package/es/select/hooks/useDebouncedSearch.js +39 -53
- package/es/select/hooks/useSelectState.d.ts +7 -7
- package/es/select/hooks/useSelectState.js +56 -113
- package/es/select/index.d.ts +7 -8
- package/es/select/types.d.ts +211 -211
- package/es/select/utils/filterOptions.d.ts +7 -6
- package/es/select/utils/filterOptions.js +26 -31
- package/es/select/utils/helpers.d.ts +10 -9
- package/es/select/utils/helpers.js +42 -52
- package/es/select/utils/index.d.ts +4 -7
- package/es/select/utils/sortOptions.d.ts +6 -5
- package/es/select/utils/sortOptions.js +19 -31
- package/es/select/utils/tagAggregation.d.ts +6 -6
- package/es/select/utils/tagAggregation.js +34 -47
- package/es/text-input/hooks/useTextInputState.d.ts +6 -2
- package/es/text-input/hooks/useTextInputState.js +69 -126
- package/es/text-input/types.d.ts +48 -48
- package/es/text-input/utils/validation.d.ts +7 -2
- package/es/text-input/utils/validation.js +50 -70
- package/es/typeUtils.d.ts +11 -8
- package/es/typeUtils.js +61 -84
- package/es/walletValidity.d.ts +36 -34
- package/es/walletValidity.js +332 -456
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
- package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +16 -0
- package/lib/_virtual/_rolldown/runtime.js +23 -0
- package/lib/arrayUtils.d.ts +4 -1
- package/lib/arrayUtils.js +14 -39
- package/lib/common/stateHelper.d.ts +6 -2
- package/lib/common/stateHelper.js +21 -32
- package/lib/common/types.d.ts +13 -10
- package/lib/componentStorage.d.ts +27 -25
- package/lib/componentStorage.js +96 -126
- package/lib/constants/index.js +7 -36
- package/lib/date.d.ts +6 -3
- package/lib/date.js +43 -65
- package/lib/document.d.ts +6 -3
- package/lib/document.js +46 -62
- package/lib/escPosPrinter/EscPosPrinter.js +327 -403
- package/lib/escPosPrinter/index.d.ts +9 -9
- package/lib/escPosPrinter/index.js +38 -84
- package/lib/format.d.ts +12 -11
- package/lib/format.js +91 -99
- package/lib/image.d.ts +13 -10
- package/lib/image.js +48 -74
- package/lib/index.d.ts +38 -23
- package/lib/index.js +115 -78
- package/lib/jsBridge/index.d.ts +8 -4
- package/lib/jsBridge/index.js +58 -77
- package/lib/jsBridge/regDeviceApi.js +106 -153
- package/lib/jsBridge/types.d.ts +95 -115
- package/lib/locales.d.ts +11 -8
- package/lib/locales.js +79 -90
- package/lib/log.d.ts +11 -6
- package/lib/log.js +37 -61
- package/lib/miniRedux.d.ts +20 -13
- package/lib/miniRedux.js +43 -92
- package/lib/number-input/hooks/useNumberInputState.d.ts +6 -2
- package/lib/number-input/hooks/useNumberInputState.js +71 -81
- package/lib/number-input/types.d.ts +88 -88
- package/lib/number-input/utils/formatter.d.ts +13 -10
- package/lib/number-input/utils/formatter.js +52 -49
- package/lib/number-input/utils/validation.d.ts +7 -2
- package/lib/number-input/utils/validation.js +50 -52
- package/lib/otherUtils.d.ts +12 -9
- package/lib/otherUtils.js +86 -98
- package/lib/platform.d.ts +17 -9
- package/lib/platform.js +85 -122
- package/lib/select/hooks/useDebouncedSearch.d.ts +4 -1
- package/lib/select/hooks/useDebouncedSearch.js +40 -41
- package/lib/select/hooks/useSelectState.d.ts +7 -7
- package/lib/select/hooks/useSelectState.js +58 -93
- package/lib/select/index.d.ts +7 -8
- package/lib/select/types.d.ts +211 -211
- package/lib/select/utils/filterOptions.d.ts +7 -6
- package/lib/select/utils/filterOptions.js +26 -37
- package/lib/select/utils/helpers.d.ts +10 -9
- package/lib/select/utils/helpers.js +45 -41
- package/lib/select/utils/index.d.ts +4 -7
- package/lib/select/utils/sortOptions.d.ts +6 -5
- package/lib/select/utils/sortOptions.js +18 -39
- package/lib/select/utils/tagAggregation.d.ts +6 -6
- package/lib/select/utils/tagAggregation.js +33 -41
- package/lib/text-input/hooks/useTextInputState.d.ts +6 -2
- package/lib/text-input/hooks/useTextInputState.js +69 -79
- package/lib/text-input/types.d.ts +48 -48
- package/lib/text-input/utils/validation.d.ts +7 -2
- package/lib/text-input/utils/validation.js +49 -58
- package/lib/typeUtils.d.ts +11 -8
- package/lib/typeUtils.js +68 -73
- package/lib/walletValidity.d.ts +36 -34
- package/lib/walletValidity.js +345 -317
- package/package.json +1 -2
- package/es/common/index.d.ts +0 -5
- package/es/common/index.js +0 -5
- package/es/common/types.js +0 -1
- package/es/constants/index.d.ts +0 -7
- package/es/firebase/config/index.d.ts +0 -13
- package/es/firebase/config/index.js +0 -54
- package/es/firebase/index.d.ts +0 -28
- package/es/firebase/index.js +0 -232
- package/es/jsBridge/types.js +0 -1
- package/es/number-input/hooks/index.d.ts +0 -4
- package/es/number-input/hooks/index.js +0 -5
- package/es/number-input/index.d.ts +0 -14
- package/es/number-input/index.js +0 -21
- package/es/number-input/types.js +0 -1
- package/es/number-input/utils/index.d.ts +0 -7
- package/es/number-input/utils/index.js +0 -8
- package/es/select/hooks/index.d.ts +0 -5
- package/es/select/hooks/index.js +0 -6
- package/es/select/index.js +0 -13
- package/es/select/types.js +0 -1
- package/es/select/utils/index.js +0 -8
- package/es/text-input/hooks/index.d.ts +0 -4
- package/es/text-input/hooks/index.js +0 -5
- package/es/text-input/index.d.ts +0 -14
- package/es/text-input/index.js +0 -20
- package/es/text-input/types.js +0 -1
- package/es/text-input/utils/index.d.ts +0 -5
- package/es/text-input/utils/index.js +0 -7
- package/lib/common/index.d.ts +0 -5
- package/lib/common/index.js +0 -29
- package/lib/common/types.js +0 -17
- package/lib/constants/index.d.ts +0 -7
- package/lib/firebase/config/index.d.ts +0 -13
- package/lib/firebase/config/index.js +0 -79
- package/lib/firebase/index.d.ts +0 -28
- package/lib/firebase/index.js +0 -180
- package/lib/jsBridge/types.js +0 -17
- package/lib/number-input/hooks/index.d.ts +0 -4
- package/lib/number-input/hooks/index.js +0 -29
- package/lib/number-input/index.d.ts +0 -14
- package/lib/number-input/index.js +0 -41
- package/lib/number-input/types.js +0 -17
- package/lib/number-input/utils/index.d.ts +0 -7
- package/lib/number-input/utils/index.js +0 -39
- package/lib/select/hooks/index.d.ts +0 -5
- package/lib/select/hooks/index.js +0 -34
- package/lib/select/index.js +0 -53
- package/lib/select/types.js +0 -17
- package/lib/select/utils/index.js +0 -48
- package/lib/text-input/hooks/index.d.ts +0 -4
- package/lib/text-input/hooks/index.js +0 -29
- package/lib/text-input/index.d.ts +0 -14
- package/lib/text-input/index.js +0 -35
- package/lib/text-input/types.js +0 -17
- package/lib/text-input/utils/index.d.ts +0 -5
- package/lib/text-input/utils/index.js +0 -32
package/es/walletValidity.js
CHANGED
|
@@ -1,499 +1,375 @@
|
|
|
1
|
-
import dayjs from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
ALL_DAY_END: '23:59',
|
|
9
|
-
DEFAULT_FUTURE_YEARS: 10,
|
|
10
|
-
SECONDS_SUFFIX: ':59'
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
//#region src/walletValidity.ts
|
|
3
|
+
const CONSTANTS = {
|
|
4
|
+
ALL_DAY_START: "00:00",
|
|
5
|
+
ALL_DAY_END: "23:59",
|
|
6
|
+
DEFAULT_FUTURE_YEARS: 10,
|
|
7
|
+
SECONDS_SUFFIX: ":59"
|
|
11
8
|
};
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
9
|
+
const textConfig = {
|
|
10
|
+
"zh-HK": {
|
|
11
|
+
weekdays: [
|
|
12
|
+
"日",
|
|
13
|
+
"一",
|
|
14
|
+
"二",
|
|
15
|
+
"三",
|
|
16
|
+
"四",
|
|
17
|
+
"五",
|
|
18
|
+
"六"
|
|
19
|
+
],
|
|
20
|
+
separator: "、",
|
|
21
|
+
timeSeparator: "–",
|
|
22
|
+
rangeSeparator: " 至 ",
|
|
23
|
+
periodSeparator: ";",
|
|
24
|
+
timeSlotSeparator: ",",
|
|
25
|
+
every: "每",
|
|
26
|
+
day: "天",
|
|
27
|
+
week: "周",
|
|
28
|
+
month: "月",
|
|
29
|
+
year: "年",
|
|
30
|
+
available: "可用",
|
|
31
|
+
unlimited: "无限期",
|
|
32
|
+
multipleRules: "多規則,點詳情",
|
|
33
|
+
multipleSlots: ",多時段",
|
|
34
|
+
until: "至",
|
|
35
|
+
daily: "每天",
|
|
36
|
+
days: "天",
|
|
37
|
+
weeks: "周",
|
|
38
|
+
everyPrefix: "每",
|
|
39
|
+
weekPrefix: "周",
|
|
40
|
+
dateFormat: "YYYY-MM-DD",
|
|
41
|
+
dateTimeFormat: "YYYY-MM-DD HH:mm",
|
|
42
|
+
longTermValidFrom: "自",
|
|
43
|
+
noExpiry: "起長期有效",
|
|
44
|
+
on: ""
|
|
45
|
+
},
|
|
46
|
+
"zh-CN": {
|
|
47
|
+
weekdays: [
|
|
48
|
+
"日",
|
|
49
|
+
"一",
|
|
50
|
+
"二",
|
|
51
|
+
"三",
|
|
52
|
+
"四",
|
|
53
|
+
"五",
|
|
54
|
+
"六"
|
|
55
|
+
],
|
|
56
|
+
separator: "、",
|
|
57
|
+
timeSeparator: "–",
|
|
58
|
+
rangeSeparator: " 至 ",
|
|
59
|
+
periodSeparator: ";",
|
|
60
|
+
timeSlotSeparator: ",",
|
|
61
|
+
every: "每",
|
|
62
|
+
day: "天",
|
|
63
|
+
week: "周",
|
|
64
|
+
month: "月",
|
|
65
|
+
year: "年",
|
|
66
|
+
available: "可用",
|
|
67
|
+
unlimited: "无限期",
|
|
68
|
+
multipleRules: "多规则,点详情",
|
|
69
|
+
multipleSlots: ",多时段",
|
|
70
|
+
until: "至",
|
|
71
|
+
daily: "每天",
|
|
72
|
+
days: "天",
|
|
73
|
+
weeks: "周",
|
|
74
|
+
everyPrefix: "每",
|
|
75
|
+
weekPrefix: "周",
|
|
76
|
+
dateFormat: "YYYY-MM-DD",
|
|
77
|
+
dateTimeFormat: "YYYY-MM-DD HH:mm",
|
|
78
|
+
longTermValidFrom: "自",
|
|
79
|
+
noExpiry: "起长期有效",
|
|
80
|
+
on: ""
|
|
81
|
+
},
|
|
82
|
+
"en": {
|
|
83
|
+
weekdays: [
|
|
84
|
+
"Sun",
|
|
85
|
+
"Mon",
|
|
86
|
+
"Tue",
|
|
87
|
+
"Wed",
|
|
88
|
+
"Thu",
|
|
89
|
+
"Fri",
|
|
90
|
+
"Sat"
|
|
91
|
+
],
|
|
92
|
+
separator: ", ",
|
|
93
|
+
timeSeparator: "–",
|
|
94
|
+
rangeSeparator: " - ",
|
|
95
|
+
periodSeparator: "; ",
|
|
96
|
+
timeSlotSeparator: ", ",
|
|
97
|
+
every: "every ",
|
|
98
|
+
day: "day",
|
|
99
|
+
week: "week",
|
|
100
|
+
month: "month",
|
|
101
|
+
year: "year",
|
|
102
|
+
available: "available",
|
|
103
|
+
unlimited: "unlimited",
|
|
104
|
+
multipleRules: "Multiple rules, see details",
|
|
105
|
+
multipleSlots: ", multiple slots",
|
|
106
|
+
until: "Until ",
|
|
107
|
+
daily: "daily",
|
|
108
|
+
days: "days",
|
|
109
|
+
weeks: "weeks",
|
|
110
|
+
everyPrefix: "every ",
|
|
111
|
+
weekPrefix: "",
|
|
112
|
+
dateFormat: "DD MMM YYYY",
|
|
113
|
+
dateTimeFormat: "DD MMM YYYY h:mm A",
|
|
114
|
+
longTermValidFrom: "from ",
|
|
115
|
+
noExpiry: ", no expiry",
|
|
116
|
+
on: "on "
|
|
117
|
+
}
|
|
101
118
|
};
|
|
102
|
-
|
|
103
119
|
/**
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
120
|
+
* 获取星期几的表示
|
|
121
|
+
* @param dayNumbers 星期几的数字数组 (0-6, 0代表周日)
|
|
122
|
+
* @param locale 语言设置
|
|
123
|
+
* @param separator 分隔符,可选,默认使用locale配置的分隔符
|
|
124
|
+
* @returns 格式化的星期几文案
|
|
125
|
+
*/
|
|
110
126
|
function getWeekdayText(dayNumbers, locale, separator) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return config.weekdays[day];
|
|
114
|
-
}).join(separator || config.separator);
|
|
127
|
+
const config = textConfig[locale];
|
|
128
|
+
return dayNumbers.map((day) => config.weekdays[day]).join(separator || config.separator);
|
|
115
129
|
}
|
|
116
|
-
|
|
117
130
|
/**
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
131
|
+
* 获取指定语言的文案配置
|
|
132
|
+
* @param locale 语言设置
|
|
133
|
+
* @param key 配置项key
|
|
134
|
+
* @returns 对应语言的文案
|
|
135
|
+
*/
|
|
123
136
|
function getText(locale, key) {
|
|
124
|
-
|
|
137
|
+
return textConfig[locale][key];
|
|
125
138
|
}
|
|
126
|
-
|
|
127
139
|
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
140
|
+
* 获取指定语言的配置对象(缓存优化)
|
|
141
|
+
* @param locale 语言设置
|
|
142
|
+
* @returns 对应语言的完整配置对象
|
|
143
|
+
*/
|
|
132
144
|
function getConfig(locale) {
|
|
133
|
-
|
|
145
|
+
return textConfig[locale];
|
|
134
146
|
}
|
|
135
|
-
|
|
136
147
|
/**
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
148
|
+
* 获取每日频率文案
|
|
149
|
+
* @param frequency 频率数字
|
|
150
|
+
* @param locale 语言设置
|
|
151
|
+
* @returns 格式化的每日频率文案
|
|
152
|
+
*/
|
|
142
153
|
function getDailyFrequencyText(frequency, locale) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (locale === 'en') {
|
|
148
|
-
return "".concat(config.everyPrefix).concat(frequency, " ").concat(config.days);
|
|
149
|
-
} else {
|
|
150
|
-
return "".concat(config.everyPrefix).concat(frequency).concat(config.days);
|
|
151
|
-
}
|
|
154
|
+
if (frequency === 1) return getText(locale, "daily");
|
|
155
|
+
const config = textConfig[locale];
|
|
156
|
+
if (locale === "en") return `${config.everyPrefix}${frequency} ${config.days}`;
|
|
157
|
+
else return `${config.everyPrefix}${frequency}${config.days}`;
|
|
152
158
|
}
|
|
153
|
-
|
|
154
159
|
/**
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
+
* 获取每周频率前缀文案
|
|
161
|
+
* @param frequency 频率数字
|
|
162
|
+
* @param locale 语言设置
|
|
163
|
+
* @returns 格式化的每周频率前缀文案
|
|
164
|
+
*/
|
|
160
165
|
function getWeeklyFrequencyPrefix(frequency, locale) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (locale === 'en') {
|
|
166
|
-
return "".concat(config.everyPrefix).concat(frequency, " ").concat(config.weeks, ", ");
|
|
167
|
-
} else {
|
|
168
|
-
return "".concat(config.everyPrefix).concat(frequency).concat(config.weeks, " ");
|
|
169
|
-
}
|
|
166
|
+
if (frequency === 1) return "";
|
|
167
|
+
const config = textConfig[locale];
|
|
168
|
+
if (locale === "en") return `${config.everyPrefix}${frequency} ${config.weeks}, `;
|
|
169
|
+
else return `${config.everyPrefix}${frequency}${config.weeks} `;
|
|
170
170
|
}
|
|
171
|
-
|
|
172
171
|
/**
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
function formatDateTime(dateTime) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if (isAll) {
|
|
185
|
-
// 全天情况下的日期格式
|
|
186
|
-
return date.format(config.dateFormat);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// 非全天情况下的日期时间格式
|
|
190
|
-
return date.format(config.dateTimeFormat);
|
|
172
|
+
* 格式化日期时间函数
|
|
173
|
+
* @param dateTime 日期时间字符串
|
|
174
|
+
* @param isAll 是否为全天
|
|
175
|
+
* @param locale 语言设置
|
|
176
|
+
* @returns 格式化后的日期时间字符串
|
|
177
|
+
*/
|
|
178
|
+
function formatDateTime(dateTime, isAll = false, locale = "zh-CN") {
|
|
179
|
+
const date = dayjs(dateTime);
|
|
180
|
+
const config = getConfig(locale);
|
|
181
|
+
if (isAll) return date.format(config.dateFormat);
|
|
182
|
+
return date.format(config.dateTimeFormat);
|
|
191
183
|
}
|
|
192
|
-
|
|
193
184
|
/**
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
185
|
+
* 判断是否为全天日程
|
|
186
|
+
* @param startTime 开始时间 (HH:mm格式)
|
|
187
|
+
* @param endTime 结束时间 (HH:mm格式)
|
|
188
|
+
* @returns 是否为全天日程
|
|
189
|
+
*/
|
|
199
190
|
function isAllDaySchedule(startTime, endTime) {
|
|
200
|
-
|
|
191
|
+
return startTime === CONSTANTS.ALL_DAY_START && endTime === CONSTANTS.ALL_DAY_END;
|
|
201
192
|
}
|
|
202
|
-
|
|
203
193
|
/**
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
function formatDateRange(startDate, endDate, isStarted, locale) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
194
|
+
* 生成日期范围文案
|
|
195
|
+
* @param startDate 开始日期
|
|
196
|
+
* @param endDate 结束日期
|
|
197
|
+
* @param isStarted 是否已开始
|
|
198
|
+
* @param locale 语言设置
|
|
199
|
+
* @param isAllDay 是否为全天
|
|
200
|
+
* @returns 格式化的日期范围文案
|
|
201
|
+
*/
|
|
202
|
+
function formatDateRange(startDate, endDate, isStarted, locale, isAllDay = false) {
|
|
203
|
+
const config = getConfig(locale);
|
|
204
|
+
if (isStarted) {
|
|
205
|
+
const endDateStr = formatDateTime(endDate, isAllDay, locale);
|
|
206
|
+
return `${config.until}${endDateStr}`;
|
|
207
|
+
} else {
|
|
208
|
+
const startDateStr = formatDateTime(startDate, isAllDay, locale);
|
|
209
|
+
const endDateStr = formatDateTime(endDate, isAllDay, locale);
|
|
210
|
+
return `${startDateStr}${config.rangeSeparator}${endDateStr}`;
|
|
211
|
+
}
|
|
223
212
|
}
|
|
224
|
-
|
|
225
213
|
/**
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
return '';
|
|
251
|
-
}
|
|
252
|
-
var now = dayjs();
|
|
253
|
-
|
|
254
|
-
// 获取日程开始时间
|
|
255
|
-
var startTime = null;
|
|
256
|
-
if (schedule.start_time) {
|
|
257
|
-
startTime = dayjs(schedule.start_time);
|
|
258
|
-
} else if (schedule.designation && schedule.designation.length > 0) {
|
|
259
|
-
// designation类型,取第一个日期作为开始时间
|
|
260
|
-
var firstDesignation = schedule.designation[0];
|
|
261
|
-
if (firstDesignation && firstDesignation.start_date && firstDesignation.start_time) {
|
|
262
|
-
startTime = dayjs("".concat(firstDesignation.start_date, " ").concat(firstDesignation.start_time));
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// 判断开始时间是否在当前时间之后
|
|
267
|
-
var isStarted = startTime ? isTimeStarted(now, startTime) : false;
|
|
268
|
-
|
|
269
|
-
// 根据不同类型和状态返回摘要
|
|
270
|
-
return generateSummaryText(schedule, isStarted, locale);
|
|
271
|
-
} catch (error) {
|
|
272
|
-
console.warn('Error in getScheduleSummary:', error);
|
|
273
|
-
return '';
|
|
274
|
-
}
|
|
214
|
+
* 获取schedule摘要信息
|
|
215
|
+
* @param scheduleList 日程列表
|
|
216
|
+
* @param locale 语言设置
|
|
217
|
+
* @returns 摘要文本
|
|
218
|
+
*/
|
|
219
|
+
function getScheduleSummary(scheduleList, locale = "zh-CN") {
|
|
220
|
+
try {
|
|
221
|
+
if (!scheduleList || !Array.isArray(scheduleList)) return "";
|
|
222
|
+
if (scheduleList.length > 1) return getText(locale, "multipleRules");
|
|
223
|
+
if (scheduleList.length === 0) return "";
|
|
224
|
+
const schedule = scheduleList[0];
|
|
225
|
+
if (!schedule) return "";
|
|
226
|
+
const now = dayjs();
|
|
227
|
+
let startTime = null;
|
|
228
|
+
if (schedule.start_time) startTime = dayjs(schedule.start_time);
|
|
229
|
+
else if (schedule.designation && schedule.designation.length > 0) {
|
|
230
|
+
const firstDesignation = schedule.designation[0];
|
|
231
|
+
if (firstDesignation && firstDesignation.start_date && firstDesignation.start_time) startTime = dayjs(`${firstDesignation.start_date} ${firstDesignation.start_time}`);
|
|
232
|
+
}
|
|
233
|
+
return generateSummaryText(schedule, startTime ? isTimeStarted(now, startTime) : false, locale);
|
|
234
|
+
} catch (error) {
|
|
235
|
+
console.warn("Error in getScheduleSummary:", error);
|
|
236
|
+
return "";
|
|
237
|
+
}
|
|
275
238
|
}
|
|
276
|
-
|
|
277
239
|
/**
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
240
|
+
* 判断开始时间是否在当前时间之后
|
|
241
|
+
* @param now 当前时间
|
|
242
|
+
* @param startTime 开始时间
|
|
243
|
+
* @returns 是否已开始
|
|
244
|
+
*/
|
|
283
245
|
function isTimeStarted(now, startTime) {
|
|
284
|
-
|
|
246
|
+
return startTime.isBefore(now);
|
|
285
247
|
}
|
|
286
|
-
|
|
287
248
|
/**
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
249
|
+
* 生成摘要文本
|
|
250
|
+
* @param schedule 日程对象
|
|
251
|
+
* @param isStarted 是否已开始
|
|
252
|
+
* @param locale 语言设置
|
|
253
|
+
* @returns 生成的摘要文本
|
|
254
|
+
*/
|
|
294
255
|
function generateSummaryText(schedule, isStarted, locale) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if (!endDate) return '';
|
|
304
|
-
var endDateStr = formatDateTime(endDate, true, locale);
|
|
305
|
-
var prefix = '';
|
|
306
|
-
var suffix = getText(locale, 'multipleSlots');
|
|
307
|
-
return "".concat(prefix).concat(endDateStr).concat(suffix);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// 3. 循环日程
|
|
311
|
-
if (schedule.repeat_type !== 'none' && schedule.repeat_rule) {
|
|
312
|
-
return generateRecurringSummary(schedule, isStarted, locale);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
// 4. 单个日程(包括designation类型的单个日期段)
|
|
316
|
-
return generateSingleScheduleSummary(schedule, isStarted, locale);
|
|
256
|
+
if (schedule.type === "designation" && schedule.designation && schedule.designation.length > 1) return getText(locale, "multipleRules");
|
|
257
|
+
if (schedule.type === "time-slots") {
|
|
258
|
+
const endDate = getScheduleEndDate(schedule);
|
|
259
|
+
if (!endDate) return "";
|
|
260
|
+
return `${formatDateTime(endDate, true, locale)}${getText(locale, "multipleSlots")}`;
|
|
261
|
+
}
|
|
262
|
+
if (schedule.repeat_type !== "none" && schedule.repeat_rule) return generateRecurringSummary(schedule, isStarted, locale);
|
|
263
|
+
return generateSingleScheduleSummary(schedule, isStarted, locale);
|
|
317
264
|
}
|
|
318
|
-
|
|
319
265
|
/**
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
266
|
+
* 生成循环日程摘要
|
|
267
|
+
* @param schedule 日程对象
|
|
268
|
+
* @param isStarted 是否已开始
|
|
269
|
+
* @param locale 语言设置
|
|
270
|
+
* @returns 循环日程摘要文本
|
|
271
|
+
*/
|
|
326
272
|
function generateRecurringSummary(schedule, isStarted, locale) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
if (repeat_type === 'daily') {
|
|
346
|
-
var frequencyText = getDailyFrequencyText(frequency, locale);
|
|
347
|
-
var dateRange = formatDateRange(schedule.start_time, endDate, isStarted, locale, true);
|
|
348
|
-
return "".concat(dateRange, "\uFF0C").concat(frequencyText);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
// 按周循环
|
|
352
|
-
if (repeat_type === 'weekly') {
|
|
353
|
-
var weekdaysText = getWeekdayText(frequency_date, locale, '/');
|
|
354
|
-
var frequencyPrefix = getWeeklyFrequencyPrefix(frequency, locale);
|
|
355
|
-
var config = getConfig(locale);
|
|
356
|
-
var _dateRange = formatDateRange(schedule.start_time, endDate, isStarted, locale, true);
|
|
357
|
-
return "".concat(_dateRange, "\uFF0C").concat(frequencyPrefix).concat(config.weekPrefix).concat(weekdaysText);
|
|
358
|
-
}
|
|
359
|
-
return '';
|
|
273
|
+
const { repeat_type, repeat_rule } = schedule;
|
|
274
|
+
if (!repeat_rule) return "";
|
|
275
|
+
const { frequency, frequency_date, end } = repeat_rule;
|
|
276
|
+
if (end.type === "never") return generateNeverEndingRecurringSummary(schedule, isStarted, locale, repeat_type, frequency, frequency_date);
|
|
277
|
+
const endDate = getScheduleEndDate(schedule);
|
|
278
|
+
if (!endDate) return "";
|
|
279
|
+
formatDateTime(endDate, true, locale);
|
|
280
|
+
if (repeat_type === "daily") {
|
|
281
|
+
const frequencyText = getDailyFrequencyText(frequency, locale);
|
|
282
|
+
return `${formatDateRange(schedule.start_time, endDate, isStarted, locale, true)},${frequencyText}`;
|
|
283
|
+
}
|
|
284
|
+
if (repeat_type === "weekly") {
|
|
285
|
+
const weekdaysText = getWeekdayText(frequency_date, locale, "/");
|
|
286
|
+
const frequencyPrefix = getWeeklyFrequencyPrefix(frequency, locale);
|
|
287
|
+
const config = getConfig(locale);
|
|
288
|
+
return `${formatDateRange(schedule.start_time, endDate, isStarted, locale, true)},${frequencyPrefix}${config.weekPrefix}${weekdaysText}`;
|
|
289
|
+
}
|
|
290
|
+
return "";
|
|
360
291
|
}
|
|
361
|
-
|
|
362
292
|
/**
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
293
|
+
* 生成永不结束的循环日程摘要
|
|
294
|
+
* @param schedule 日程对象
|
|
295
|
+
* @param isStarted 是否已开始
|
|
296
|
+
* @param locale 语言设置
|
|
297
|
+
* @param repeatType 循环类型
|
|
298
|
+
* @param frequency 频率
|
|
299
|
+
* @param frequencyDate 频率日期数组(用于周循环)
|
|
300
|
+
* @returns 永不结束的循环日程摘要文本
|
|
301
|
+
*/
|
|
372
302
|
function generateNeverEndingRecurringSummary(schedule, isStarted, locale, repeatType, frequency, frequencyDate) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
if (repeatType === 'weekly') {
|
|
397
|
-
var weekdaysText = getWeekdayText(frequencyDate, locale, locale === 'en' ? ' & ' : '/');
|
|
398
|
-
if (frequency === 1) {
|
|
399
|
-
// 频率=1:中文"每周三/五可用",英文"on Wed & Fri"
|
|
400
|
-
if (locale === 'en') {
|
|
401
|
-
return "".concat(config.on).concat(weekdaysText);
|
|
402
|
-
} else {
|
|
403
|
-
return "".concat(config.everyPrefix).concat(config.weekPrefix).concat(weekdaysText).concat(config.available);
|
|
404
|
-
}
|
|
405
|
-
} else {
|
|
406
|
-
// 频率>1:中文"每2周 周三/五",英文"Every 2 weeks, on Wed & Fri"
|
|
407
|
-
var frequencyPrefix = getWeeklyFrequencyPrefix(frequency, locale);
|
|
408
|
-
if (locale === 'en') {
|
|
409
|
-
return "".concat(frequencyPrefix).concat(config.on).concat(weekdaysText);
|
|
410
|
-
} else {
|
|
411
|
-
return "".concat(frequencyPrefix).concat(config.weekPrefix).concat(weekdaysText);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
return '';
|
|
303
|
+
const config = getConfig(locale);
|
|
304
|
+
if (repeatType === "daily") if (frequency === 1) {
|
|
305
|
+
if (schedule.start_time) {
|
|
306
|
+
const startDateStr = formatDateTime(schedule.start_time, true, locale);
|
|
307
|
+
return `${config.longTermValidFrom}${startDateStr}${config.noExpiry}`;
|
|
308
|
+
}
|
|
309
|
+
return "";
|
|
310
|
+
} else {
|
|
311
|
+
const frequencyText = getDailyFrequencyText(frequency, locale);
|
|
312
|
+
if (locale === "en") return `${frequencyText}`;
|
|
313
|
+
else return `${frequencyText}${config.available}`;
|
|
314
|
+
}
|
|
315
|
+
if (repeatType === "weekly") {
|
|
316
|
+
const weekdaysText = getWeekdayText(frequencyDate, locale, locale === "en" ? " & " : "/");
|
|
317
|
+
if (frequency === 1) if (locale === "en") return `${config.on}${weekdaysText}`;
|
|
318
|
+
else return `${config.everyPrefix}${config.weekPrefix}${weekdaysText}${config.available}`;
|
|
319
|
+
else {
|
|
320
|
+
const frequencyPrefix = getWeeklyFrequencyPrefix(frequency, locale);
|
|
321
|
+
if (locale === "en") return `${frequencyPrefix}${config.on}${weekdaysText}`;
|
|
322
|
+
else return `${frequencyPrefix}${config.weekPrefix}${weekdaysText}`;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return "";
|
|
416
326
|
}
|
|
417
|
-
|
|
418
327
|
/**
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
328
|
+
* 生成单个日程摘要
|
|
329
|
+
* @param schedule 日程对象
|
|
330
|
+
* @param isStarted 是否已开始
|
|
331
|
+
* @param locale 语言设置
|
|
332
|
+
* @returns 单个日程摘要文本
|
|
333
|
+
*/
|
|
425
334
|
function generateSingleScheduleSummary(schedule, isStarted, locale) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
} else {
|
|
442
|
-
// 非全天日程
|
|
443
|
-
var startDateTime = "".concat(startDate, " ").concat(startTime).concat(CONSTANTS.SECONDS_SUFFIX);
|
|
444
|
-
var endDateTime = "".concat(endDate, " ").concat(endTime).concat(CONSTANTS.SECONDS_SUFFIX);
|
|
445
|
-
return formatDateRange(startDateTime, endDateTime, isStarted, locale, false);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
// 标准日程处理
|
|
450
|
-
if (isAllDay) {
|
|
451
|
-
// 全天日程
|
|
452
|
-
var _endDate = getScheduleEndDate(schedule);
|
|
453
|
-
if (!_endDate) return '';
|
|
454
|
-
return formatDateRange(schedule.start_time, _endDate, isStarted, locale, true);
|
|
455
|
-
} else {
|
|
456
|
-
// 非全天日程
|
|
457
|
-
return formatDateRange(schedule.start_time, schedule.end_time, isStarted, locale, false);
|
|
458
|
-
}
|
|
335
|
+
const isAllDay = schedule.is_all === 1;
|
|
336
|
+
if (schedule.type === "designation" && schedule.designation && schedule.designation.length === 1) {
|
|
337
|
+
const designation = schedule.designation[0];
|
|
338
|
+
const startDate = designation.start_date;
|
|
339
|
+
const endDate = designation.end_date;
|
|
340
|
+
const startTime = designation.start_time;
|
|
341
|
+
const endTime = designation.end_time;
|
|
342
|
+
if (isAllDaySchedule(startTime, endTime) || isAllDay) return formatDateRange(startDate, endDate, isStarted, locale, true);
|
|
343
|
+
else return formatDateRange(`${startDate} ${startTime}${CONSTANTS.SECONDS_SUFFIX}`, `${endDate} ${endTime}${CONSTANTS.SECONDS_SUFFIX}`, isStarted, locale, false);
|
|
344
|
+
}
|
|
345
|
+
if (isAllDay) {
|
|
346
|
+
const endDate = getScheduleEndDate(schedule);
|
|
347
|
+
if (!endDate) return "";
|
|
348
|
+
return formatDateRange(schedule.start_time, endDate, isStarted, locale, true);
|
|
349
|
+
} else return formatDateRange(schedule.start_time, schedule.end_time, isStarted, locale, false);
|
|
459
350
|
}
|
|
460
|
-
|
|
461
351
|
/**
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
352
|
+
* 获取日程结束日期
|
|
353
|
+
* @param schedule 日程对象
|
|
354
|
+
* @returns 结束日期字符串,如果无法确定则返回null
|
|
355
|
+
*/
|
|
466
356
|
function getScheduleEndDate(schedule) {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
if (schedule.end_time) {
|
|
487
|
-
return schedule.end_time;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
// time-slots类型
|
|
491
|
-
if (schedule.start_time) {
|
|
492
|
-
return schedule.start_time;
|
|
493
|
-
}
|
|
494
|
-
return null;
|
|
495
|
-
} catch (error) {
|
|
496
|
-
console.warn('Error in getScheduleEndDate:', error);
|
|
497
|
-
return null;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
357
|
+
try {
|
|
358
|
+
if (schedule.repeat_rule) {
|
|
359
|
+
if (schedule.repeat_rule.end.type === "never") return `${dayjs().add(CONSTANTS.DEFAULT_FUTURE_YEARS, "year").format("YYYY-MM-DD")} ${CONSTANTS.ALL_DAY_END}${CONSTANTS.SECONDS_SUFFIX}`;
|
|
360
|
+
else if (schedule.repeat_rule.end.end_date) return `${schedule.repeat_rule.end.end_date} ${CONSTANTS.ALL_DAY_END}${CONSTANTS.SECONDS_SUFFIX}`;
|
|
361
|
+
}
|
|
362
|
+
if (schedule.designation && schedule.designation.length > 0) {
|
|
363
|
+
const lastDesignation = schedule.designation[schedule.designation.length - 1];
|
|
364
|
+
return `${lastDesignation.end_date} ${lastDesignation.end_time}${CONSTANTS.SECONDS_SUFFIX}`;
|
|
365
|
+
}
|
|
366
|
+
if (schedule.end_time) return schedule.end_time;
|
|
367
|
+
if (schedule.start_time) return schedule.start_time;
|
|
368
|
+
return null;
|
|
369
|
+
} catch (error) {
|
|
370
|
+
console.warn("Error in getScheduleEndDate:", error);
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
//#endregion
|
|
375
|
+
export { getScheduleSummary };
|