feat: daily notes (dev only) (#1894)
This commit is contained in:
31
packages/web/src/javascripts/Utils/DateUtils.spec.ts
Normal file
31
packages/web/src/javascripts/Utils/DateUtils.spec.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { addDays } from '@/Utils/DateUtils'
|
||||
import { numDaysBetweenDates } from './DateUtils'
|
||||
|
||||
describe('date utils', () => {
|
||||
describe('numDaysBetweenDates', () => {
|
||||
it('should return full days diff accurately', () => {
|
||||
const today = new Date()
|
||||
|
||||
expect(numDaysBetweenDates(today, addDays(today, 1))).toEqual(1)
|
||||
expect(numDaysBetweenDates(today, addDays(today, 2))).toEqual(2)
|
||||
expect(numDaysBetweenDates(today, addDays(today, 3))).toEqual(3)
|
||||
})
|
||||
|
||||
it('should return absolute value of difference', () => {
|
||||
const today = new Date()
|
||||
|
||||
expect(numDaysBetweenDates(today, addDays(today, 3))).toEqual(3)
|
||||
expect(numDaysBetweenDates(addDays(today, 3), today)).toEqual(3)
|
||||
})
|
||||
|
||||
it('should return 1 day difference between two dates on different days but 1 hour apart', () => {
|
||||
const today = new Date()
|
||||
const oneHourBeforeMidnight = new Date()
|
||||
oneHourBeforeMidnight.setHours(0, 0, 0, 0)
|
||||
oneHourBeforeMidnight.setHours(-1, 0, 0, 0)
|
||||
|
||||
expect(today.toDateString()).not.toEqual(oneHourBeforeMidnight.toDateString())
|
||||
expect(numDaysBetweenDates(today, oneHourBeforeMidnight)).toEqual(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user