chore: fix date tests
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { addDaysToDate } from '@standardnotes/utils'
|
||||
import { ListableContentItem } from '../Types/ListableContentItem'
|
||||
import { addDays, getWeekdayName } from '@/Utils/DateUtils'
|
||||
import { getWeekdayName } from '@/Utils/DateUtils'
|
||||
import { DailyItemsDay } from './DailyItemsDaySection'
|
||||
import { dateToDailyDayIdentifier } from './Utils'
|
||||
|
||||
@@ -53,11 +54,11 @@ export function insertBlanks(entries: DailyItemsDay[], location: 'front' | 'end'
|
||||
|
||||
for (let i = 1; i <= number; i++) {
|
||||
if (location === 'front') {
|
||||
const plusNFromFirstDay = addDays(laterDay, i)
|
||||
const plusNFromFirstDay = addDaysToDate(laterDay, i)
|
||||
const futureEntry = templateEntryForDate(plusNFromFirstDay)
|
||||
entries.unshift(futureEntry)
|
||||
} else {
|
||||
const minusNFromLastDay = addDays(earlierDay, -i)
|
||||
const minusNFromLastDay = addDaysToDate(earlierDay, -i)
|
||||
const pastEntry = templateEntryForDate(minusNFromLastDay)
|
||||
entries.push(pastEntry)
|
||||
}
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user