fix: use local date methods for Pomodoro session bucketing in getStatsForDate#1758
Open
ITblacksheep wants to merge 2 commits intocallumalpass:mainfrom
Open
fix: use local date methods for Pomodoro session bucketing in getStatsForDate#1758ITblacksheep wants to merge 2 commits intocallumalpass:mainfrom
ITblacksheep wants to merge 2 commits intocallumalpass:mainfrom
Conversation
added 2 commits
April 3, 2026 11:16
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
Fixes #1658 — Pomodoro stats view incorrectly counts evening sessions as belonging to the next day.
Root Cause
Sessions are stored by getCurrentTimestamp() with the local timezone offset (e.g. "2026-04-02T21:09:25.755-04:00"). When getStatsForDate calls formatDateForStorage(new Date(session.startTime)), it uses getUTCDate() internally which converts the Eastern session to UTC next day:
"2026-04-02T21:09:25.755-04:00"
→ new Date() → 2026-04-03T01:09:25.755Z internally
→ getUTCDate() → 3
→ formatDateForStorage returns "2026-04-03"
A session at 9pm Eastern on April 2nd gets filed under April 3rd, inflating today's count.
Fix
In getStatsForDate, replace formatDateForStorage with local date methods which correctly resolve the stored timezone offset:
typescript// Before
const sessionDate = formatDateForStorage(new Date(session.startTime));
// After
const d = new Date(session.startTime);
const sessionDate =
${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')};Also updated getTodayStats to pass getTodayLocal() directly without converting to a UTC anchor first.
This approach is also travel-safe — JavaScript resolves local date methods using the stored timezone offset (-04:00), not the current system timezone. So a session created in Eastern time always reads as its Eastern date regardless of where you are when you read it.
Verification
Confirmed with real pomodoroHistory data — before fix:
Buggy count (UTC): 5 completed sessions today
Fixed count (local): 3 completed sessions today
2 sessions from 2026-04-02T21:xx-04:00 were incorrectly counted as April 3rd.
Verified in Obsidian console:
javascriptconst stats = await plugin.pomodoroService.getTodayStats();
// { pomodorosCompleted: 6, totalMinutes: 150, completionRate: 100 }
Tests
Added regression tests in tests/timezone-bugs/pomodoro-session-bucketing.test.ts following the existing timezone bug documentation pattern. Tests cover:
Evening sessions correctly bucketed to local date
Morning sessions unaffected
Real-world data reproducing the exact bug
Travel-safe behavior across multiple timezones
Pre-existing Failing Test
tests/unit/modals/TaskCreationModal.test.ts — should apply task creation defaults — was already failing before this PR. It exhibits the same UTC/local date mismatch pattern (new Date('2025-01-15') creates UTC midnight which shifts in non-UTC timezones). Flagging for a follow-up issue but leaving out of scope for this PR to keep the fix focused.