Skip to content

ConflictDetector._isWithinBusinessHours has broken hour comparison logic #70

@thedhanawada

Description

@thedhanawada

Bug Description

ConflictDetector._isWithinBusinessHours() (lines 507-516 in core/conflicts/ConflictDetector.js) has fundamentally broken logic:

_isWithinBusinessHours(start, end, options) {
    const startHour = start.getHours();
    const endHour = end.getHours();
    const businessStart = parseInt(options.businessHours.start.split(':')[0]);
    const businessEnd = parseInt(options.businessHours.end.split(':')[0]);
    return startHour >= businessStart && endHour <= businessEnd;
}

Problems:

  1. Ignores minutes: A gap starting at 8:45 AM with business hours 9:00-17:00 would pass (8 >= 9 is false, so it's rejected even though part of the gap is valid). Conversely, 9:59 is treated the same as 9:00.

  2. Doesn't handle multi-day spans: If start and end are on different days, the hour comparison is meaningless.

  3. endHour boundary: An event ending at exactly 17:00 has endHour = 17, so 17 <= 17 passes. But 17:01 has endHour = 17 too, which also passes — the minutes are lost.

  4. Weekend handling: The excludeWeekends option from getFreePeriods() is passed through but never checked here.

Impact

getFreePeriods() returns incorrect free time slots when businessHoursOnly: true is used, making the scheduling assistant unreliable.

Files

  • core/conflicts/ConflictDetector.js:507-516
  • Called from getFreePeriods() at lines 188-189 and 205

Metadata

Metadata

Assignees

No one assigned

    Labels

    phase:0-foundationImmediate fixes and test infrastructurepriority:highImportant for next milestonetype:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions