Skip to content

Commit aa21929

Browse files
committed
fix utils.getMonthsForYear() to account for months shorter than that of the selected date; resolves #140
1 parent c776d13 commit aa21929

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/utils/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ export function getDateString(year, month, date) {
157157
}
158158

159159
export function getMonthsForYear(year, day = 1) {
160-
return Array.apply(null, Array(12)).map((val, index) => new Date(year, index, day));
160+
return Array.apply(null, Array(12)).map((val, index) => {
161+
const constrainedDay = Math.min(getDaysInMonth(new Date(year, index, 1)), day);
162+
return new Date(year, index, constrainedDay);
163+
});
161164
}
162165

163166
export const withImmutableProps = (props) => withPropsOnChange(() => false, props);

0 commit comments

Comments
 (0)