Files
silverbullet-icalendar/conductor/tracks/rrule_generic_formatter_20260219/spec.md

1.9 KiB

Specification: Generic RRULE Object Formatter

Overview

The current implementation for converting RRULE objects (from ts-ics) back to strings is brittle and fails when encountering nested objects or arrays for properties like BYDAY. This results in [object Object] being injected into the RRULE string, causing syntax errors in the rrule library. This track replaces the specific property handling with a robust, recursive generic formatter.

Functional Requirements

  • Recursive Value Formatting: The formatRRuleValue function must handle nested structures:
    • Arrays: Join elements with commas (e.g., ['MO', 'TU'] -> MO,TU).
    • Date Objects: Format as YYYYMMDDTHHMMSSZ.
    • Nested Property Objects: If an object has a date, day, or value property, extract and format that value (e.g., { day: 'MO' } -> MO).
    • Recursion: If an array contains objects, or an object contains an array, the logic must recurse until primitives are reached.
  • iCalendar Compliance: Ensure the resulting string for every property matches the iCalendar spec format expected by rrule.js.

Implementation Steps

  1. Reproduce: Create a test case in icalendar_test.ts where BYDAY is an object or an array of objects. Verify it fails with Invalid weekday string: [object Object].
  2. Fix: Re-implement formatRRuleValue in icalendar.ts as a recursive function that handles Arrays, Dates, and standard ts-ics nested value objects.
  3. Verify:
    • Confirm the BYDAY reproduction test passes.
    • Add a composite test with UNTIL (Date) and BYDAY (Array) together.
    • Run regression tests to ensure standard string RRULEs still work.

Acceptance Criteria

  • expandRecurrences correctly handles BYDAY when provided as an array of objects.
  • expandRecurrences correctly handles UNTIL when provided as a nested date object.
  • All 12+ existing tests pass, including regression checks for string-based RRULEs.