Skip to content

Commit 031dadb

Browse files
committed
fix(input-date): calendar sometimes cut off the last day
1 parent febff8d commit 031dadb

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

packages/ui-components/src/lib/inputs/InputDate/InputDate.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,26 @@ import { useEffect } from 'react';
1212
// https://github.com/mui/material-ui/issues/30591#issuecomment-1377997824
1313
class Adapter extends AdapterLuxon {
1414
public getWeekdays = () => {
15-
return ['S', 'M', 'T', 'W', 'T', 'F', 'S'];
15+
return ['Su', 'M', 'Tu', 'W', 'Th', 'F', 'Sa'];
1616
};
1717

1818
getWeekArray = (date: DateTime) => {
19-
const { days } = date.endOf('month').endOf('week').diff(date.startOf('month').startOf('week'), 'days').toObject();
19+
date = date.setLocale('en-US');
20+
21+
// Manually adjust the start and end of the week to begin on Sunday
22+
const startOfMonth = date.startOf('month');
23+
const endOfMonth = date.endOf('month');
24+
const startOfFirstWeek = startOfMonth.minus({ days: startOfMonth.weekday % 7 });
25+
const endOfLastWeek = endOfMonth.plus({ days: 6 - (endOfMonth.weekday % 7) });
26+
const { days } = endOfLastWeek.diff(startOfFirstWeek, 'days').toObject();
2027

2128
let weeks: DateTime[][] = [];
2229
new Array(Math.round(days ?? 0))
2330
.fill(0)
2431
.map((_, i) => i)
25-
.map(day => date.startOf('month').startOf('week').minus({ days: 1 }).plus({ days: day }))
32+
.map(day => startOfFirstWeek.plus({ days: day }))
2633
.forEach((v, i) => {
34+
console.log('v', v.toLocaleString(), 'i', i);
2735
if (i === 0 || (i % 7 === 0 && i > 6)) {
2836
weeks.push([v]);
2937
return;

0 commit comments

Comments
 (0)