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