From 495e91f5945245d9344cfd38c88cfb4dbc8cea90 Mon Sep 17 00:00:00 2001 From: Dave Anderson Date: Sun, 8 Nov 2015 22:24:29 -0500 Subject: [PATCH] fix(datepicker): min-date: timezone fix for literals tweaks * toISOString -> toJSON (equivalent) * date.setYear fix * fix test to capture date-format mismatch edge case in #3437 --- src/datepicker/datepicker.js | 3 ++- src/datepicker/test/datepicker.spec.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index accdc08503..c1f67cb913 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -633,8 +633,9 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi if (!date) { date = new Date(value); if (angular.isDate(date) && !isNaN(date)) { - var dateArray = date.toISOString().split('T')[0].split('-'); + var dateArray = date.toJSON().split('T')[0].split('-'); date = new Date(+dateArray[0], +dateArray[1] - 1, +dateArray[2]); + date.setFullYear(+dateArray[0]); } } scope.watchData[key] = date; diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 1b97feb9af..de3aed8f48 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1950,8 +1950,8 @@ describe('datepicker directive', function() { 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('
')($rootScope); + var literalMinDate = minDate.toJSON().split('T')[0]; + var wrapElement = $compile('
')($rootScope); $rootScope.$digest(); assignElements(wrapElement); assignButtonBar();