Skip to content

Commit

Permalink
feat: update daysDiff to return absolute value
Browse files Browse the repository at this point in the history
  • Loading branch information
altaywtf committed Oct 25, 2023
1 parent 6089527 commit 780c168
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/date/date.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ describe('date', () => {
expect(daysDiff('2020-02-05T16:13:28')).toBe(0);
expect(daysDiff('2020-02-04T06:51:43')).toBe(1);
});

it('returns absolute value', () => {
expect(daysDiff('2020-02-06T16:13:28')).toBe(1);
});
});
});
2 changes: 1 addition & 1 deletion src/date/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const daysDiff = (
) => {
const day1 = dayjs(ensureUTC(date1)).startOf('day');
const day2 = dayjs(ensureUTC(date2)).startOf('day');
return day2.diff(day1, 'day');
return Math.abs(day2.diff(day1, 'day'));
};

export const getUnixTimestamp = (date: UTCTimestamp) => {
Expand Down

0 comments on commit 780c168

Please sign in to comment.