chore: fix date tests

This commit is contained in:
Mo
2022-12-01 07:05:02 -06:00
parent 1ee6be4e5c
commit 73ca12275f
6 changed files with 31 additions and 20 deletions

View File

@@ -1,4 +1,4 @@
import { addDays } from '@/Utils/DateUtils'
import { addDaysToDate } from '@standardnotes/utils'
import { numDaysBetweenDates } from './DateUtils'
describe('date utils', () => {
@@ -6,16 +6,16 @@ describe('date utils', () => {
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)
expect(numDaysBetweenDates(today, addDaysToDate(today, 1))).toEqual(1)
expect(numDaysBetweenDates(today, addDaysToDate(today, 2))).toEqual(2)
expect(numDaysBetweenDates(today, addDaysToDate(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)
expect(numDaysBetweenDates(today, addDaysToDate(today, 3))).toEqual(3)
expect(numDaysBetweenDates(addDaysToDate(today, 3), today)).toEqual(3)
})
it('should return 1 day difference between two dates on different days but 1 hour apart', () => {

View File

@@ -63,12 +63,6 @@ export function numDaysBetweenDates(date1: Date, date2: Date): number {
return Math.floor(diffInDays)
}
export function addDays(date: Date, days: number) {
const result = new Date(date)
result.setDate(result.getDate() + days)
return result
}
/**
* @returns Date with day equal to first day of the offseted month
*/