From 850afeba7c8d52f29cdace621779dce30d3404eb Mon Sep 17 00:00:00 2001 From: Tyler <3deathsaves@gmail.com> Date: Mon, 29 Jun 2026 15:56:53 -0600 Subject: [PATCH 1/2] Include dayOfWeek in calendar time components - Add dayOfWeek to CalendariaCalendar.timeToComponents output - Compute it via _computeDayOfWeek so it respects festival and intercalary day rules - Restores the core CalendarData component contract for external consumers --- scripts/data/calendaria-calendar.mjs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/data/calendaria-calendar.mjs b/scripts/data/calendaria-calendar.mjs index bd3c3816..3fd31c1d 100644 --- a/scripts/data/calendaria-calendar.mjs +++ b/scripts/data/calendaria-calendar.mjs @@ -168,7 +168,8 @@ export default class CalendariaCalendar extends foundry.data.CalendarData { dayOfMonth -= d; month++; } - return { year, month, dayOfMonth, hour, minute, second }; + const dayOfWeek = this._computeDayOfWeek({ year, month, dayOfMonth }); + return { year, month, dayOfMonth, dayOfWeek, hour, minute, second }; } /** @override */ From e13187fbae9355b33572235d747fec03ac81e6f3 Mon Sep 17 00:00:00 2001 From: Tyler <3deathsaves@gmail.com> Date: Mon, 29 Jun 2026 15:56:56 -0600 Subject: [PATCH 2/2] Add Item Piles merchant holiday integration - Answer the Item Piles getHolidays hook with Calendaria note categories - Answer getActiveHolidays with categories of notes occurring in the queried range - Register both hooks in the integration layer --- scripts/hooks.mjs | 14 +++++++++++++- scripts/integrations/_module.mjs | 1 + scripts/integrations/item-piles.mjs | 28 ++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 scripts/integrations/item-piles.mjs diff --git a/scripts/hooks.mjs b/scripts/hooks.mjs index d44313c6..0885d67d 100644 --- a/scripts/hooks.mjs +++ b/scripts/hooks.mjs @@ -3,7 +3,17 @@ import { BigCal, Chronicle, HUD, MiniCal, Stopwatch, SunDial, TimeKeeper } from import { CalendarManager } from './calendar/_module.mjs'; import { HOOKS, MODULE, SCENE_FLAGS, SETTINGS } from './constants.mjs'; import { FestivalManager } from './festivals/_module.mjs'; -import { onDayChangeForBastions, onLongRest, onPF1eRest, onPF2eRest, onPreRest, onShortRest, patchBastionButton } from './integrations/_module.mjs'; +import { + onDayChangeForBastions, + onItemPilesGetActiveHolidays, + onItemPilesGetHolidays, + onLongRest, + onPF1eRest, + onPF2eRest, + onPreRest, + onShortRest, + patchBastionButton +} from './integrations/_module.mjs'; import { NoteManager, clearComputedDateCache } from './notes/_module.mjs'; import { TimeClock, onMoonPhaseChange, onUpdateScene, onWeatherChange } from './time/_module.mjs'; import { @@ -67,6 +77,8 @@ export function registerHooks() { Hooks.on('dnd5e.preShortRest', onPreRest); Hooks.on('pf1ActorRest', onPF1eRest); Hooks.on('pf2e.restForTheNight', onPF2eRest); + Hooks.on('item-piles-getHolidays', onItemPilesGetHolidays); + Hooks.on('item-piles-getActiveHolidays', onItemPilesGetActiveHolidays); Hooks.on('getSceneControlButtons', onGetSceneControlButtons); Hooks.on('preCreateChatMessage', onPreCreateChatMessage); Hooks.on('preDeleteFolder', NoteManager.onPreDeleteFolder.bind(NoteManager)); diff --git a/scripts/integrations/_module.mjs b/scripts/integrations/_module.mjs index 8a27c651..0a03c755 100644 --- a/scripts/integrations/_module.mjs +++ b/scripts/integrations/_module.mjs @@ -1,5 +1,6 @@ export * from './bastion-orders.mjs'; export * from './chat-commander.mjs'; export * from './fxmaster.mjs'; +export * from './item-piles.mjs'; export * from './luxon-sync.mjs'; export * from './rest-time.mjs'; diff --git a/scripts/integrations/item-piles.mjs b/scripts/integrations/item-piles.mjs new file mode 100644 index 00000000..279f95c1 --- /dev/null +++ b/scripts/integrations/item-piles.mjs @@ -0,0 +1,28 @@ +import { getAllPresets, NoteManager } from '../notes/_module.mjs'; + +/** + * Offer Calendaria note categories as selectable Item Piles merchant holidays. + * @param {object[]} holidays - Holiday definitions ({ id, label }) the hook collects + * @returns {void} + */ +export function onItemPilesGetHolidays(holidays) { + for (const preset of getAllPresets()) { + holidays.push({ id: preset.id, label: preset.label }); + } +} + +/** + * Report note categories that occur within an Item Piles time range. The query's + * startDate/endDate are Foundry TimeComponents, whose 0-based month and dayOfMonth + * match Calendaria's internal note dates directly. + * @param {object} query - Item Piles query with { startDate, endDate } time components + * @param {Set} active - Active holiday ids the hook collects + * @returns {void} + */ +export function onItemPilesGetActiveHolidays(query, active) { + const start = { year: query.startDate.year, month: query.startDate.month, dayOfMonth: query.startDate.dayOfMonth }; + const end = { year: query.endDate.year, month: query.endDate.month, dayOfMonth: query.endDate.dayOfMonth }; + for (const note of NoteManager.getNotesInRange(start, end)) { + for (const category of note.flagData.categories ?? []) active.add(category); + } +}