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

Commit

Permalink
feat(datepicker): use $locale for starting day
Browse files Browse the repository at this point in the history
- Change to fallback to $locale.DATETIME_FORMATS.FIRSTDAYOFWEEK for
  first day column

Closes #4954
Closes #5281
  • Loading branch information
wesleycho committed Jan 18, 2016
1 parent 3b7be53 commit 332eefb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
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 @@ -38,10 +37,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 @@ -95,7 +95,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 @@ -119,7 +119,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 @@ -174,7 +174,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 @@ -206,7 +206,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 @@ -1254,6 +1254,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

0 comments on commit 332eefb

Please sign in to comment.