forked from pkp/ui-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp/pkp-lib#10674 Improved edge case date scenarios to accurately cal…
…culate days
- Loading branch information
1 parent
0c51370
commit f517b8b
Showing
4 changed files
with
62 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {describe, test, expect} from 'vitest'; | ||
import {useDate} from './useDate'; | ||
|
||
describe('calculateDaysFromNow', () => { | ||
const {calculateDaysBetweenDates} = useDate(); | ||
test('today date should result in 0 days', () => { | ||
expect( | ||
calculateDaysBetweenDates('2025-02-20 08:10:27', '2025-02-20 11:00:00'), | ||
).toBe(0); | ||
|
||
expect( | ||
calculateDaysBetweenDates('2025-02-20 23:10:27', '2025-02-20 11:00:00'), | ||
).toBe(0); | ||
}); | ||
test('tomorrow should always result in 1 day', () => { | ||
expect( | ||
calculateDaysBetweenDates('2025-02-19 08:10:27', '2025-02-20 11:00:00'), | ||
).toBe(1); | ||
|
||
expect( | ||
calculateDaysBetweenDates('2025-02-19 23:10:27', '2025-02-20 11:00:00'), | ||
).toBe(1); | ||
}); | ||
|
||
test('yesterday should always result in -1 day', () => { | ||
expect( | ||
calculateDaysBetweenDates('2025-02-21 08:10:27', '2025-02-20 11:00:00'), | ||
).toBe(-1); | ||
|
||
expect( | ||
calculateDaysBetweenDates('2025-02-21 23:10:27', '2025-02-20 11:00:00'), | ||
).toBe(-1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters