Show the age counter as weeks with a months breakdown

Weeks and calendar months disagreed at a glance ("16 weeks" but only
"3 months"). Now the counter reads "16 weeks (3 months and 3 weeks)
old" so the two units line up, and drops the weeks past 4 months to
show just the months form.
This commit is contained in:
Alexander Heldt
2026-07-24 15:17:09 +00:00
parent 22a5ea76aa
commit 374e630d8f
2 changed files with 14 additions and 2 deletions
+13 -2
View File
@@ -245,16 +245,27 @@
(ref.getMonth() - birth.getMonth());
if (ref.getDate() < birth.getDate()) months--;
if (months < 0) months = 0;
return { days, weeks, months };
// Whole weeks left over after the calendar months (so "N months and M weeks").
const anchor = startOfDay(new Date(birth.getFullYear(),
birth.getMonth() + months, birth.getDate()));
const remWeeks = Math.floor((ref - anchor) / 86_400_000 / 7);
return { days, weeks, months, remWeeks };
}
// e.g. "16 weeks (3 months and 3 weeks) old". Weeks are the headline unit while
// the puppy is young; once it's 4+ months the week count is just noise, so we
// drop it and lead with the months form ("4 months and 1 week old").
function formatAge(birthday, at) {
const a = ageParts(birthday, at);
if (!a) return "";
const wk = `${a.weeks} week${a.weeks === 1 ? "" : "s"}`;
if (a.months < 1) return `${wk} old`;
const mo = `${a.months} month${a.months === 1 ? "" : "s"}`;
return `${wk} · ${mo} old`;
const rw = a.remWeeks > 0
? ` and ${a.remWeeks} week${a.remWeeks === 1 ? "" : "s"}` : "";
const monthPhrase = `${mo}${rw}`;
if (a.months >= 4) return `${monthPhrase} old`;
return `${wk} (${monthPhrase}) old`;
}
// Rough age-based daily sleep goal (hours), for the trend chart's goal band:
+1
View File
@@ -1,4 +1,5 @@
[
{ "date": "2026-07-24", "text": "The age counter reads \"16 weeks (3 months and 3 weeks) old\" so weeks and months line up; past 4 months it drops the weeks and shows just months (e.g. \"5 months and 2 weeks old\")" },
{ "date": "2026-07-17", "text": "The Sleep trend chart follows the selected day — pick a past day to see its full curve against the day before and the average leading up to it" },
{ "date": "2026-07-15", "text": "The Sleep trend y-axis is stretched above 10h, giving the hours around the sleep goal most of the chart" },
{ "date": "2026-07-15", "text": "The Sleep trend chart shows the sleep goal for your puppy's age as a shaded band — the projection chip gets a ✓ when today is on track" },