Skip to content

Commit 396ce76

Browse files
committed
Refactored getNumWeeks function to use a different approach.
1 parent 502db82 commit 396ce76

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/datetime-range.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ angular.module('g1b.datetime-range', []).
3737
// Get number of weeks in month
3838
scope.getNumWeeks = function () {
3939
if ( !scope.calendar ) { return; }
40-
return Math.floor(scope.calendar.clone().endOf('month').endOf('week').diff(scope.calendar.clone().startOf('month').startOf('week'), 'days') / 7) + 1;
40+
41+
var firstDayOfWeek = scope.calendar.clone().startOf('week').weekday();
42+
43+
var firstOfMonth = scope.calendar.clone().startOf('month');
44+
var lastOfMonth = scope.calendar.clone().endOf('month');
45+
46+
var firstWeekDay = (firstOfMonth.weekday() - firstDayOfWeek + 7) % 7;
47+
48+
return Math.ceil((firstWeekDay + scope.calendar.daysInMonth()) / 7);
4149
}
4250

4351
// Set selected date

0 commit comments

Comments
 (0)