Skip to content

Commit e8a1ac6

Browse files
committed
fix: Start date missing at the end
1 parent 374418a commit e8a1ac6

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/utils/dateUtil.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,16 @@ export function getWeekStartDate<DateType>(
164164
const monthStartDate = generateConfig.setDate(value, 1);
165165
const startDateWeekDay = generateConfig.getWeekDay(monthStartDate);
166166

167-
return generateConfig.addDate(monthStartDate, weekFirstDay - startDateWeekDay);
167+
let alignStartDate = generateConfig.addDate(monthStartDate, weekFirstDay - startDateWeekDay);
168+
169+
if (
170+
generateConfig.getMonth(alignStartDate) === generateConfig.getMonth(value) &&
171+
generateConfig.getDate(alignStartDate) > 1
172+
) {
173+
alignStartDate = generateConfig.addDate(alignStartDate, -7);
174+
}
175+
176+
return alignStartDate;
168177
}
169178

170179
export function getClosingViewDate<DateType>(

tests/panel.spec.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,23 @@ describe('Picker.Panel', () => {
438438
},
439439
);
440440

441+
[{ locale: zhCN, startDate: '24' }, { locale: enUS, startDate: '1' }].forEach(
442+
({ locale, startDate }) => {
443+
it(`another align test of ${locale.locale}`, () => {
444+
const wrapper = mount(
445+
<MomentPickerPanel defaultValue={getMoment('2020-03-01')} locale={locale} />,
446+
);
447+
448+
expect(
449+
wrapper
450+
.find('td')
451+
.first()
452+
.text(),
453+
).toEqual(startDate);
454+
});
455+
},
456+
);
457+
441458
it('update firstDayOfWeek', () => {
442459
const defaultFirstDay = moment(enUS.locale)
443460
.localeData()

0 commit comments

Comments
 (0)