Skip to content

Commit 266b5a7

Browse files
committed
test(calculate): add timezone midnight streak scenario
1 parent e9da96e commit 266b5a7

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
@@ -295,6 +295,35 @@ describe('calculateStreak — timezone awareness', () => {
295295
expect(result.currentStreak).toBe(0);
296296
});
297297

298+
it('handles commits around midnight correctly across timezone offsets', () => {
299+
const calendar = {
300+
totalContributions: 2,
301+
weeks: [
302+
{
303+
contributionDays: [
304+
{ contributionCount: 0, date: '2024-06-12' },
305+
{ contributionCount: 1, date: '2024-06-13' },
306+
{ contributionCount: 1, date: '2024-06-14' },
307+
{ contributionCount: 0, date: '2024-06-15' },
308+
],
309+
},
310+
],
311+
};
312+
313+
const nowUTC = new Date('2024-06-14T23:59:00.000Z');
314+
315+
const utcResult = calculateStreak(calendar, 'UTC', nowUTC);
316+
const aheadOffsetResult = calculateStreak(calendar, 'Etc/GMT-1', nowUTC);
317+
318+
expect(utcResult.todayDate).toBe('2024-06-14');
319+
expect(utcResult.currentStreak).toBe(2);
320+
expect(utcResult.longestStreak).toBe(2);
321+
322+
expect(aheadOffsetResult.todayDate).toBe('2024-06-15');
323+
expect(aheadOffsetResult.currentStreak).toBe(2);
324+
expect(aheadOffsetResult.longestStreak).toBe(2);
325+
});
326+
298327
it('preserves the streak when the local date (UTC-8) maps to a day with commits via grace period', () => {
299328
const result = calculateStreak(tzCalendar, 'Etc/GMT+8', nowUTC);
300329
expect(result.currentStreak).toBe(3);

0 commit comments

Comments
 (0)