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

Commit e0673b0

Browse files
committed
fix(datepicker): min-date: timezone fix for literals
fixes #3437
1 parent ea388b3 commit e0673b0

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: src/datepicker/datepicker.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,13 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
618618
scope.$parent.$watch(getAttribute, function(value) {
619619
scope.watchData[key] = value;
620620
if (key === 'minDate' || key === 'maxDate') {
621-
cache[key] = new Date(value);
621+
var date = parseDate(value);
622+
if(!date) {
623+
var dateArray = new Date(value).toISOString().split('T')[0].split('-');
624+
date = new Date(+dateArray[0], +dateArray[1] - 1, +dateArray[2]);
625+
}
626+
scope.watchData[key] = date;
627+
cache[key] = date;
622628
}
623629
});
624630
datepickerEl.attr(cameltoDash(key), 'watchData.' + key);

Diff for: src/datepicker/test/datepicker.spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,17 @@ describe('datepicker directive', function() {
19481948
expect(buttons.eq(0).prop('disabled')).toBe(true);
19491949
});
19501950

1951+
it('should disable today button if before min date, literal case', function() {
1952+
var minDate = new Date(new Date().setDate(new Date().getDate() + 1));
1953+
var literalMinDate = minDate.toISOString().split('T')[0];
1954+
var wrapElement = $compile('<div><input ng-model="date" uib-datepicker-popup min-date="\'' + literalMinDate + '\'" is-open="true"><div>')($rootScope);
1955+
$rootScope.$digest();
1956+
assignElements(wrapElement);
1957+
assignButtonBar();
1958+
1959+
expect(buttons.eq(0).prop('disabled')).toBe(true);
1960+
});
1961+
19511962
it('should disable today button if after max date', function() {
19521963
$rootScope.maxDate = new Date().setDate(new Date().getDate() - 2);
19531964
var wrapElement = $compile('<div><input ng-model="date" uib-datepicker-popup max-date="maxDate" is-open="true"><div>')($rootScope);

0 commit comments

Comments
 (0)