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

Commit

Permalink
fix(datepicker): min-date: timezone fix for literals
Browse files Browse the repository at this point in the history
fixes #3437
  • Loading branch information
davious committed Nov 9, 2015
1 parent 1f43cdf commit b799c53
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,16 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
scope.$parent.$watch(getAttribute, function(value) {
scope.watchData[key] = value;
if (key === 'minDate' || key === 'maxDate') {
cache[key] = new Date(value);
var date = parseDate(value);
if (!date) {
date = new Date(value);
if (angular.isDate(date) && !isNaN(date)) {
var dateArray = date.toISOString().split('T')[0].split('-');
date = new Date(+dateArray[0], +dateArray[1] - 1, +dateArray[2]);
}
}
scope.watchData[key] = date;
cache[key] = date;
}
});
datepickerEl.attr(cameltoDash(key), 'watchData.' + key);
Expand Down
11 changes: 11 additions & 0 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,17 @@ describe('datepicker directive', function() {
expect(buttons.eq(0).prop('disabled')).toBe(true);
});

it('should disable today button if before min date, literal case', function() {
var minDate = new Date(new Date().setDate(new Date().getDate() + 1));
var literalMinDate = minDate.toISOString().split('T')[0];
var wrapElement = $compile('<div><input ng-model="date" uib-datepicker-popup min-date="\'' + literalMinDate + '\'" is-open="true"><div>')($rootScope);
$rootScope.$digest();
assignElements(wrapElement);
assignButtonBar();

expect(buttons.eq(0).prop('disabled')).toBe(true);
});

it('should disable today button if after max date', function() {
$rootScope.maxDate = new Date().setDate(new Date().getDate() - 2);
var wrapElement = $compile('<div><input ng-model="date" uib-datepicker-popup max-date="maxDate" is-open="true"><div>')($rootScope);
Expand Down

0 comments on commit b799c53

Please sign in to comment.