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

Commit 5e4480d

Browse files
committed
feat(datepicker): use $locale for starting day
- Change to fallback to $locale.DATETIME_FORMATS.FIRSTDAYOFWEEK for first day column
1 parent a5797b9 commit 5e4480d

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

Diff for: 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 = {};
@@ -37,10 +36,19 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
3736
});
3837

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

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

Diff for: src/datepicker/docs/readme.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ The datepicker has 3 modes:
9797
<small class="badge">$</small>
9898
<i class="glyphicon glyphicon-eye-open"></i> -
9999
The date object. Needs to be a Javascript Date object.
100-
100+
101101
* `ng-model-options`
102102
<small class="badge">$</small>
103103
<small class="badge">C</small>
@@ -121,7 +121,7 @@ The datepicker has 3 modes:
121121
* `starting-day`
122122
<small class="badge">$</small>
123123
<small class="badge">C</small>
124-
_(Default: `0`)_ -
124+
_(Default: `$locale.DATETIME_FORMATS.FIRSTDAYOFWEEK`)_ -
125125
Starting day of the week from 0-6 (0=Sunday, ..., 6=Saturday).
126126

127127
* `template-url`
@@ -176,7 +176,7 @@ The popup is a wrapper that you can use in an input to toggle a datepicker. To c
176176
<small class="badge">C</small>
177177
_(Default: `false`, Config: `appendToBody`)_ -
178178
Append the datepicker popup element to `body`, rather than inserting after `datepicker-popup`.
179-
179+
180180
* `datepicker-options`
181181
<small class="badge">$</small> -
182182
An object with any combination of the datepicker settings (in camelCase) used to configure the wrapped datepicker.
@@ -208,7 +208,7 @@ The popup is a wrapper that you can use in an input to toggle a datepicker. To c
208208
<small class="badge">C</small>
209209
_(Default: `true`)_ -
210210
Whether or not to display a button bar underneath the uib-datepicker.
211-
211+
212212
* `type`
213213
<small class="badge">C</small>
214214
_(Default: `text`, Config: `html5Types`)_ -

Diff for: src/datepicker/test/datepicker.spec.js

+3
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,9 @@ describe('datepicker', function() {
12231223
}));
12241224
afterEach(inject(function(uibDatepickerConfig) {
12251225
// return it to the original state
1226+
Object.keys(uibDatepickerConfig).forEach(function(key) {
1227+
delete uibDatepickerConfig[key];
1228+
});
12261229
angular.extend(uibDatepickerConfig, originalConfig);
12271230
}));
12281231

0 commit comments

Comments
 (0)