Skip to content

Onsite gap “week start” calculation is overly complex and likely incorrect in some locales #15

@edunzer

Description

@edunzer

The logic calculates dayOfWeek using toStartOfWeek().daysBetween(date) + 1 and then uses a custom daysToMonday formula. This is fragile and can miscompute the Monday start depending on Apex toStartOfWeek() behavior and org locale settings.

How to fix: Use the platform’s toStartOfWeek() directly for the week start:

  • onsiteGapWeekStart = input.onsiteStartDate.toStartOfWeek();
  • onsiteGapWeekEnd = onsiteGapWeekStart.addDays(6);
    This is simpler and avoids off-by-N errors.

File: ScheduleHoursDistributor.cls (onsite gap block in generateCategoryScheduleExceptions)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions