From c24d5357c3480ec36575ee1eb30a29bc530ccc2b Mon Sep 17 00:00:00 2001 From: Andrew Patton Date: Sun, 28 Apr 2024 18:29:38 -0700 Subject: [PATCH] Use getLastDateFromMonth util in MonthCalendar --- packages/date-picker/src/MonthCalendar.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/date-picker/src/MonthCalendar.tsx b/packages/date-picker/src/MonthCalendar.tsx index e0f15ca2..3b1b09eb 100644 --- a/packages/date-picker/src/MonthCalendar.tsx +++ b/packages/date-picker/src/MonthCalendar.tsx @@ -3,7 +3,12 @@ import clsx from 'clsx'; import * as React from 'react'; import { ROOT_CLASS_NAME, STYLES } from './styles/month-calendar.js'; -import { getMonthFromDate, getMonthNameFromMonth, getYearFromMonth } from './utils.js'; +import { + getLastDateFromMonth, + getMonthFromDate, + getMonthNameFromMonth, + getYearFromMonth, +} from './utils.js'; export type Props = { className?: string; @@ -38,8 +43,7 @@ export default function MonthCalendar({ title = title ?? `${getMonthNameFromMonth(month)} ${year}`; const monthWithinYear = month % 12; const firstDate = new Date(year, monthWithinYear, 1); - const nextMonth = month + 1; - const lastDate = new Date(getYearFromMonth(nextMonth), nextMonth % 12, 1); + const lastDate = getLastDateFromMonth(month); lastDate.setDate(lastDate.getDate() - 1); const totalDays = lastDate.getDate(); const firstDay = firstDate.getDay();