Skip to content

Commit

Permalink
Merge pull request component#13 from colinf/StartDay
Browse files Browse the repository at this point in the history
Adjust padding at start/end of month - fix for issue component#11
  • Loading branch information
tj committed Sep 21, 2012
2 parents 825b3bc + 9130039 commit 8a7b343
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/days.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8a7b343

Please sign in to comment.