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

    Class OnCallPeriod

    Represents a continuous on-call period with automatic OOH (Out of Hours) calculation.

    This class encapsulates the business logic for determining whether on-call shifts qualify as "out of hours" work and categorizing them into weekdays vs. weekends. It uses timezone-aware date handling to ensure accurate calculations across different geographical locations.

    A shift qualifies as OOH (Out of Hours) if it meets ALL of the following:

    1. Spans Days: Start and end are on different calendar days
    2. After Work Hours: Extends past 17:30 (end of work day)
    3. Minimum Duration: Lasts at least 6 hours
    • Weekdays (Mon-Thu): Compensated at £50 per OOH day
    • Weekends (Fri-Sun): Compensated at £75 per OOH day

    Note: Friday is considered a weekend day for compensation purposes.

    All date calculations respect the provided timezone to ensure accurate determination of "end of work day" and day boundaries. This is critical for distributed teams across multiple timezones.

    // Create a period for Thursday 5pm to Monday 9am (UK time)
    const period = new OnCallPeriod(
    new Date('2024-08-01T17:30:00+01:00'),
    new Date('2024-08-05T09:00:00+01:00'),
    'Europe/London'
    );

    console.log(period.numberOfOohWeekDays); // 1 (Thursday)
    console.log(period.numberOfOohWeekends); // 3 (Friday, Saturday, Sunday)
    // Monday is excluded as shift ends at 09:00 (before 17:30)
    Index

    Constructors

    • Creates a new OnCallPeriod and automatically calculates OOH days.

      The constructor immediately analyzes the period to determine which days qualify as out-of-hours work, categorizing them into weekdays and weekends.

      Parameters

      • s: Date

        Start date/time of the on-call period

      • u: Date

        End date/time of the on-call period

      • timeZone: string = 'UTC'

        IANA timezone identifier (defaults to 'UTC')

      Returns OnCallPeriod

      const period = new OnCallPeriod(
      new Date('2024-08-01T17:00:00Z'),
      new Date('2024-08-04T09:00:00Z'),
      'Europe/London'
      );

    Properties

    since: Date

    Start date/time of the on-call period

    timeZone: string

    IANA timezone identifier (e.g., 'Europe/London', 'America/New_York')

    until: Date

    End date/time of the on-call period

    Accessors

    • get numberOfOohWeekDays(): number

      Gets the number of OOH weekdays (Monday-Thursday) in this period.

      Returns number

      Count of OOH weekdays

    • get numberOfOohWeekends(): number

      Gets the number of OOH weekend days (Friday-Sunday) in this period.

      Returns number

      Count of OOH weekend days

    Methods

    • Returns a human-readable string representation of this on-call period.

      Includes the date range, timezone, and breakdown of OOH days by category.

      Returns string

      Formatted multi-line string describing the period

      console.log(period.toString());
      // Output:
      // On call period from Thu Aug 01 2024 17:30:00 to Mon Aug 05 2024 09:00:00 (Europe/London)
      // Number of OOH Weekdays (Mon-Thu): 1
      // Number of OOH Weekends (Fri-Sun): 3