mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 13:01:00 +00:00
fix(glp1): file timeline side effects under the mood entry's own day
The timeline grouped side effects by the UTC day of moodLoggedAt, so an evening entry west of UTC (or a morning one east of it) showed on the neighbouring day. The entry's stored date is already the writer's local day; group by that.
This commit is contained in:
1 parent
838629276c
commit
67d88de3d5
2 files changed
+20
-2
No files matched your search
@@ -54,6 +54,7 @@ function medication() {
|
||||
|
||||
function moodDay(day: number, tags: string[]) {
|
||||
return {
|
||||
date: `2026-04-${String(day).padStart(2, "0")}`,
|
||||
moodLoggedAt: new Date(Date.UTC(2026, 3, day, 9, 0, 0)),
|
||||
tags: JSON.stringify(tags),
|
||||
};
|
||||
@@ -99,6 +100,20 @@ describe("GET /api/insights/glp1-timeline side-effect days", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("files a side effect under the entry's own day, not its UTC day", async () => {
|
||||
// Logged 2026-04-10 at 20:00 in Los Angeles: already the 11th in UTC.
|
||||
const out = await timeline([
|
||||
{
|
||||
date: "2026-04-10",
|
||||
moodLoggedAt: new Date("2026-04-11T03:00:00.000Z"),
|
||||
tags: JSON.stringify(["nausea"]),
|
||||
},
|
||||
]);
|
||||
expect(out.entries).toEqual([
|
||||
{ date: "2026-04-10T12:00:00Z", kind: "side-effect", tags: ["nausea"] },
|
||||
]);
|
||||
});
|
||||
|
||||
it("recognises the chip label of every shipped locale", async () => {
|
||||
const out = await timeline([
|
||||
moodDay(10, ["Übelkeit"]),
|
||||
|
||||
@@ -80,7 +80,7 @@ export const GET = apiHandler(async (request: NextRequest) => {
|
||||
deletedAt: null,
|
||||
moodLoggedAt: { gte: ninetyDaysAgo },
|
||||
},
|
||||
select: { moodLoggedAt: true, tags: true },
|
||||
select: { date: true, tags: true },
|
||||
orderBy: { moodLoggedAt: "desc" },
|
||||
});
|
||||
|
||||
@@ -140,7 +140,10 @@ export const GET = apiHandler(async (request: NextRequest) => {
|
||||
const { matched, unresolvedCount } = matchGlp1SideEffectTags(mood.tags);
|
||||
unresolvedTagCount += unresolvedCount;
|
||||
if (matched.length === 0) continue;
|
||||
const dayKey = mood.moodLoggedAt.toISOString().slice(0, 10);
|
||||
// `date` is the day the entry belongs to in the writer's zone. The UTC
|
||||
// day of `moodLoggedAt` moved an evening entry west of UTC (a morning
|
||||
// one east of it) onto the neighbouring day.
|
||||
const dayKey = mood.date;
|
||||
const existing = sideEffectByDay.get(dayKey) ?? [];
|
||||
for (const t of matched) {
|
||||
if (!existing.includes(t)) existing.push(t);
|
||||
|
||||
Reference in new issue
Block a user