Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions plugins/liuchen19960902/timezone-guard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions plugins/liuchen19960902/timezone-guard/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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` 这类非整小时时区),以及两地同日、相差一天或两天时的时差文案。

## 许可

Expand Down
7 changes: 3 additions & 4 deletions plugins/liuchen19960902/timezone-guard/miniapp/client/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/* ------------------------------------------------------------------ *
* 城市库
Expand Down Expand Up @@ -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(' · '));
}
}
Expand Down
13 changes: 13 additions & 0 deletions plugins/liuchen19960902/timezone-guard/miniapp/client/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -130,5 +142,6 @@
parseOffset: parseOffset,
formatDiff: formatDiff,
dayDelta: dayDelta,
relativeDayNote: relativeDayNote,
};
});
14 changes: 13 additions & 1 deletion plugins/liuchen19960902/timezone-guard/test/time.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 跑的是同一份源码,
Expand Down Expand Up @@ -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), '凌晨');
Expand Down