Skip to content

Commit

Permalink
Use getLastDateFromMonth util in MonthCalendar
Browse files Browse the repository at this point in the history
  • Loading branch information
acusti committed Apr 29, 2024
1 parent bfd2b66 commit c24d535
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/date-picker/src/MonthCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c24d535

Please sign in to comment.