Skip to content

fix : added correct yesterday calculation in calculateStreak#2468

Open
tmdeveloper007 wants to merge 1 commit into
Umbrella-io:mainfrom
tmdeveloper007:#2463
Open

fix : added correct yesterday calculation in calculateStreak#2468
tmdeveloper007 wants to merge 1 commit into
Umbrella-io:mainfrom
tmdeveloper007:#2463

Conversation

@tmdeveloper007

Copy link
Copy Markdown
Contributor

Closes #2463.

Summary of What Has Been Done:
Fixed a silent bug in calculateStreak (src/lib/dates/streakDateUtils.ts) where the local variable yesterday was assigned the result of getLocalDateString(userTimezone) without offsetting by one day — so the grace-period check uniqueDates[0] !== today && uniqueDates[0] !== yesterday always passed the yesterday branch 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 broken const yesterday = getLocalDateString(userTimezone) with a calculation that parses today, subtracts one calendar day in UTC, and re-formats the result as YYYY-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.
  • New file: test/streak-date-utils.test.ts (19 tests, all passing under npm test).
  • Coverage:
    • getLocalDateString: UTC, a fixed-offset timezone (Asia/Kolkata), and the invalid-timezone fallback all return a YYYY-MM-DD string.
    • utcToLocalDate: a UTC ISO timestamp is converted to the right date in Asia/Kolkata (UTC+5:30) and UTC; a Date object 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:
      • empty input → 0
      • single date equal to today → 1
      • single date equal to yesterday → 1 (regression case: the previous code returned 0)
      • single date older than yesterday → 0
      • sorted-most-recent-first array of 5 consecutive dates ending today → 5
      • a 1-day gap in the middle breaks the streak at the gap
      • repeated dates are de-duplicated
      • input order does not matter
  • All other functions and call sites in the codebase are untouched.

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.

@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:testing GSSoC type bonus: tests (+10 pts) type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts) labels Jun 15, 2026
@github-actions

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Umbrella-io — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts) type:testing GSSoC type bonus: tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix : repair yesterday calculation in calculateStreak

1 participant