fix: normalize dates to UTC midnight for timezone-independent comparisons#50
Merged
fix: normalize dates to UTC midnight for timezone-independent comparisons#50
Conversation
There was a problem hiding this comment.
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.
Collaborator
|
👍🏻 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
parseDueDateToDaywas 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.000Zinstead of2026-01-29T00:00:00.000Z).isDueOnDateandisDueBeforecompared local midnight vs local midnight (viaparseISO), so the offsets cancelled out and comparisons were always correct. The entire flow (today, upcoming) worked correctly — just by accident..toISOString()returnsT00:00:00and the tests pass. At UTC-3 (or any negative offset), local midnight shifts forward in UTC, causing the 4 test assertions to fail.Date.UTC()and usesparseDueDateToDayon both sides of comparisons, making the correctness explicit and timezone-independent.Manually verified
td todayandtd upcomingproduce correct output after the fix.Test plan
npx vitest run src/__tests__/dates.test.ts— all 41 tests pass (including the 4 previously failing)td today— correctly shows overdue and today sectionstd upcoming 3— correctly shows overdue, tomorrow, and future date headers