fix: bucket the badge streak by local day instead of UTC#905
Open
Anexus5919 wants to merge 1 commit into
Open
Conversation
|
@Anexus5919 is attempting to deploy a commit to the somiljain2024-4175's projects Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Author
|
@Somil450 @diksha78dev Kindly have a review on this pr. Thanks! |
calculateStreak in useBadges bucketed each workout by its UTC date (toISOString().slice(0, 10)) and computed today/yesterday in UTC. For users not at UTC, workouts on the same local day could land in different UTC buckets and consecutive local days could collapse into one, miscounting the badge streak near the local/UTC day boundary. Bucket each workout by its local calendar date instead. calculateStreak is exported so the behavior can be unit tested.
761e838 to
0885c6b
Compare
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.
📌 Related Issue
Fixes #868
📝 Description
calculateStreakinuseBadges.tsbucketed each workout by its UTC date (toISOString().slice(0, 10)) and computed today/yesterday in UTC. For users not at UTC, workouts on the same local day can land in different UTC buckets and consecutive local days can collapse into one, miscounting the badge streak near the local/UTC day boundary.🔹 What has been changed?
src/hooks/useBadges.ts: bucket each workout, and today/yesterday, by its local calendar date (${getFullYear()}-${getMonth()+1}-${getDate()}) instead of the UTC date.calculateStreakis now exported so the pure logic can be unit tested.src/hooks/__tests__/useBadges.test.ts: adds tests, including the regression case of two workouts on consecutive local days that fall on the same UTC date.🔹 Why are these changes needed?
🛠️ Type of Change
🧪 Testing
✅ Tests Performed
npx vitest run src/hooks/__tests__/useBadges.test.ts-> 3 tests pass.npx tsc --noEmit:useBadges.tsclean;npx eslint: 0 problems.🌐 Browsers Tested
Not applicable (streak-count logic; verified via unit tests).
📷 Screenshots / Demo (if applicable)
Not applicable.
📋 Checklist
💬 Additional Notes
Branched from latest
upstream/main(5464425). This is the badge streak inuseBadges.ts, separate from the workout streak instreakUtils.ts(#867).