Skip to content

DateUtils.differenceInDays uses DST-unsafe millisecond arithmetic #65

@thedhanawada

Description

@thedhanawada

Bug Description

DateUtils.differenceInDays() (line 258-261 in core/calendar/DateUtils.js) uses millisecond arithmetic:

static differenceInDays(date1, date2) {
    const diff = date1.getTime() - date2.getTime();
    return Math.floor(diff / (1000 * 60 * 60 * 24));
}

This is inconsistent with the rest of the file, which deliberately uses setDate() for date arithmetic to handle DST transitions correctly (see comments on lines 40-41, 56-57, 106-107, 413-414).

Problem

When a DST transition occurs between date1 and date2, the number of milliseconds in a day is 23 or 25 hours instead of 24. This causes differenceInDays to return incorrect results. For example, crossing a "spring forward" boundary could report 0 days difference for dates that are actually 1 day apart.

Expected Fix

Use date-based arithmetic that's immune to DST, similar to the pattern used elsewhere in the file. For example, compare normalized dates (midnight-to-midnight) using setHours(0,0,0,0) before computing the difference.

Files

  • core/calendar/DateUtils.js:258-261
  • Also affects differenceInWeeks() which delegates to differenceInDays()

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