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

Commit

Permalink
feat(datepicker): full six-week calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxandxss authored and bekos committed Apr 16, 2014
1 parent 2423f6d commit b0b1434
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
18 changes: 8 additions & 10 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,19 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.position'])

ctrl._refreshView = function() {
var year = ctrl.activeDate.getFullYear(),
month = ctrl.activeDate.getMonth(),
firstDayOfMonth = new Date(year, month, 1),
difference = ctrl.startingDay - firstDayOfMonth.getDay(),
numDisplayedFromPreviousMonth = (difference > 0) ? 7 - difference : - difference,
firstDate = new Date(firstDayOfMonth), numDates = 0;
month = ctrl.activeDate.getMonth(),
firstDayOfMonth = new Date(year, month, 1),
difference = ctrl.startingDay - firstDayOfMonth.getDay(),
numDisplayedFromPreviousMonth = (difference > 0) ? 7 - difference : - difference,
firstDate = new Date(firstDayOfMonth);

if ( numDisplayedFromPreviousMonth > 0 ) {
firstDate.setDate( - numDisplayedFromPreviousMonth + 1 );
numDates += numDisplayedFromPreviousMonth; // Previous
}
numDates += getDaysInMonth(year, month); // Current
numDates += (7 - numDates % 7) % 7; // Next

var days = getDates(firstDate, numDates);
for (var i = 0; i < numDates; i ++) {
// 42 is the number of days on a six-month calendar
var days = getDates(firstDate, 42);
for (var i = 0; i < 42; i ++) {
days[i] = angular.extend(ctrl.createDateObject(days[i], ctrl.formatDay), {
secondary: days[i].getMonth() !== month,
uid: scope.uniqueId + '-' + i
Expand Down
30 changes: 19 additions & 11 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,13 @@ describe('datepicker directive', function () {
['05', '06', '07', '08', '09', '10', '11'],
['12', '13', '14', '15', '16', '17', '18'],
['19', '20', '21', '22', '23', '24', '25'],
['26', '27', '28', '29', '30', '01', '02']
['26', '27', '28', '29', '30', '01', '02'],
['03', '04', '05', '06', '07', '08', '09']
]);
});

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

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

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

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

clickOption( 17 );
Expand Down Expand Up @@ -707,12 +711,13 @@ describe('datepicker directive', function () {
['06', '07', '08', '09', '10', '11', '12'],
['13', '14', '15', '16', '17', '18', '19'],
['20', '21', '22', '23', '24', '25', '26'],
['27', '28', '29', '30', '01', '02', '03']
['27', '28', '29', '30', '01', '02', '03'],
['04', '05', '06', '07', '08', '09', '10']
]);
});

it('renders the week numbers correctly', function() {
expect(getWeeks()).toEqual(['35', '36', '37', '38', '39']);
expect(getWeeks()).toEqual(['35', '36', '37', '38', '39', '40']);
});
});

Expand Down Expand Up @@ -913,7 +918,7 @@ describe('datepicker directive', function () {
});

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

it('executes the dateDisabled expression for each visible month plus one for validation', function() {
Expand Down Expand Up @@ -981,7 +986,8 @@ describe('datepicker directive', function () {
['5', '6', '7', '8', '9', '10', '11'],
['12', '13', '14', '15', '16', '17', '18'],
['19', '20', '21', '22', '23', '24', '25'],
['26', '27', '28', '29', '30', '1', '2']
['26', '27', '28', '29', '30', '1', '2'],
['3', '4', '5', '6', '7', '8', '9']
]);
});
});
Expand Down Expand Up @@ -1042,7 +1048,8 @@ describe('datepicker directive', function () {
['4', '5', '6', '7', '8', '9', '10'],
['11', '12', '13', '14', '15', '16', '17'],
['18', '19', '20', '21', '22', '23', '24'],
['25', '26', '27', '28', '29', '30', '1']
['25', '26', '27', '28', '29', '30', '1'],
['2', '3', '4', '5', '6', '7', '8']
]);
});

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

Expand Down

0 comments on commit b0b1434

Please sign in to comment.