Skip to content

Commit 849ad9d

Browse files
committed
Fix two-day date differences in Timezone Guard
1 parent 0e8c24a commit 849ad9d

6 files changed

Lines changed: 35 additions & 11 deletions

File tree

‎plugins/liuchen19960902/timezone-guard/.minimax-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"schemaVersion": 1,
33
"name": "timezone-guard",
44
"displayName": "A/时差保安",
5-
"version": "1.0.2",
5+
"version": "1.0.3",
66
"description": "别在对方睡着的时区跟对方聊天。A/时差保安实时对照对方当地时间:绿了正常聊,黄了短聊,红了先睡。",
77
"author": "FineCat",
88
"icon": "icon.png",

‎plugins/liuchen19960902/timezone-guard/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ follows the **other** city's local time, because what matters is whether *they*
99
> and the date format are all in Chinese. This README and `README.zh-CN.md` are the two languages it
1010
> ships in; the page itself has no language switch.
1111
12-
Author: [FineCat](https://github.com/LiuChen19960902) · Version: `1.0.2`
12+
Author: [FineCat](https://github.com/LiuChen19960902) · Version: `1.0.3`
1313

1414
![A/时差保安 showing the verdict, with the target city clock above the local one](docs/preview.png)
1515

@@ -148,8 +148,8 @@ npm test
148148

149149
Run it from the package directory. The suite covers the band thresholds landing exactly on the
150150
hour (06:00 / 09:00 / 18:00 / 22:00), offset parsing including non-integral zones such as
151-
`GMT+05:45`, the time-difference wording, and the calendar-day difference used for "still
152-
yesterday".
151+
`GMT+05:45`, and the time-difference wording for cities on the same date or one or two calendar
152+
days apart.
153153

154154
## License
155155

‎plugins/liuchen19960902/timezone-guard/README.zh-CN.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
> **界面只有中文。** 插件名、判定文案、城市名、时段、日期格式都是中文,没有语言切换;本仓库提供中英两份 README,页面本身只有一种语言。
88
9-
作者:[FineCat](https://github.com/LiuChen19960902) · 版本:`1.0.2`
9+
作者:[FineCat](https://github.com/LiuChen19960902) · 版本:`1.0.3`
1010

1111
![A/时差保安:判定区给出「短聊就好」,下方是对方城市与自己的两个时钟](docs/preview.png)
1212

@@ -89,7 +89,7 @@ MiniMax Code 桌面版 **3.1.4**,Windows 11 家庭版(10.0.26300,x64)。
8989
npm test
9090
```
9191

92-
在包目录下执行。覆盖四个阈值正好落在整点(06:00 / 09:00 / 18:00 / 22:00)、偏移解析(含 `GMT+05:45` 这类非整小时时区)、时差文案,以及「对方还在昨天」用的日历日差。
92+
在包目录下执行。覆盖四个阈值正好落在整点(06:00 / 09:00 / 18:00 / 22:00)、偏移解析(含 `GMT+05:45` 这类非整小时时区),以及两地同日、相差一天或两天时的时差文案。
9393

9494
## 许可
9595

‎plugins/liuchen19960902/timezone-guard/miniapp/client/app.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// 时区规范化、档位判定、偏移解析、时差文案都放在 time.js 里:
1414
// 那份文件浏览器与 Node 共用同一份源码,可以直接跑 node --test,
1515
// 也不用在这里和别处各留一份、改一处漏一处。
16-
const { resolveZone, periodOf, parseOffset, formatDiff, dayDelta } = window.TZ_TIME;
16+
const { resolveZone, periodOf, parseOffset, formatDiff, relativeDayNote } = window.TZ_TIME;
1717

1818
/* ------------------------------------------------------------------ *
1919
* 城市库
@@ -696,9 +696,8 @@ function render() {
696696
// 非整小时是「5 小时 45 分钟」,直接接在「快」后面会连成一团,这里补一个空格。
697697
const gap = diffMinutes % 60 === 0 ? '' : ' ';
698698
const parts = [`${ahead}比${behind}快${gap}${formatDiff(diffMinutes)}`];
699-
const dayDiff = dayDelta(target, home);
700-
if (dayDiff < 0) parts.push('对方还在昨天');
701-
else if (dayDiff > 0) parts.push('对方那边已是明天');
699+
const dayNote = relativeDayNote(target, home);
700+
if (dayNote) parts.push(dayNote);
702701
setText(el.factDiff, parts.join(' · '));
703702
}
704703
}

‎plugins/liuchen19960902/timezone-guard/miniapp/client/time.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@
122122
return Math.round((t - h) / 86400000);
123123
}
124124

125+
const DAY_NOTES = {
126+
'-2': '对方还在前天',
127+
'-1': '对方还在昨天',
128+
1: '对方那边已是明天',
129+
2: '对方那边已是后天',
130+
};
131+
132+
/** 按对方相对我方的日历日差生成提示,同日省略。 */
133+
function relativeDayNote(target, home) {
134+
return DAY_NOTES[dayDelta(target, home)] || '';
135+
}
136+
125137
return {
126138
STORAGE_KEY: STORAGE_KEY,
127139
resolveZone: resolveZone,
@@ -130,5 +142,6 @@
130142
parseOffset: parseOffset,
131143
formatDiff: formatDiff,
132144
dayDelta: dayDelta,
145+
relativeDayNote: relativeDayNote,
133146
};
134147
});

‎plugins/liuchen19960902/timezone-guard/test/time.test.mjs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import assert from 'node:assert/strict';
33

44
import time from '../miniapp/client/time.js';
55

6-
const { STORAGE_KEY, resolveZone, periodOf, bandOf, parseOffset, formatDiff, dayDelta } = time;
6+
const { STORAGE_KEY, resolveZone, periodOf, bandOf, parseOffset, formatDiff, dayDelta, relativeDayNote } = time;
77

88
/**
99
* 这里测的是 miniapp/client/time.js —— 浏览器和 Node 跑的是同一份源码,
@@ -90,6 +90,18 @@ test('dayDelta: 只看日历日,不看时刻', () => {
9090
assert.equal(dayDelta(day(2027, 1, 1), day(2026, 12, 31)), 1);
9191
});
9292

93+
test('relativeDayNote: 日期变更线两侧可相差两个日历日,同日没有后缀', () => {
94+
// 2026-11-22T10:30Z:帕果帕果为 21 日 23:30,UTC 为 22 日,基里蒂马蒂为 23 日 00:30。
95+
const pagoPago = { year: 2026, month: 11, day: 21 };
96+
const utc = { year: 2026, month: 11, day: 22 };
97+
const kiritimati = { year: 2026, month: 11, day: 23 };
98+
assert.equal(relativeDayNote(pagoPago, kiritimati), '对方还在前天');
99+
assert.equal(relativeDayNote(pagoPago, utc), '对方还在昨天');
100+
assert.equal(relativeDayNote(utc, utc), '');
101+
assert.equal(relativeDayNote(kiritimati, utc), '对方那边已是明天');
102+
assert.equal(relativeDayNote(kiritimati, pagoPago), '对方那边已是后天');
103+
});
104+
93105
test('periodOf: 中文时段替代 AM/PM', () => {
94106
assert.equal(periodOf(0), '凌晨');
95107
assert.equal(periodOf(5), '凌晨');

0 commit comments

Comments
 (0)