From 9130039826464811dd19541f4f4f277c2db79dea Mon Sep 17 00:00:00 2001 From: colinf Date: Fri, 21 Sep 2012 11:46:17 +0100 Subject: [PATCH] Adjust padding at start/end of month - fix for issue #11 --- lib/days.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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