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

Commit 332eefb

Browse files
committed
feat(datepicker): use $locale for starting day
- Change to fallback to $locale.DATETIME_FORMATS.FIRSTDAYOFWEEK for first day column Closes #4954 Closes #5281
1 parent 3b7be53 commit 332eefb

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/datepicker/datepicker.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
1717
ngModelOptions: {},
1818
shortcutPropagation: false,
1919
showWeeks: true,
20-
startingDay: 0,
2120
yearColumns: 5,
2221
yearRows: 4
2322
})
2423

25-
.controller('UibDatepickerController', ['$scope', '$attrs', '$parse', '$interpolate', '$log', 'dateFilter', 'uibDatepickerConfig', '$datepickerSuppressError', 'uibDateParser',
26-
function($scope, $attrs, $parse, $interpolate, $log, dateFilter, datepickerConfig, $datepickerSuppressError, dateParser) {
24+
.controller('UibDatepickerController', ['$scope', '$attrs', '$parse', '$interpolate', '$locale', '$log', 'dateFilter', 'uibDatepickerConfig', '$datepickerSuppressError', 'uibDateParser',
25+
function($scope, $attrs, $parse, $interpolate, $locale, $log, dateFilter, datepickerConfig, $datepickerSuppressError, dateParser) {
2726
var self = this,
2827
ngModelCtrl = { $setViewValue: angular.noop }, // nullModelCtrl;
2928
ngModelOptions = {},
@@ -38,10 +37,19 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
3837
});
3938

4039
// Evaled configuration attributes
41-
angular.forEach(['showWeeks', 'startingDay', 'yearRows', 'yearColumns', 'shortcutPropagation'], function(key) {
42-
self[key] = angular.isDefined($attrs[key]) ? $scope.$parent.$eval($attrs[key]) : datepickerConfig[key];
40+
angular.forEach(['showWeeks', 'yearRows', 'yearColumns', 'shortcutPropagation'], function(key) {
41+
self[key] = angular.isDefined($attrs[key]) ?
42+
$scope.$parent.$eval($attrs[key]) : datepickerConfig[key];
4343
});
4444

45+
if (angular.isDefined($attrs.startingDay)) {
46+
self.startingDay = $scope.$parent.$eval($attrs.startingDay);
47+
} else if (angular.isNumber(datepickerConfig.startingDay)) {
48+
self.startingDay = datepickerConfig.startingDay;
49+
} else {
50+
self.startingDay = ($locale.DATETIME_FORMATS.FIRSTDAYOFWEEK + 8) % 7;
51+
}
52+
4553
// Watchable date attributes
4654
angular.forEach(['minDate', 'maxDate'], function(key) {
4755
if ($attrs[key]) {

src/datepicker/docs/readme.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ The datepicker has 3 modes:
9595
<small class="badge">$</small>
9696
<i class="glyphicon glyphicon-eye-open"></i> -
9797
The date object. Needs to be a Javascript Date object.
98-
98+
9999
* `ng-model-options`
100100
<small class="badge">$</small>
101101
<small class="badge">C</small>
@@ -119,7 +119,7 @@ The datepicker has 3 modes:
119119
* `starting-day`
120120
<small class="badge">$</small>
121121
<small class="badge">C</small>
122-
_(Default: `0`)_ -
122+
_(Default: `$locale.DATETIME_FORMATS.FIRSTDAYOFWEEK`)_ -
123123
Starting day of the week from 0-6 (0=Sunday, ..., 6=Saturday).
124124

125125
* `template-url`
@@ -174,7 +174,7 @@ The popup is a wrapper that you can use in an input to toggle a datepicker. To c
174174
<small class="badge">C</small>
175175
_(Default: `false`, Config: `appendToBody`)_ -
176176
Append the datepicker popup element to `body`, rather than inserting after `datepicker-popup`.
177-
177+
178178
* `datepicker-options`
179179
<small class="badge">$</small> -
180180
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
206206
<small class="badge">C</small>
207207
_(Default: `true`)_ -
208208
Whether or not to display a button bar underneath the uib-datepicker.
209-
209+
210210
* `type`
211211
<small class="badge">C</small>
212212
_(Default: `text`, Config: `html5Types`)_ -

src/datepicker/test/datepicker.spec.js

+3
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,9 @@ describe('datepicker', function() {
12541254
}));
12551255
afterEach(inject(function(uibDatepickerConfig) {
12561256
// return it to the original state
1257+
Object.keys(uibDatepickerConfig).forEach(function(key) {
1258+
delete uibDatepickerConfig[key];
1259+
});
12571260
angular.extend(uibDatepickerConfig, originalConfig);
12581261
}));
12591262

0 commit comments

Comments
 (0)