koishi-plugin-tmp-bot 1.21.0 → 1.21.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.
@@ -197,12 +197,22 @@ function normalizeHistory(playerHistory) {
197
197
 
198
198
  if (!playerHistory || playerHistory.length === 0) return [];
199
199
 
200
+ // 手动解析时间字符串,避免不同环境下 Date 解析行为不一致
201
+ function parseTime(str) {
202
+ const [datePart, timePart] = str.trim().replace('T', ' ').split(' ');
203
+ const [y, m, d] = datePart.split('-').map(Number);
204
+ const parts = timePart.split(':').map(Number);
205
+ const h = parts[0] || 0, min = parts[1] || 0;
206
+ return new Date(y, m - 1, d, h, min, 0).getTime();
207
+ }
208
+
200
209
  const now = Date.now();
201
210
  const currentSlot = Math.floor(now / SLOT_MS) * SLOT_MS;
202
211
 
203
212
  const dataMap = {};
204
213
  for (const item of playerHistory) {
205
- const ts = new Date(item.updateTime.replace(' ', 'T')).getTime();
214
+ const ts = parseTime(item.updateTime);
215
+ if (isNaN(ts)) continue;
206
216
  const slot = Math.floor(ts / SLOT_MS) * SLOT_MS;
207
217
  dataMap[slot] = item.playerCount;
208
218
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-tmp-bot",
3
3
  "description": "欧洲卡车模拟2 TMP查询插件,不会部署的可以直接使用此机器人->QQ:3523283907",
4
- "version": "1.21.0",
4
+ "version": "1.21.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "homepage": "https://github.com/79887143/koishi-plugin-tmp-bot",