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

Commit e233d94

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 e233d94

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
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

-12
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();
@@ -1242,17 +1241,6 @@ describe('datepicker', function() {
12421241
]);
12431242
});
12441243

1245-
it('changes the title, year format & range in `year` mode', function() {
1246-
clickTitleButton();
1247-
clickTitleButton();
1248-
1249-
expect(getTitle()).toBe('01 - 10');
1250-
expect(getOptions()).toEqual([
1251-
['01', '02', '03', '04', '05'],
1252-
['06', '07', '08', '09', '10']
1253-
]);
1254-
});
1255-
12561244
it('changes the `starting-day` & day headers & format', function() {
12571245
expect(getLabels()).toEqual(['Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']);
12581246
expect(getOptions(false)).toEqual([

0 commit comments

Comments
 (0)