Skip to content

Commit

Permalink
Work around date±duration operations being broken
Browse files Browse the repository at this point in the history
Looks like adding a dayjs duration object to a dayjs date object returns an
invalid date object with most fields set to `NaN`
  • Loading branch information
cmd-johnson committed Nov 7, 2023
1 parent 16e2ec5 commit e911d42
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions packages/frontend/src/pages/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ export function CalendarPage(): JSX.Element {
}, [dispatch, month, year])

const handleTodayClicked = () => setCurrentMonth(dayjs.utc())
const handleNextMonthClicked = () =>
setCurrentMonth(m => m.add(dayjs.duration({ months: 1 })))
const handlePrevMonthClicked = () =>
setCurrentMonth(m => m.subtract(dayjs.duration({ months: 1 })))
const handleNextMonthClicked = () => setCurrentMonth(m => m.add(1, 'month'))
const handlePrevMonthClicked = () => setCurrentMonth(m => m.subtract(1, 'month'))
const handleReloadClicked = () => {
dispatch(clearCalendarEntries())
dispatch(loadMonth({ month, year }))
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/store/calendar-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function getDisplayedMonthRange(date: { year: number, month: number }): {
const startOfMonthPadding = modulo(firstOfMonth.day() - dayjs.localeData().firstDayOfWeek(), 7)
const from = firstOfMonth.subtract(startOfMonthPadding, 'days')
const displayedWeeks = Math.ceil((from.daysInMonth() + startOfMonthPadding) / 7)
const to = from.add(dayjs.duration({ weeks: displayedWeeks }))
const to = from.add(displayedWeeks, 'weeks')
return { from, to, displayedWeeks }
}

Expand Down

0 comments on commit e911d42

Please sign in to comment.