feat: expand companion platform, device controls, and memoir workflows
ci / verify (push) Canceled after 0s
ci / verify (push) Canceled after 0s
Add customer and operator login, BLE provisioning, device fleet controls, call memory, memoir generation, and refreshed family and maintenance portals. Include API contracts, migrations, firmware sources, tests, assets, and deployment documentation.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { BEIJING_TIMEZONE, formatBeijingDateTime, beijingDateKey, beijingDateTimeInput, parseBeijingDateTimeInput, beijingDateBoundary, beijingDayStart, beijingWeekStart, beijingCalendarRange } from "../src/lib/beijing-time.ts";
|
||||
|
||||
test("Beijing display, date grouping and form round-trip ignore the browser timezone", () => {
|
||||
const previous = process.env.TZ;
|
||||
try {
|
||||
for (const zone of ["Etc/UTC", "America/Los_Angeles", "America/New_York", "Asia/Tokyo"]) {
|
||||
process.env.TZ = zone;
|
||||
const at = new Date("2026-10-05T12:16:08Z");
|
||||
assert.equal(BEIJING_TIMEZONE, "Asia/Shanghai");
|
||||
assert.match(formatBeijingDateTime(at), /20:16:08/);
|
||||
assert.equal(formatBeijingDateTime(at, { hour: "2-digit", minute: "2-digit", timeZone: zone }), "20:16");
|
||||
assert.equal(beijingDateKey("2026-10-04T16:30:00Z"), "2026-10-05");
|
||||
assert.equal(beijingDateTimeInput(at), "2026-10-05T20:16");
|
||||
assert.equal(parseBeijingDateTimeInput("2026-10-05T20:16"), "2026-10-05T12:16:00.000Z");
|
||||
assert.equal(parseBeijingDateTimeInput("2026-10-05T20:16:08.123"), "2026-10-05T12:16:08.123Z");
|
||||
assert.equal(beijingDayStart(at).toISOString(), "2026-10-04T16:00:00.000Z");
|
||||
assert.equal(beijingDateBoundary("2026-10-05", 1).toISOString(), "2026-10-05T16:00:00.000Z");
|
||||
assert.deepEqual(beijingCalendarRange(30, new Date("2026-10-05T16:30:00Z")), {
|
||||
from: "2026-09-06T16:00:00.000Z", to: "2026-10-05T16:30:00.000Z", timezone: "Asia/Shanghai",
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
if (previous === undefined) delete process.env.TZ; else process.env.TZ = previous;
|
||||
}
|
||||
});
|
||||
|
||||
test("Monday Beijing midnight resets the week, Tuesday midnight does not", () => {
|
||||
assert.equal(beijingWeekStart(new Date("2026-10-04T15:59:59Z")).toISOString(), "2026-09-27T16:00:00.000Z");
|
||||
assert.equal(beijingWeekStart(new Date("2026-10-04T16:00:00Z")).toISOString(), "2026-10-04T16:00:00.000Z");
|
||||
assert.equal(beijingWeekStart(new Date("2026-10-05T16:00:00Z")).toISOString(), "2026-10-04T16:00:00.000Z");
|
||||
assert.equal(beijingDateBoundary("2025-12-31", 1).toISOString(), "2025-12-31T16:00:00.000Z");
|
||||
assert.equal(beijingDateBoundary("2028-02-28", 1).toISOString(), "2028-02-28T16:00:00.000Z");
|
||||
});
|
||||
|
||||
test("invalid dates do not become a shifted date or an invented valid time", () => {
|
||||
for (const value of [null, undefined, "", "not-a-date"]) {
|
||||
assert.equal(formatBeijingDateTime(value), "—");
|
||||
assert.equal(beijingDateKey(value), "");
|
||||
assert.equal(beijingDateTimeInput(value), "");
|
||||
}
|
||||
for (const value of ["2026-02-29T10:00", "2026-10-05T24:00", "2026-10-05T20:99", "2026-10-05T20:16:60", "2026-10-05", "2026-10-05T20:16Z"]) {
|
||||
assert.throws(() => parseBeijingDateTimeInput(value), RangeError);
|
||||
}
|
||||
assert.throws(() => beijingDateBoundary("2026-02-30"), RangeError);
|
||||
assert.throws(() => beijingCalendarRange(0), RangeError);
|
||||
});
|
||||
Reference in New Issue
Block a user