mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
fix(checkups): say "overdue since yesterday" instead of "overdue by 1 days"
The due phrase on the check-up card and the checkups page counted a check-up one day past its date as "Overdue by 1 days", and the same counted form read wrongly in German. One day over now has its own phrase in all seven languages. Both overdue phrases keep the warning colour through a shared `isOverdueDue` helper, so a surface no longer compares against a single key.
This commit is contained in:
1 parent
5fb5145d7a
commit
f5bab3258a
12 files changed
+60
-9
No files matched your search
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
import { describe, it, expect } from "vitest";
|
||||
|
||||
import { relativeDueKey } from "../due-day";
|
||||
import { isOverdueDue, relativeDueKey } from "../due-day";
|
||||
|
||||
/**
|
||||
* The profile zone under test. July is deliberate: no IANA zone shifts its
|
||||
@@ -84,11 +84,33 @@ describe("relativeDueKey", () => {
|
||||
).toEqual(TOMORROW);
|
||||
});
|
||||
|
||||
it("counts a checkup from yesterday as one day overdue, however recent", () => {
|
||||
// Forty-five minutes in the past. It was still yesterday's checkup.
|
||||
it("calls a checkup from yesterday overdue since yesterday, however recent", () => {
|
||||
// Forty-five minutes in the past. It was still yesterday's checkup. Its
|
||||
// own phrase, because "overdue by 1 days" is what the counted form reads
|
||||
// as on the one day an open check-up is most likely to be looked at.
|
||||
expect(
|
||||
relativeDueKey(zoned(FRIDAY, 23, 30), at(SATURDAY, 0, 15), ZONE),
|
||||
).toEqual({ key: "measurementReminders.overdueByDays", days: 1 });
|
||||
).toEqual({ key: "measurementReminders.overdueSinceYesterday", days: 1 });
|
||||
});
|
||||
|
||||
it("counts the days for a checkup overdue longer than that", () => {
|
||||
expect(relativeDueKey(zoned(FRIDAY, 9), at(FRIDAY + 2, 10), ZONE)).toEqual({
|
||||
key: "measurementReminders.overdueByDays",
|
||||
days: 2,
|
||||
});
|
||||
});
|
||||
|
||||
it("reads both overdue phrases as overdue, and nothing else", () => {
|
||||
const now = at(SATURDAY, 12);
|
||||
expect(isOverdueDue(relativeDueKey(zoned(FRIDAY, 9), now, ZONE))).toBe(
|
||||
true,
|
||||
);
|
||||
expect(isOverdueDue(relativeDueKey(zoned(FRIDAY - 3, 9), now, ZONE))).toBe(
|
||||
true,
|
||||
);
|
||||
expect(isOverdueDue(relativeDueKey(zoned(SATURDAY, 9), now, ZONE))).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it("counts whole calendar days for a checkup further out", () => {
|
||||
|
||||
@@ -86,6 +86,11 @@ export function relativeDueKey(
|
||||
if (Number.isNaN(due.getTime()))
|
||||
return { key: "measurementReminders.nextDue.none", days: 0 };
|
||||
const deltaDays = calendarDaysUntil(due, new Date(now), timeZone);
|
||||
// Its own phrase rather than the counted one: "overdue by 1 days" is what
|
||||
// the counted form reads as, on the one day an open check-up (which since
|
||||
// v1.39.2 stays due after its reminder) is most likely to be looked at.
|
||||
if (deltaDays === -1)
|
||||
return { key: "measurementReminders.overdueSinceYesterday", days: 1 };
|
||||
if (deltaDays < 0)
|
||||
return {
|
||||
key: "measurementReminders.overdueByDays",
|
||||
@@ -97,3 +102,15 @@ export function relativeDueKey(
|
||||
return { key: "measurementReminders.nextDue.tomorrow", days: 1 };
|
||||
return { key: "measurementReminders.nextDue.inDays", days: deltaDays };
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a phrase from {@link relativeDueKey} says "overdue". Two keys do —
|
||||
* "since yesterday" and the counted one — so a surface that colours an
|
||||
* overdue badge asks here rather than comparing against one of them.
|
||||
*/
|
||||
export function isOverdueDue(due: RelativeDue): boolean {
|
||||
return (
|
||||
due.key === "measurementReminders.overdueByDays" ||
|
||||
due.key === "measurementReminders.overdueSinceYesterday"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user