diff --git a/plugins/liuchen19960902/timezone-guard/.minimax-plugin/plugin.json b/plugins/liuchen19960902/timezone-guard/.minimax-plugin/plugin.json index 130b9442..f5901391 100644 --- a/plugins/liuchen19960902/timezone-guard/.minimax-plugin/plugin.json +++ b/plugins/liuchen19960902/timezone-guard/.minimax-plugin/plugin.json @@ -2,7 +2,7 @@ "schemaVersion": 1, "name": "timezone-guard", "displayName": "A/时差保安", - "version": "1.0.2", + "version": "1.0.3", "description": "别在对方睡着的时区跟对方聊天。A/时差保安实时对照对方当地时间:绿了正常聊,黄了短聊,红了先睡。", "author": "FineCat", "icon": "icon.png", diff --git a/plugins/liuchen19960902/timezone-guard/README.md b/plugins/liuchen19960902/timezone-guard/README.md index 27bda3e5..475e917b 100644 --- a/plugins/liuchen19960902/timezone-guard/README.md +++ b/plugins/liuchen19960902/timezone-guard/README.md @@ -9,7 +9,7 @@ follows the **other** city's local time, because what matters is whether *they* > and the date format are all in Chinese. This README and `README.zh-CN.md` are the two languages it > ships in; the page itself has no language switch. -Author: [FineCat](https://github.com/LiuChen19960902) · Version: `1.0.2` +Author: [FineCat](https://github.com/LiuChen19960902) · Version: `1.0.3` ![A/时差保安 showing the verdict, with the target city clock above the local one](docs/preview.png) @@ -148,8 +148,8 @@ npm test Run it from the package directory. The suite covers the band thresholds landing exactly on the hour (06:00 / 09:00 / 18:00 / 22:00), offset parsing including non-integral zones such as -`GMT+05:45`, the time-difference wording, and the calendar-day difference used for "still -yesterday". +`GMT+05:45`, and the time-difference wording for cities on the same date or one or two calendar +days apart. ## License diff --git a/plugins/liuchen19960902/timezone-guard/README.zh-CN.md b/plugins/liuchen19960902/timezone-guard/README.zh-CN.md index faca230f..2754788c 100644 --- a/plugins/liuchen19960902/timezone-guard/README.zh-CN.md +++ b/plugins/liuchen19960902/timezone-guard/README.zh-CN.md @@ -6,7 +6,7 @@ > **界面只有中文。** 插件名、判定文案、城市名、时段、日期格式都是中文,没有语言切换;本仓库提供中英两份 README,页面本身只有一种语言。 -作者:[FineCat](https://github.com/LiuChen19960902) · 版本:`1.0.2` +作者:[FineCat](https://github.com/LiuChen19960902) · 版本:`1.0.3` ![A/时差保安:判定区给出「短聊就好」,下方是对方城市与自己的两个时钟](docs/preview.png) @@ -89,7 +89,7 @@ MiniMax Code 桌面版 **3.1.4**,Windows 11 家庭版(10.0.26300,x64)。 npm test ``` -在包目录下执行。覆盖四个阈值正好落在整点(06:00 / 09:00 / 18:00 / 22:00)、偏移解析(含 `GMT+05:45` 这类非整小时时区)、时差文案,以及「对方还在昨天」用的日历日差。 +在包目录下执行。覆盖四个阈值正好落在整点(06:00 / 09:00 / 18:00 / 22:00)、偏移解析(含 `GMT+05:45` 这类非整小时时区),以及两地同日、相差一天或两天时的时差文案。 ## 许可 diff --git a/plugins/liuchen19960902/timezone-guard/miniapp/client/app.js b/plugins/liuchen19960902/timezone-guard/miniapp/client/app.js index 8554285b..3c83eb65 100644 --- a/plugins/liuchen19960902/timezone-guard/miniapp/client/app.js +++ b/plugins/liuchen19960902/timezone-guard/miniapp/client/app.js @@ -13,7 +13,7 @@ // 时区规范化、档位判定、偏移解析、时差文案都放在 time.js 里: // 那份文件浏览器与 Node 共用同一份源码,可以直接跑 node --test, // 也不用在这里和别处各留一份、改一处漏一处。 -const { resolveZone, periodOf, parseOffset, formatDiff, dayDelta } = window.TZ_TIME; +const { resolveZone, periodOf, parseOffset, formatDiff, relativeDayNote } = window.TZ_TIME; /* ------------------------------------------------------------------ * * 城市库 @@ -696,9 +696,8 @@ function render() { // 非整小时是「5 小时 45 分钟」,直接接在「快」后面会连成一团,这里补一个空格。 const gap = diffMinutes % 60 === 0 ? '' : ' '; const parts = [`${ahead}比${behind}快${gap}${formatDiff(diffMinutes)}`]; - const dayDiff = dayDelta(target, home); - if (dayDiff < 0) parts.push('对方还在昨天'); - else if (dayDiff > 0) parts.push('对方那边已是明天'); + const dayNote = relativeDayNote(target, home); + if (dayNote) parts.push(dayNote); setText(el.factDiff, parts.join(' · ')); } } diff --git a/plugins/liuchen19960902/timezone-guard/miniapp/client/time.js b/plugins/liuchen19960902/timezone-guard/miniapp/client/time.js index 35e3d69b..28bdc17c 100644 --- a/plugins/liuchen19960902/timezone-guard/miniapp/client/time.js +++ b/plugins/liuchen19960902/timezone-guard/miniapp/client/time.js @@ -122,6 +122,18 @@ return Math.round((t - h) / 86400000); } + const DAY_NOTES = { + '-2': '对方还在前天', + '-1': '对方还在昨天', + 1: '对方那边已是明天', + 2: '对方那边已是后天', + }; + + /** 按对方相对我方的日历日差生成提示,同日省略。 */ + function relativeDayNote(target, home) { + return DAY_NOTES[dayDelta(target, home)] || ''; + } + return { STORAGE_KEY: STORAGE_KEY, resolveZone: resolveZone, @@ -130,5 +142,6 @@ parseOffset: parseOffset, formatDiff: formatDiff, dayDelta: dayDelta, + relativeDayNote: relativeDayNote, }; }); diff --git a/plugins/liuchen19960902/timezone-guard/test/time.test.mjs b/plugins/liuchen19960902/timezone-guard/test/time.test.mjs index e9ef30f9..80e3d161 100644 --- a/plugins/liuchen19960902/timezone-guard/test/time.test.mjs +++ b/plugins/liuchen19960902/timezone-guard/test/time.test.mjs @@ -3,7 +3,7 @@ import assert from 'node:assert/strict'; import time from '../miniapp/client/time.js'; -const { STORAGE_KEY, resolveZone, periodOf, bandOf, parseOffset, formatDiff, dayDelta } = time; +const { STORAGE_KEY, resolveZone, periodOf, bandOf, parseOffset, formatDiff, dayDelta, relativeDayNote } = time; /** * 这里测的是 miniapp/client/time.js —— 浏览器和 Node 跑的是同一份源码, @@ -90,6 +90,18 @@ test('dayDelta: 只看日历日,不看时刻', () => { assert.equal(dayDelta(day(2027, 1, 1), day(2026, 12, 31)), 1); }); +test('relativeDayNote: 日期变更线两侧可相差两个日历日,同日没有后缀', () => { + // 2026-11-22T10:30Z:帕果帕果为 21 日 23:30,UTC 为 22 日,基里蒂马蒂为 23 日 00:30。 + const pagoPago = { year: 2026, month: 11, day: 21 }; + const utc = { year: 2026, month: 11, day: 22 }; + const kiritimati = { year: 2026, month: 11, day: 23 }; + assert.equal(relativeDayNote(pagoPago, kiritimati), '对方还在前天'); + assert.equal(relativeDayNote(pagoPago, utc), '对方还在昨天'); + assert.equal(relativeDayNote(utc, utc), ''); + assert.equal(relativeDayNote(kiritimati, utc), '对方那边已是明天'); + assert.equal(relativeDayNote(kiritimati, pagoPago), '对方那边已是后天'); +}); + test('periodOf: 中文时段替代 AM/PM', () => { assert.equal(periodOf(0), '凌晨'); assert.equal(periodOf(5), '凌晨');