diff --git a/lib/days.js b/lib/days.js index 379aa87..039ddce 100644 --- a/lib/days.js +++ b/lib/days.js @@ -193,13 +193,16 @@ Days.prototype.rowsFor = function(date){ var month = date.getMonth(); var year = date.getFullYear(); + // days required before start of month to pad to Sunday + var startDate = new Date(date); + startDate.setDate(1); + var before = startDate.getDay(); + // calculate overflow var total = daysInMonth(month); var perRow = 7; - var totalShown = perRow * Math.ceil(total / perRow); - var extra = totalShown - total || 7; - var before = Math.floor(extra / 2); - var after = Math.ceil(extra / 2); + var totalShown = perRow * Math.ceil((total + before) / perRow); + var after = totalShown - (total + before); var cells = []; // cells before