From 332eefb46497486d24e5633be53acb6709bc22d7 Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Sat, 16 Jan 2016 12:08:06 -0800 Subject: [PATCH] feat(datepicker): use $locale for starting day - Change to fallback to $locale.DATETIME_FORMATS.FIRSTDAYOFWEEK for first day column Closes #4954 Closes #5281 --- src/datepicker/datepicker.js | 18 +++++++++++++----- src/datepicker/docs/readme.md | 8 ++++---- src/datepicker/test/datepicker.spec.js | 3 +++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 4f0377536b..22e30b8998 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -17,13 +17,12 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst ngModelOptions: {}, shortcutPropagation: false, showWeeks: true, - startingDay: 0, yearColumns: 5, yearRows: 4 }) -.controller('UibDatepickerController', ['$scope', '$attrs', '$parse', '$interpolate', '$log', 'dateFilter', 'uibDatepickerConfig', '$datepickerSuppressError', 'uibDateParser', - function($scope, $attrs, $parse, $interpolate, $log, dateFilter, datepickerConfig, $datepickerSuppressError, dateParser) { +.controller('UibDatepickerController', ['$scope', '$attrs', '$parse', '$interpolate', '$locale', '$log', 'dateFilter', 'uibDatepickerConfig', '$datepickerSuppressError', 'uibDateParser', + function($scope, $attrs, $parse, $interpolate, $locale, $log, dateFilter, datepickerConfig, $datepickerSuppressError, dateParser) { var self = this, ngModelCtrl = { $setViewValue: angular.noop }, // nullModelCtrl; ngModelOptions = {}, @@ -38,10 +37,19 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst }); // Evaled configuration attributes - angular.forEach(['showWeeks', 'startingDay', 'yearRows', 'yearColumns', 'shortcutPropagation'], function(key) { - self[key] = angular.isDefined($attrs[key]) ? $scope.$parent.$eval($attrs[key]) : datepickerConfig[key]; + angular.forEach(['showWeeks', 'yearRows', 'yearColumns', 'shortcutPropagation'], function(key) { + self[key] = angular.isDefined($attrs[key]) ? + $scope.$parent.$eval($attrs[key]) : datepickerConfig[key]; }); + if (angular.isDefined($attrs.startingDay)) { + self.startingDay = $scope.$parent.$eval($attrs.startingDay); + } else if (angular.isNumber(datepickerConfig.startingDay)) { + self.startingDay = datepickerConfig.startingDay; + } else { + self.startingDay = ($locale.DATETIME_FORMATS.FIRSTDAYOFWEEK + 8) % 7; + } + // Watchable date attributes angular.forEach(['minDate', 'maxDate'], function(key) { if ($attrs[key]) { diff --git a/src/datepicker/docs/readme.md b/src/datepicker/docs/readme.md index 190c8a98d3..b686bc725d 100644 --- a/src/datepicker/docs/readme.md +++ b/src/datepicker/docs/readme.md @@ -95,7 +95,7 @@ The datepicker has 3 modes: $ - The date object. Needs to be a Javascript Date object. - + * `ng-model-options` $ C @@ -119,7 +119,7 @@ The datepicker has 3 modes: * `starting-day` $ C - _(Default: `0`)_ - + _(Default: `$locale.DATETIME_FORMATS.FIRSTDAYOFWEEK`)_ - Starting day of the week from 0-6 (0=Sunday, ..., 6=Saturday). * `template-url` @@ -174,7 +174,7 @@ The popup is a wrapper that you can use in an input to toggle a datepicker. To c C _(Default: `false`, Config: `appendToBody`)_ - Append the datepicker popup element to `body`, rather than inserting after `datepicker-popup`. - + * `datepicker-options` $ - An object with any combination of the datepicker settings (in camelCase) used to configure the wrapped datepicker. @@ -206,7 +206,7 @@ The popup is a wrapper that you can use in an input to toggle a datepicker. To c C _(Default: `true`)_ - Whether or not to display a button bar underneath the uib-datepicker. - + * `type` C _(Default: `text`, Config: `html5Types`)_ - diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index a1f9166767..abf2b72100 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1254,6 +1254,9 @@ describe('datepicker', function() { })); afterEach(inject(function(uibDatepickerConfig) { // return it to the original state + Object.keys(uibDatepickerConfig).forEach(function(key) { + delete uibDatepickerConfig[key]; + }); angular.extend(uibDatepickerConfig, originalConfig); }));