From b0b1434389c889360b174b718b79fc1993c099bc Mon Sep 17 00:00:00 2001 From: Jesus Rodriguez Date: Mon, 10 Mar 2014 00:30:30 +0100 Subject: [PATCH] feat(datepicker): full six-week calendar --- src/datepicker/datepicker.js | 18 +++++++--------- src/datepicker/test/datepicker.spec.js | 30 ++++++++++++++++---------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 89498b85a5..09c1cff706 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -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 diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index cd4c5b8398..a4bc60d29d 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -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() { @@ -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 ); @@ -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 ); @@ -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 ); @@ -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']); }); }); @@ -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() { @@ -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'] ]); }); }); @@ -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'] ]); }); @@ -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'] ]); });