Skip to content

Commit eb1bedc

Browse files
authored
test(calculate): verify streak formulas for timezone shifts around midnight timeline (JhaSourav07#2016)
## Description Fixes JhaSourav07#1470 Adds a dedicated test covering streak calculations around midnight timezone transitions. This test simulates contributions occurring at 23:59 and 00:01 UTC and verifies that current streak and longest streak calculations remain accurate across the date boundary. ### Changes Made - Added a dedicated test for streak calculations around midnight boundaries - Simulated contributions occurring at 23:59 and 00:01 UTC - Verified current streak calculations before and after the date transition - Verified longest streak calculations remain accurate across the boundary - Added assertions for timezone-aware date resolution ## Pillar Testing ## Checklist - [x] Added/updated tests - [x] npm run lint passes - [x] npm run typecheck passes - [x] npm run test passes - [x] Verified streak calculations across 23:59 → 00:01 midnight transitions ### Result - Protects against off-by-one streak errors around date boundaries - Ensures timezone-aware streak calculations remain accurate - Adds regression coverage for midnight transition edge cases
2 parents 3da5347 + e9fdd0c commit eb1bedc

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

lib/calculate.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,41 @@ describe('calculateStreak — timezone awareness', () => {
892892
],
893893
};
894894

895+
it('verifies streak formulas for timezone shifts around midnight timeline', () => {
896+
const calendar = {
897+
totalContributions: 2,
898+
weeks: [
899+
{
900+
contributionDays: [
901+
{ contributionCount: 1, date: '2024-06-14' },
902+
{ contributionCount: 1, date: '2024-06-15' },
903+
],
904+
},
905+
],
906+
};
907+
908+
// Commit timeline:
909+
// 2024-06-14 23:59 UTC
910+
const beforeMidnight = new Date('2024-06-14T23:59:00.000Z');
911+
912+
// 2 minutes later
913+
// 2024-06-15 00:01 UTC
914+
const afterMidnight = new Date('2024-06-15T00:01:00.000Z');
915+
916+
const resultBefore = calculateStreak(calendar, 'UTC', beforeMidnight);
917+
918+
const resultAfter = calculateStreak(calendar, 'UTC', afterMidnight);
919+
920+
expect(resultBefore.currentStreak).toBe(1);
921+
expect(resultAfter.currentStreak).toBe(2);
922+
923+
expect(resultBefore.longestStreak).toBe(2);
924+
expect(resultAfter.longestStreak).toBe(2);
925+
926+
expect(resultBefore.todayDate).toBe('2024-06-14');
927+
expect(resultAfter.todayDate).toBe('2024-06-15');
928+
});
929+
895930
const nowUTC = new Date('2024-06-16T07:00:00.000Z');
896931

897932
it('breaks the streak when evaluated in UTC because today and yesterday both have 0 commits', () => {

0 commit comments

Comments
 (0)