Skip to content

DateUtils.isDST() logic is inverted — returns true when NOT in DST #109

@thedhanawada

Description

@thedhanawada

Bug Description

DateUtils.isDST() at lines 493-501 returns true when the current offset equals the MAXIMUM of January/July offsets. In the Northern Hemisphere, the maximum offset is the standard (winter) offset, not DST. This means the function returns true during standard time and false during DST — exactly backwards.

Impact

  • All DST-aware date arithmetic that depends on this function produces wrong results
  • addHoursWithDST() (which calls this indirectly via offset comparison) may double-adjust
  • Timezone conversions near DST boundaries produce incorrect times
  • Affects both Northern and Southern hemisphere timezones (inverted for both)

Code Location

// DateUtils.js:493-501
static isDST(date, timeZone) {
  const jan = new Date(date.getFullYear(), 0, 1);
  const jul = new Date(date.getFullYear(), 6, 1);
  const janOffset = DateUtils.getTimezoneOffset(jan, timeZone);
  const julOffset = DateUtils.getTimezoneOffset(jul, timeZone);
  const currentOffset = DateUtils.getTimezoneOffset(date, timeZone);

  return Math.max(janOffset, julOffset) === currentOffset;  // INVERTED
}

Fix

DST offset is the MINIMUM (least positive / most negative), not maximum:

return Math.min(janOffset, julOffset) === currentOffset;

Or equivalently, DST is when the offset differs from the standard (max) offset:

return Math.max(janOffset, julOffset) \!== currentOffset;

Files

  • core/calendar/DateUtils.js:493-501

Metadata

Metadata

Assignees

No one assigned

    Labels

    phase:0-foundationImmediate fixes and test infrastructurepriority:criticalMust fix before any releasetype:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions