Skip to content

Commit 8080eff

Browse files
authored
test(calculate): verify streak formulas for timezone shifts around midnight timeline (JhaSourav07#1854)
## Description Fixes JhaSourav07#1500 Added a new test case in `lib/calculate.test.ts` to verify streak calculations when contribution activity occurs around midnight across different timezone offsets. The test simulates a scenario where the same UTC timestamp maps to different local dates depending on the configured timezone and verifies that: * `todayDate` is calculated correctly for each timezone. * Active streaks remain accurate across date boundaries. * Grace-period behavior works correctly when local midnight causes a day shift. * Longest streak calculations remain unaffected by timezone changes. ## Pillar * [ ] 🎨 Pillar 1 — New Theme Design * [ ] 📐 Pillar 2 — Geometric SVG Improvement * [x] 🕐 Pillar 3 — Timezone Logic Optimization * [ ] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview Not applicable — this PR only adds automated test coverage. ## Checklist before requesting a review: * [x] I have read the `CONTRIBUTING.md` file. * [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). * [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). * [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). * [ ] I have updated `README.md` if I added a new theme or URL parameter. * [x] I have started the repo. * [x] I have made sure that i have only one commit to merge in this PR. * [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). * [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 4e791aa + 266b5a7 commit 8080eff

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

lib/calculate.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,35 @@ describe('calculateStreak — timezone awareness', () => {
383383
expect(result.currentStreak).toBe(0);
384384
});
385385

386+
it('handles commits around midnight correctly across timezone offsets', () => {
387+
const calendar = {
388+
totalContributions: 2,
389+
weeks: [
390+
{
391+
contributionDays: [
392+
{ contributionCount: 0, date: '2024-06-12' },
393+
{ contributionCount: 1, date: '2024-06-13' },
394+
{ contributionCount: 1, date: '2024-06-14' },
395+
{ contributionCount: 0, date: '2024-06-15' },
396+
],
397+
},
398+
],
399+
};
400+
401+
const nowUTC = new Date('2024-06-14T23:59:00.000Z');
402+
403+
const utcResult = calculateStreak(calendar, 'UTC', nowUTC);
404+
const aheadOffsetResult = calculateStreak(calendar, 'Etc/GMT-1', nowUTC);
405+
406+
expect(utcResult.todayDate).toBe('2024-06-14');
407+
expect(utcResult.currentStreak).toBe(2);
408+
expect(utcResult.longestStreak).toBe(2);
409+
410+
expect(aheadOffsetResult.todayDate).toBe('2024-06-15');
411+
expect(aheadOffsetResult.currentStreak).toBe(2);
412+
expect(aheadOffsetResult.longestStreak).toBe(2);
413+
});
414+
386415
it('preserves the streak when the local date (UTC-8) maps to a day with commits via grace period', () => {
387416
const result = calculateStreak(tzCalendar, 'Etc/GMT+8', nowUTC);
388417
expect(result.currentStreak).toBe(3);

0 commit comments

Comments
 (0)