Skip to content

Commit e9fdd0c

Browse files
committed
test(calculate): verify streak formulas for timezone shifts around midnight timeline
1 parent 1d04c74 commit e9fdd0c

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
@@ -403,6 +403,41 @@ describe('calculateStreak — timezone awareness', () => {
403403
],
404404
};
405405

406+
it('verifies streak formulas for timezone shifts around midnight timeline', () => {
407+
const calendar = {
408+
totalContributions: 2,
409+
weeks: [
410+
{
411+
contributionDays: [
412+
{ contributionCount: 1, date: '2024-06-14' },
413+
{ contributionCount: 1, date: '2024-06-15' },
414+
],
415+
},
416+
],
417+
};
418+
419+
// Commit timeline:
420+
// 2024-06-14 23:59 UTC
421+
const beforeMidnight = new Date('2024-06-14T23:59:00.000Z');
422+
423+
// 2 minutes later
424+
// 2024-06-15 00:01 UTC
425+
const afterMidnight = new Date('2024-06-15T00:01:00.000Z');
426+
427+
const resultBefore = calculateStreak(calendar, 'UTC', beforeMidnight);
428+
429+
const resultAfter = calculateStreak(calendar, 'UTC', afterMidnight);
430+
431+
expect(resultBefore.currentStreak).toBe(1);
432+
expect(resultAfter.currentStreak).toBe(2);
433+
434+
expect(resultBefore.longestStreak).toBe(2);
435+
expect(resultAfter.longestStreak).toBe(2);
436+
437+
expect(resultBefore.todayDate).toBe('2024-06-14');
438+
expect(resultAfter.todayDate).toBe('2024-06-15');
439+
});
440+
406441
const nowUTC = new Date('2024-06-16T07:00:00.000Z');
407442

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

0 commit comments

Comments
 (0)