mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 22:02:16 +00:00
The scan commit and the review screen looked for an existing reading in the UTC day of the scanned date. A hand-entered morning draw east of UTC sits on the previous UTC day, so scanning the same report wrote the reading a second time. Both checks now compare calendar days: a date-only reading's stated date, or the user's day of a hand-entered instant.
30 lines
1.4 KiB
TypeScript
30 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { labReadingDay, labReadingDaySearchRange } from "../reading-day";
|
|
|
|
describe("labReadingDay", () => {
|
|
it("reads a date-only reading as its stated date in every zone", () => {
|
|
const noon = new Date("2026-06-10T12:00:00.000Z");
|
|
const legacyMidnight = new Date("2026-06-10T00:00:00.000Z");
|
|
for (const tz of ["America/Los_Angeles", "Pacific/Kiritimati", "UTC"]) {
|
|
expect(labReadingDay(noon, tz)).toBe("2026-06-10");
|
|
expect(labReadingDay(legacyMidnight, tz)).toBe("2026-06-10");
|
|
}
|
|
});
|
|
|
|
it("reads a hand-entered instant on the user's own day", () => {
|
|
const draw = new Date("2026-06-09T23:00:00.000Z"); // 08:00 on the 10th in Tokyo
|
|
expect(labReadingDay(draw, "Asia/Tokyo")).toBe("2026-06-10");
|
|
expect(labReadingDay(draw, "America/Los_Angeles")).toBe("2026-06-09");
|
|
});
|
|
|
|
it("searches a range that holds the day's readings in any zone", () => {
|
|
const range = labReadingDaySearchRange("2026-06-10");
|
|
const kiritimatiMorning = new Date("2026-06-09T10:30:00.000Z"); // 00:30 on the 10th at UTC+14
|
|
const utcMinus12Late = new Date("2026-06-11T10:30:00.000Z"); // 22:30 on the 10th at UTC-12
|
|
expect(kiritimatiMorning >= range.gte && kiritimatiMorning < range.lt).toBe(
|
|
true,
|
|
);
|
|
expect(utcMinus12Late >= range.gte && utcMinus12Late < range.lt).toBe(true);
|
|
});
|
|
});
|