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

feat(datepicker): use $locale for starting day #5281

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -37,10 +36,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]) {
Expand Down
8 changes: 4 additions & 4 deletions src/datepicker/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ The datepicker has 3 modes:
<small class="badge">$</small>
<i class="glyphicon glyphicon-eye-open"></i> -
The date object. Needs to be a Javascript Date object.

* `ng-model-options`
<small class="badge">$</small>
<small class="badge">C</small>
Expand All @@ -121,7 +121,7 @@ The datepicker has 3 modes:
* `starting-day`
<small class="badge">$</small>
<small class="badge">C</small>
_(Default: `0`)_ -
_(Default: `$locale.DATETIME_FORMATS.FIRSTDAYOFWEEK`)_ -
Starting day of the week from 0-6 (0=Sunday, ..., 6=Saturday).

* `template-url`
Expand Down Expand Up @@ -176,7 +176,7 @@ The popup is a wrapper that you can use in an input to toggle a datepicker. To c
<small class="badge">C</small>
_(Default: `false`, Config: `appendToBody`)_ -
Append the datepicker popup element to `body`, rather than inserting after `datepicker-popup`.

* `datepicker-options`
<small class="badge">$</small> -
An object with any combination of the datepicker settings (in camelCase) used to configure the wrapped datepicker.
Expand Down Expand Up @@ -208,7 +208,7 @@ The popup is a wrapper that you can use in an input to toggle a datepicker. To c
<small class="badge">C</small>
_(Default: `true`)_ -
Whether or not to display a button bar underneath the uib-datepicker.

* `type`
<small class="badge">C</small>
_(Default: `text`, Config: `html5Types`)_ -
Expand Down
3 changes: 3 additions & 0 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,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);
}));

Expand Down