Skip to content

fix: normalize dates to UTC midnight for timezone-independent comparisons#50

Merged
gnapse merged 1 commit intomainfrom
ernesto/fix-date-parsing-tests
Feb 9, 2026
Merged

fix: normalize dates to UTC midnight for timezone-independent comparisons#50
gnapse merged 1 commit intomainfrom
ernesto/fix-date-parsing-tests

Conversation

@gnapse
Copy link
Collaborator

@gnapse gnapse commented Feb 9, 2026

Summary

  • parseDueDateToDay was returning dates at local midnight instead of UTC midnight. This caused 4 unit tests to fail because .toISOString() exposed the timezone offset (e.g. 2026-01-29T03:00:00.000Z instead of 2026-01-29T00:00:00.000Z).
  • The runtime behavior was never affected: isDueOnDate and isDueBefore compared local midnight vs local midnight (via parseISO), so the offsets cancelled out and comparisons were always correct. The entire flow (today, upcoming) worked correctly — just by accident.
  • The bug was introduced in fix: resolve td today missing tasks with specific times #30, authored from UTC+0. At UTC+0, local midnight is UTC midnight, so .toISOString() returns T00:00:00 and the tests pass. At UTC-3 (or any negative offset), local midnight shifts forward in UTC, causing the 4 test assertions to fail.
  • The fix normalizes to UTC midnight using Date.UTC() and uses parseDueDateToDay on both sides of comparisons, making the correctness explicit and timezone-independent.

Manually verified td today and td upcoming produce correct output after the fix.

Test plan

  • npx vitest run src/__tests__/dates.test.ts — all 41 tests pass (including the 4 previously failing)
  • Full test suite — all 668 tests pass (via pre-push hook)
  • td today — correctly shows overdue and today sections
  • td upcoming 3 — correctly shows overdue, tomorrow, and future date headers

@gnapse gnapse requested a review from scottlovegrove February 9, 2026 14:34
Copy link

@doist-bot doist-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request effectively addresses date parsing inconsistencies by normalizing all dates to UTC midnight, ensuring robust timezone-independent comparisons across the application. The changes, particularly in parseDueDateToDay, isDueOnDate, and isDueBefore, resolve previous test failures and contribute to the overall correctness of date handling, with all existing tests passing. No issues were flagged in the inline comments during the review.

@gnapse gnapse merged commit 4d29ef7 into main Feb 9, 2026
4 checks passed
@gnapse gnapse deleted the ernesto/fix-date-parsing-tests branch February 9, 2026 14:37
@scottlovegrove
Copy link
Collaborator

👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments