2026-10-05 19:54:15 +01:00
|
|
|
(function exposeCalendar(root, factory) {
|
|
|
|
|
const api = factory();
|
|
|
|
|
if (typeof module === "object" && module.exports) module.exports = api;
|
|
|
|
|
if (root) root.ValleyCalendar = api;
|
2026-10-06 10:07:21 +01:00
|
|
|
})(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);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
});
|