Record planting day and show harvest dates

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-10-06 10:07:21 +01:00
parent 07057e6c3d
commit 83a9cb6dcc
11 changed files with 282 additions and 44 deletions

View file

@ -2,10 +2,29 @@
const api = factory();
if (typeof module === "object" && module.exports) module.exports = api;
if (root) root.ValleyCalendar = api;
})(typeof window === "undefined" ? globalThis : window, () => ({
birthdayOn(birthdays, season, day, year) {
const entry = birthdays?.[season]?.[day];
if (!entry || (entry[1] && entry[1] !== year)) return null;
return entry[0];
}
}));
})(typeof window === "undefined" ? globalThis : window, () => {
const seasons = ["spring", "summer", "fall", "winter"];
// Days since Spring 1, Year 1 (which is day 1).
const dayNumber = ({ year, season, day }) => (year - 1) * 112 + seasons.indexOf(season) * 28 + day;
const fromDayNumber = number => {
const offset = number - 1;
return { year: Math.floor(offset / 112) + 1, season: seasons[Math.floor(offset % 112 / 28)], day: offset % 28 + 1 };
};
return {
birthdayOn(birthdays, season, day, year) {
const entry = birthdays?.[season]?.[day];
if (!entry || (entry[1] && entry[1] !== year)) return null;
return entry[0];
},
// Crops are harvestable `growDays` after planting when watered daily.
harvestDate(planted, growDays) {
return fromDayNumber(dayNumber(planted) + growDays);
},
daysBetween(from, to) {
return dayNumber(to) - dayNumber(from);
}
};
});