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:
+13
-2
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user