Skip to content

Commit 3159f13

Browse files
weekend day streak
1 parent e85dcd5 commit 3159f13

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

lib/calculate.test.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,79 @@ describe('calculateStreak', () => {
737737
expect(result.longestStreak).toBe(1);
738738
expect(result.totalContributions).toBe(1);
739739
});
740+
741+
it('simulates a timeline with commits exclusively on Saturdays and Sundays and verifies streak metrics', () => {
742+
// 2024-01-01 is a Monday.
743+
// Index: 0 (Mon), 1 (Tue), 2 (Wed), 3 (Thu), 4 (Fri), 5 (Sat), 6 (Sun)
744+
// Custom calendar with commits ONLY on Sat and Sun:
745+
// Week 1: 0, 0, 0, 0, 0, 1, 1 (Sat Jan 6, Sun Jan 7)
746+
// Week 2: 0, 0, 0, 0, 0, 1, 1 (Sat Jan 13, Sun Jan 14)
747+
// Week 3: 0, 0, 0, 0, 0, 1, 1 (Sat Jan 20, Sun Jan 21)
748+
const calendar = buildCalendar([
749+
0,
750+
0,
751+
0,
752+
0,
753+
0,
754+
1,
755+
1, // Week 1 (Jan 1 to Jan 7)
756+
0,
757+
0,
758+
0,
759+
0,
760+
0,
761+
1,
762+
1, // Week 2 (Jan 8 to Jan 14)
763+
0,
764+
0,
765+
0,
766+
0,
767+
0,
768+
1,
769+
1, // Week 3 (Jan 15 to Jan 21)
770+
]);
771+
772+
// Scenario A: Evaluate on Sunday, Jan 21, 2024.
773+
// Sunday has a commit, so current streak is 2 (Sat Jan 20 & Sun Jan 21).
774+
// Longest streak is 2.
775+
const resultSunday = calculateStreak(calendar, 'UTC', new Date('2024-01-21T12:00:00Z'));
776+
expect(resultSunday.currentStreak).toBe(2);
777+
expect(resultSunday.longestStreak).toBe(2);
778+
expect(resultSunday.totalContributions).toBe(6);
779+
780+
// Scenario B: Evaluate on Monday, Jan 22, 2024 (using extended calendar).
781+
// We add Monday (index 21) with 0 commits.
782+
const extendedCalendar = buildCalendar([
783+
0,
784+
0,
785+
0,
786+
0,
787+
0,
788+
1,
789+
1,
790+
0,
791+
0,
792+
0,
793+
0,
794+
0,
795+
1,
796+
1,
797+
0,
798+
0,
799+
0,
800+
0,
801+
0,
802+
1,
803+
1,
804+
0, // Monday, Jan 22 (0 commits)
805+
]);
806+
// Today (Monday) has 0 commits, yesterday (Sunday) has 1 commit.
807+
// Under a grace period of 1, the streak is kept alive.
808+
// Current streak should be 2. Longest streak is 2.
809+
const resultMonday = calculateStreak(extendedCalendar, 'UTC', new Date('2024-01-22T12:00:00Z'));
810+
expect(resultMonday.currentStreak).toBe(2);
811+
expect(resultMonday.longestStreak).toBe(2);
812+
});
740813
});
741814

742815
describe('calculateStreak — timezone awareness', () => {

0 commit comments

Comments
 (0)