Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| const activityDate = new Date(activity.date); | ||
| const dateString = activityDate.toISOString().split('T')[0]; // YYYY-MM-DD format | ||
| uniqueDays.add(dateString); |
There was a problem hiding this comment.
Potential bug: The streak API converts activity dates to UTC using toISOString(), which is inconsistent with other APIs that use local time, potentially causing incorrect streak calculations.
-
Description: The new streak API at
/api/streak/route.tsconverts activity dates to a UTC date string usingactivityDate.toISOString().split('T')[0]. This is inconsistent with the established pattern in other endpoints, such as/api/activities/route.ts, which parse dates into local time. This discrepancy can lead to incorrect streak calculations. For example, an activity logged by a user in a timezone with a significant UTC offset late on a Sunday night could be converted to Monday in UTC, causing it to be excluded from the current week's streak calculation and misaligning the user's activity log. -
Suggested fix: Adopt the established date parsing logic from other API routes. Instead of converting to UTC with
toISOString(), ensure the date from the database is treated as local time, similar to the logic in/api/activities/route.tsand/api/meals/route.ts, to ensure consistent date handling across the application.
severity: 0.75, confidence: 0.95
Did we get this right? 👍 / 👎 to inform future reviews.
Lets users see a streak that they're on when they've done activities for 4 or more days in a week.