koishi-plugin-echo-cave 1.24.2 → 1.24.3
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/lib/index.cjs +11 -16
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -909,34 +909,29 @@ var PREDEFINED_PERIODS = [
|
|
|
909
909
|
];
|
|
910
910
|
var TIME_UNITS = {
|
|
911
911
|
m: 30 * 24 * 60 * 60 * 1e3,
|
|
912
|
-
// 月(按约 30 天算)
|
|
913
912
|
w: 7 * 24 * 60 * 60 * 1e3,
|
|
914
|
-
// 周
|
|
915
913
|
d: 24 * 60 * 60 * 1e3,
|
|
916
|
-
// 天
|
|
917
914
|
h: 60 * 60 * 1e3
|
|
918
|
-
// 小时
|
|
919
915
|
};
|
|
920
916
|
function parseCustomTime(timeStr) {
|
|
917
|
+
if (!timeStr || typeof timeStr !== "string") return null;
|
|
918
|
+
const s = timeStr.toLowerCase();
|
|
919
|
+
if (!/^(\d+(m|w|d|h))+$/i.test(s)) return null;
|
|
921
920
|
const regex = /(\d+)([mwdh])/g;
|
|
922
921
|
let match;
|
|
923
922
|
let totalMs = 0;
|
|
924
|
-
let lastUnit = "";
|
|
925
923
|
const unitOrder = ["m", "w", "d", "h"];
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
const [, value, unit] = match;
|
|
931
|
-
const num = parseInt(value, 10);
|
|
924
|
+
let lastIndex = -1;
|
|
925
|
+
while ((match = regex.exec(s)) !== null) {
|
|
926
|
+
const value = parseInt(match[1], 10);
|
|
927
|
+
const unit = match[2].toLowerCase();
|
|
932
928
|
const currentIndex = unitOrder.indexOf(unit);
|
|
933
|
-
|
|
934
|
-
if (
|
|
935
|
-
if (lastUnit && currentIndex > lastIndex) {
|
|
929
|
+
if (currentIndex === -1) return null;
|
|
930
|
+
if (lastIndex !== -1 && currentIndex < lastIndex) {
|
|
936
931
|
return null;
|
|
937
932
|
}
|
|
938
|
-
totalMs +=
|
|
939
|
-
|
|
933
|
+
totalMs += value * (TIME_UNITS[unit] ?? 0);
|
|
934
|
+
lastIndex = currentIndex;
|
|
940
935
|
}
|
|
941
936
|
return totalMs;
|
|
942
937
|
}
|