koishi-plugin-tmp-bot 1.21.0 → 1.21.2

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
  }
@@ -275,6 +285,45 @@ function setData(apiData) {
275
285
 
276
286
  listEl.innerHTML = '';
277
287
 
288
+ // === DEBUG: 诊断信息输出到页面 ===
289
+ const debugEl = document.createElement('div');
290
+ debugEl.id = 'debug-info';
291
+ debugEl.style.cssText = 'color:#0f0;font-size:11px;padding:6px 10px;background:#111;margin:4px 10px;border-radius:4px;font-family:monospace;white-space:pre-wrap;';
292
+ listEl.appendChild(debugEl);
293
+
294
+ const dbg = [];
295
+ dbg.push('now=' + Date.now() + ' new Date=' + new Date().toISOString());
296
+ dbg.push('timezone=' + Intl.DateTimeFormat().resolvedOptions().timeZone);
297
+ dbg.push('offset(min)=' + new Date().getTimezoneOffset());
298
+
299
+ const first = servers[0];
300
+ if (first && first.playerHistory && first.playerHistory.length > 0) {
301
+ const sample = first.playerHistory[0];
302
+ dbg.push('sample.updateTime=' + JSON.stringify(sample.updateTime));
303
+ const replaced = sample.updateTime.replace(' ', 'T');
304
+ dbg.push('replaced=' + replaced);
305
+ dbg.push('new Date(str).getTime()=' + new Date(replaced).getTime());
306
+ dbg.push('new Date(str)=' + new Date(replaced).toISOString());
307
+
308
+ // 手动解析
309
+ const [datePart, timePart] = sample.updateTime.trim().replace('T', ' ').split(' ');
310
+ const [y, m, d] = datePart.split('-').map(Number);
311
+ const parts = timePart.split(':').map(Number);
312
+ const h = parts[0] || 0, min = parts[1] || 0;
313
+ const manualTs = new Date(y, m - 1, d, h, min, 0).getTime();
314
+ dbg.push('manual parse: y=' + y + ' m=' + m + ' d=' + d + ' h=' + h + ' min=' + min);
315
+ dbg.push('manualTs=' + manualTs + ' ISO=' + new Date(manualTs).toISOString());
316
+
317
+ // normalizeHistory 结果
318
+ const normalized = normalizeHistory(first.playerHistory);
319
+ const nonZero = normalized.filter(v => v !== 0);
320
+ dbg.push('normalized.len=' + normalized.length + ' nonZero=' + nonZero.length);
321
+ dbg.push('first5=' + JSON.stringify(normalized.slice(0, 5)));
322
+ dbg.push('last5=' + JSON.stringify(normalized.slice(-5)));
323
+ }
324
+ debugEl.innerText = dbg.join('\n');
325
+ // === END DEBUG ===
326
+
278
327
  servers.forEach(server => {
279
328
  listEl.appendChild(createServerCard(server));
280
329
  });
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.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "homepage": "https://github.com/79887143/koishi-plugin-tmp-bot",