Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit b0b1434

Browse files
Foxandxssbekos
authored andcommitted
feat(datepicker): full six-week calendar
1 parent 2423f6d commit b0b1434

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

src/datepicker/datepicker.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,19 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.position'])
227227

228228
ctrl._refreshView = function() {
229229
var year = ctrl.activeDate.getFullYear(),
230-
month = ctrl.activeDate.getMonth(),
231-
firstDayOfMonth = new Date(year, month, 1),
232-
difference = ctrl.startingDay - firstDayOfMonth.getDay(),
233-
numDisplayedFromPreviousMonth = (difference > 0) ? 7 - difference : - difference,
234-
firstDate = new Date(firstDayOfMonth), numDates = 0;
230+
month = ctrl.activeDate.getMonth(),
231+
firstDayOfMonth = new Date(year, month, 1),
232+
difference = ctrl.startingDay - firstDayOfMonth.getDay(),
233+
numDisplayedFromPreviousMonth = (difference > 0) ? 7 - difference : - difference,
234+
firstDate = new Date(firstDayOfMonth);
235235

236236
if ( numDisplayedFromPreviousMonth > 0 ) {
237237
firstDate.setDate( - numDisplayedFromPreviousMonth + 1 );
238-
numDates += numDisplayedFromPreviousMonth; // Previous
239238
}
240-
numDates += getDaysInMonth(year, month); // Current
241-
numDates += (7 - numDates % 7) % 7; // Next
242239

243-
var days = getDates(firstDate, numDates);
244-
for (var i = 0; i < numDates; i ++) {
240+
// 42 is the number of days on a six-month calendar
241+
var days = getDates(firstDate, 42);
242+
for (var i = 0; i < 42; i ++) {
245243
days[i] = angular.extend(ctrl.createDateObject(days[i], ctrl.formatDay), {
246244
secondary: days[i].getMonth() !== month,
247245
uid: scope.uniqueId + '-' + i

src/datepicker/test/datepicker.spec.js

+19-11
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,13 @@ describe('datepicker directive', function () {
129129
['05', '06', '07', '08', '09', '10', '11'],
130130
['12', '13', '14', '15', '16', '17', '18'],
131131
['19', '20', '21', '22', '23', '24', '25'],
132-
['26', '27', '28', '29', '30', '01', '02']
132+
['26', '27', '28', '29', '30', '01', '02'],
133+
['03', '04', '05', '06', '07', '08', '09']
133134
]);
134135
});
135136

136137
it('renders the week numbers based on ISO 8601', function() {
137-
expect(getWeeks()).toEqual(['34', '35', '36', '37', '38']);
138+
expect(getWeeks()).toEqual(['34', '35', '36', '37', '38', '39']);
138139
});
139140

140141
it('value is correct', function() {
@@ -183,7 +184,8 @@ describe('datepicker directive', function () {
183184
['08', '09', '10', '11', '12', '13', '14'],
184185
['15', '16', '17', '18', '19', '20', '21'],
185186
['22', '23', '24', '25', '26', '27', '28'],
186-
['29', '30', '31', '01', '02', '03', '04']
187+
['29', '30', '31', '01', '02', '03', '04'],
188+
['05', '06', '07', '08', '09', '10', '11']
187189
]);
188190

189191
expectSelectedElement( null, null );
@@ -257,7 +259,8 @@ describe('datepicker directive', function () {
257259
['06', '07', '08', '09', '10', '11', '12'],
258260
['13', '14', '15', '16', '17', '18', '19'],
259261
['20', '21', '22', '23', '24', '25', '26'],
260-
['27', '28', '29', '30', '01', '02', '03']
262+
['27', '28', '29', '30', '01', '02', '03'],
263+
['04', '05', '06', '07', '08', '09', '10']
261264
]);
262265

263266
expectSelectedElement( 8 );
@@ -386,7 +389,8 @@ describe('datepicker directive', function () {
386389
['06', '07', '08', '09', '10', '11', '12'],
387390
['13', '14', '15', '16', '17', '18', '19'],
388391
['20', '21', '22', '23', '24', '25', '26'],
389-
['27', '28', '29', '30', '01', '02', '03']
392+
['27', '28', '29', '30', '01', '02', '03'],
393+
['04', '05', '06', '07', '08', '09', '10']
390394
]);
391395

392396
clickOption( 17 );
@@ -707,12 +711,13 @@ describe('datepicker directive', function () {
707711
['06', '07', '08', '09', '10', '11', '12'],
708712
['13', '14', '15', '16', '17', '18', '19'],
709713
['20', '21', '22', '23', '24', '25', '26'],
710-
['27', '28', '29', '30', '01', '02', '03']
714+
['27', '28', '29', '30', '01', '02', '03'],
715+
['04', '05', '06', '07', '08', '09', '10']
711716
]);
712717
});
713718

714719
it('renders the week numbers correctly', function() {
715-
expect(getWeeks()).toEqual(['35', '36', '37', '38', '39']);
720+
expect(getWeeks()).toEqual(['35', '36', '37', '38', '39', '40']);
716721
});
717722
});
718723

@@ -913,7 +918,7 @@ describe('datepicker directive', function () {
913918
});
914919

915920
it('executes the dateDisabled expression for each visible day plus one for validation', function() {
916-
expect($rootScope.dateDisabledHandler.calls.length).toEqual(35 + 1);
921+
expect($rootScope.dateDisabledHandler.calls.length).toEqual(42 + 1);
917922
});
918923

919924
it('executes the dateDisabled expression for each visible month plus one for validation', function() {
@@ -981,7 +986,8 @@ describe('datepicker directive', function () {
981986
['5', '6', '7', '8', '9', '10', '11'],
982987
['12', '13', '14', '15', '16', '17', '18'],
983988
['19', '20', '21', '22', '23', '24', '25'],
984-
['26', '27', '28', '29', '30', '1', '2']
989+
['26', '27', '28', '29', '30', '1', '2'],
990+
['3', '4', '5', '6', '7', '8', '9']
985991
]);
986992
});
987993
});
@@ -1042,7 +1048,8 @@ describe('datepicker directive', function () {
10421048
['4', '5', '6', '7', '8', '9', '10'],
10431049
['11', '12', '13', '14', '15', '16', '17'],
10441050
['18', '19', '20', '21', '22', '23', '24'],
1045-
['25', '26', '27', '28', '29', '30', '1']
1051+
['25', '26', '27', '28', '29', '30', '1'],
1052+
['2', '3', '4', '5', '6', '7', '8']
10461053
]);
10471054
});
10481055

@@ -1133,7 +1140,8 @@ describe('datepicker directive', function () {
11331140
['05', '06', '07', '08', '09', '10', '11'],
11341141
['12', '13', '14', '15', '16', '17', '18'],
11351142
['19', '20', '21', '22', '23', '24', '25'],
1136-
['26', '27', '28', '29', '30', '01', '02']
1143+
['26', '27', '28', '29', '30', '01', '02'],
1144+
['03', '04', '05', '06', '07', '08', '09']
11371145
]);
11381146
});
11391147

0 commit comments

Comments
 (0)