Skip to content

Commit

Permalink
fix(datepicker): min-date: timezone fix for literals
Browse files Browse the repository at this point in the history
  • Loading branch information
davious committed Nov 8, 2015
1 parent ee7ab9f commit f2c1906
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) {
var tryDate = new Date(value);
if(angular.isDate(tryDate) && !isNaN(tryDate)) {
dateArray = tryDate.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 f2c1906

Please sign in to comment.