fix : added correct yesterday calculation in calculateStreak#2468
Open
tmdeveloper007 wants to merge 1 commit into
Open
fix : added correct yesterday calculation in calculateStreak#2468tmdeveloper007 wants to merge 1 commit into
tmdeveloper007 wants to merge 1 commit into
Conversation
GSSoC Label Checklist 🏷️@Umbrella-io — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
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.
Closes #2463.
Summary of What Has Been Done:
Fixed a silent bug in
calculateStreak(src/lib/dates/streakDateUtils.ts) where the local variableyesterdaywas assigned the result ofgetLocalDateString(userTimezone)without offsetting by one day — so the grace-period checkuniqueDates[0] !== today && uniqueDates[0] !== yesterdayalways passed theyesterdaybranch trivially (the two strings were identical). The practical effect was that any user whose most recent contribution was exactly the calendar day before today in their timezone would have their streak reported as 0. Added a deterministic vitest test file covering the entire module.Changes Made:
src/lib/dates/streakDateUtils.ts: replaced the brokenconst yesterday = getLocalDateString(userTimezone)with a calculation that parsestoday, subtracts one calendar day in UTC, and re-formats the result asYYYY-MM-DD. The shift is anchored on local midnight to avoid DST edge cases where subtracting 24h of UTC time can land on the same date.test/streak-date-utils.test.ts(19 tests, all passing undernpm test).getLocalDateString: UTC, a fixed-offset timezone (Asia/Kolkata), and the invalid-timezone fallback all return aYYYY-MM-DDstring.utcToLocalDate: a UTC ISO timestamp is converted to the right date inAsia/Kolkata(UTC+5:30) and UTC; aDateobject works; an invalid timezone falls back to the ISO date.areConsecutiveDays: adjacent dates return true (forward and reverse, including month and year boundaries), the same date returns false, and dates with a one-day gap return false.calculateStreak:Impact it Made:
Restores the documented one-day grace period for streaks. Eliminates a silent bug where users (especially non-UTC ones) saw their streak drop to zero at the end of the day in their own timezone. Adds unit coverage for the entire module so future changes cannot regress it silently.