> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Business Calendar Service - Integration

> Feature ID: PF-84 Status: ✅ Complete (Phase 1) Spec Reference: PF-84-business-calendar-service.md Last Updated: 2026-03-18

**Feature ID:** PF-84
**Status:** ✅ Complete (Phase 1)
**Spec Reference:** [PF-84-business-calendar-service.md](../../../specs/pf/specs/PF-84-business-calendar-service.md)
**Last Updated:** 2026-03-18

***

## Overview

PF-84 introduces a Platform Integration Layer wrapper at `@/platform/calendar` so any core can use business-day-aware calendar logic without direct FW imports. It also defines a shared Edge Function utility for server-side business day calculations, plus holiday template and CSV import support layered on top of FW-35 calendar tables.

***

## Integration Points (from Spec)

| Dependency                        | Type                               | Purpose                                                               |
| --------------------------------- | ---------------------------------- | --------------------------------------------------------------------- |
| PF-01 (Organizations)             | Platform                           | Organization context for tenant-scoped calendar access                |
| PF-02 (RBAC)                      | Platform                           | Permission checks for calendar and holiday management operations      |
| PF-10 (Notifications)             | Platform                           | Notification support when FW-16 deadlines fire                        |
| FW-35 (SLA & Deadline Management) | Core dependency via platform layer | Owns `fw_business_calendars` and `fw_calendar_holidays` source tables |
| FW-16 (Date-Relative Triggers)    | Core dependency via platform layer | Adds `use_business_days` and optional `calendar_id` behavior          |

***

## API / Edge Function Contracts

* **Client integration layer:** `@/platform/calendar` exports:
  * **Read hooks:** `useBusinessCalendars()`, `useBusinessCalendar(calendarId)`, `useDefaultCalendar()`, `useHolidays(calendarId, year?)`
  * **Utility hook:** `useBusinessDays(calendarId)` → returns `BusinessDayUtils` with `addBusinessDays`, `subtractBusinessDays`, `isBusinessDay`, `isHoliday`, `nextBusinessDay`
  * **Template hooks:** `useHolidayTemplates(year?)`, `useApplyHolidayTemplate(calendarId, orgId)`
  * **CSV import:** `useImportHolidaysFromCsv(calendarId, orgId)`, `parseHolidayCsv(csvText)`
  * **UI components:** `CalendarPicker`, `HolidayTemplateSelector`, `HolidayImportDialog`, `HolidayPreviewTable`
  * **Pure utilities:** `addBusinessDays`, `subtractBusinessDays`, `isBusinessDay`, `isHoliday`, `nextBusinessDay`, `createDefaultBusinessHours`
* **Server shared utility:** `supabase/functions/_shared/business-calendar.ts` provides:
  * `addBusinessDays(date, days, calendarId, supabaseClient)`
  * `subtractBusinessDays(date, days, calendarId, supabaseClient)`
  * `isBusinessDay(date, calendarId, supabaseClient)`
  * `isBusinessHour(timestamp, calendarId, supabaseClient)`
  * `nextBusinessDay(date, calendarId, supabaseClient)`
  * `getBusinessHoursBetween(start, end, calendarId, supabaseClient)`
  * `isHoliday(date, holidays)` (pure, no async)
* **Caching contract:** Edge utility uses in-memory cache with 5-minute TTL to reduce repeated reads of calendar/holiday data.
* **Permission keys:** `fw.business_calendars.view`, `fw.business_calendars.manage`, `fw.calendar_holidays.manage`

***

## Security and Tenant Isolation

* Reads and writes are organization-scoped via `organization_id`; no cross-tenant access.
* Existing FW-35 RLS policies remain authoritative for `fw_business_calendars` and `fw_calendar_holidays`.
* No PHI/PII is introduced by PF-84 data payloads (calendar config only).
* CSV import remains client-side parsed; validated rows only are sent to Supabase.

***

## Event Contracts

PF-84 does not introduce new events. Existing FW-triggered events continue to apply where relevant.

***

## Related Docs

* [PF-84 Spec](../../../specs/pf/specs/PF-84-business-calendar-service.md)
* [FW-35 Spec](../../../specs/fw/archive/FW-35-sla-deadline-management.md)
* [FW-16 Spec](../../../specs/fw/archive/FW-16-event-based-workflow-triggers.md)
* [CROSS\_CORE\_INTEGRATIONS.md](./CROSS_CORE_INTEGRATIONS.md)
