CalOohPay API Documentation - v2.1.0
    Preparing search index...

    Function extractOnCallUsersFromFinalSchedule

    • Extracts and consolidates on-call users from a PagerDuty final schedule.

      This function processes all schedule entries from a PagerDuty final schedule and creates a dictionary of OnCallUser objects, consolidating multiple time periods for the same user into a single OnCallUser with multiple OnCallPeriods.

      Parameters

      • finalSchedule: FinalSchedule

        The final schedule object from PagerDuty containing rendered schedule entries

      • timeZone: string

        The IANA timezone identifier to use for OOH calculations across all entries

      Returns Record<string, OnCallUser>

      A Record mapping user IDs to OnCallUser objects with their consolidated on-call periods

      Key behaviours:

      • Multiple schedule entries for the same user are consolidated into one OnCallUser
      • Each unique user ID becomes a key in the returned Record
      • If a user appears multiple times, their OnCallPeriods are accumulated
      • Empty schedule (no entries) returns an empty Record
      • All periods use the same timezone for consistency

      Algorithm:

      1. Initialize empty dictionary of users
      2. For each schedule entry:
        • Convert entry to OnCallUser with single period
        • If user already exists, add the new period to their existing periods
        • If user is new, add them to the dictionary
      3. Return consolidated dictionary
      const finalSchedule = {
      rendered_schedule_entries: [
      { start: new Date('2024-01-01T18:00:00Z'), end: new Date('2024-01-02T09:00:00Z'),
      user: { id: 'USER1', summary: 'John Doe' } },
      { start: new Date('2024-01-02T18:00:00Z'), end: new Date('2024-01-03T09:00:00Z'),
      user: { id: 'USER1', summary: 'John Doe' } },
      { start: new Date('2024-01-03T18:00:00Z'), end: new Date('2024-01-04T09:00:00Z'),
      user: { id: 'USER2', summary: 'Jane Smith' } }
      ]
      };
      const users = extractOnCallUsersFromFinalSchedule(finalSchedule, 'Europe/London');
      // Returns: { 'USER1': OnCallUser with 2 periods, 'USER2': OnCallUser with 1 period }