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

Commit 4d41d10

Browse files
committed
feat(datepicker): use $locale for starting day
- Change to fallback to $locale.DATETIME_FORMATS.FIRSTDAYOFWEEK for first day column BREAKING CHANGE: Due to usage of $locale, if one wants the prior behavior, one should use the starting-day attribute on the datepicker element
1 parent a5797b9 commit 4d41d10

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

Diff for: src/datepicker/datepicker.js

+9-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,15 @@ 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+
self.startingDay = angular.isDefined($attrs.startingDay) ?
45+
$scope.$parent.$eval($attrs.startingDay) :
46+
($locale.DATETIME_FORMATS.FIRSTDAYOFWEEK + 8) % 7;
47+
4448
// Watchable date attributes
4549
angular.forEach(['minDate', 'maxDate'], function(key) {
4650
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

-13
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,6 @@ describe('datepicker', function() {
12161216
uibDatepickerConfig.showWeeks = false;
12171217
uibDatepickerConfig.yearRows = 2;
12181218
uibDatepickerConfig.yearColumns = 5;
1219-
uibDatepickerConfig.startingDay = 6;
12201219

12211220
element = $compile('<uib-datepicker ng-model="date"></uib-datepicker>')($rootScope);
12221221
$rootScope.$digest();
@@ -1253,18 +1252,6 @@ describe('datepicker', function() {
12531252
]);
12541253
});
12551254

1256-
it('changes the `starting-day` & day headers & format', function() {
1257-
expect(getLabels()).toEqual(['Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']);
1258-
expect(getOptions(false)).toEqual([
1259-
['28', '29', '30', '31', '1', '2', '3'],
1260-
['4', '5', '6', '7', '8', '9', '10'],
1261-
['11', '12', '13', '14', '15', '16', '17'],
1262-
['18', '19', '20', '21', '22', '23', '24'],
1263-
['25', '26', '27', '28', '29', '30', '1'],
1264-
['2', '3', '4', '5', '6', '7', '8']
1265-
]);
1266-
});
1267-
12681255
it('changes initial visibility for weeks', function() {
12691256
expect(getLabelsRow().find('th').length).toEqual(7);
12701257
var tr = element.find('tbody').find('tr');

0 commit comments

Comments
 (0)