diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index d4a133beb6..c7f185e9ea 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -2,6 +2,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst .value('$datepickerSuppressError', false) +.value('$datepickerLiteralWarning', true) + .constant('uibDatepickerConfig', { datepickerMode: 'day', formatDay: 'dd', @@ -21,8 +23,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst yearRows: 4 }) -.controller('UibDatepickerController', ['$scope', '$attrs', '$parse', '$interpolate', '$locale', '$log', 'dateFilter', 'uibDatepickerConfig', '$datepickerSuppressError', 'uibDateParser', - function($scope, $attrs, $parse, $interpolate, $locale, $log, dateFilter, datepickerConfig, $datepickerSuppressError, dateParser) { +.controller('UibDatepickerController', ['$scope', '$attrs', '$parse', '$interpolate', '$locale', '$log', 'dateFilter', 'uibDatepickerConfig', '$datepickerLiteralWarning', '$datepickerSuppressError', 'uibDateParser', + function($scope, $attrs, $parse, $interpolate, $locale, $log, dateFilter, datepickerConfig, $datepickerLiteralWarning, $datepickerSuppressError, dateParser) { var self = this, ngModelCtrl = { $setViewValue: angular.noop }, // nullModelCtrl; ngModelOptions = {}, @@ -99,6 +101,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst if (angular.isDate(value)) { self[key] = dateParser.fromTimezone(new Date(value), ngModelOptions.timezone); } else { + if ($datepickerLiteralWarning) { + $log.warn('Literal date support has been deprecated, please switch to date object usage'); + } + self[key] = new Date(dateFilter(value, 'medium')); } } else { diff --git a/src/datepicker/docs/readme.md b/src/datepicker/docs/readme.md index af88960824..cdbf1fa78c 100644 --- a/src/datepicker/docs/readme.md +++ b/src/datepicker/docs/readme.md @@ -84,7 +84,7 @@ Apart from the previous settings, to configure the uib-datepicker you need to cr C _(Default: `null`)_ - - Defines the maximum available date. + Defines the maximum available date. Requires a Javascript Date object. * `maxMode` C @@ -96,7 +96,7 @@ Apart from the previous settings, to configure the uib-datepicker you need to cr C _(Default: `null`)_ - - Defines the minimum available date. + Defines the minimum available date. Requires a Javascript Date object. * `minMode` C diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index cbfa53a937..f1651eee47 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -139,6 +139,86 @@ describe('datepicker', function() { element.trigger(e); } + describe('$datepickerLiteralWarning', function() { + var $compile, + $log, + $scope; + + it('should warn when using literals for min date by default', function() { + inject(function(_$log_, _$rootScope_, _$compile_) { + $log = _$log_; + $scope = _$rootScope_.$new(); + $compile = _$compile_; + }); + + spyOn($log, 'warn'); + $scope.options = { + minDate: '1984-01-01' + }; + element = $compile('')($scope); + $scope.$digest(); + + expect($log.warn).toHaveBeenCalledWith('Literal date support has been deprecated, please switch to date object usage'); + }); + + it('should suppress warning when using literals for min date', function() { + module(function($provide) { + $provide.value('$datepickerLiteralWarning', false); + }); + inject(function(_$log_, _$rootScope_, _$compile_) { + $log = _$log_; + $scope = _$rootScope_.$new(); + $compile = _$compile_; + }); + + spyOn($log, 'warn'); + $scope.options = { + minDate: '1984-01-01' + }; + element = $compile('')($scope); + $scope.$digest(); + + expect($log.warn).not.toHaveBeenCalled(); + }); + + it('should warn when using literals for max date by default', function() { + inject(function(_$log_, _$rootScope_, _$compile_) { + $log = _$log_; + $scope = _$rootScope_.$new(); + $compile = _$compile_; + }); + + spyOn($log, 'warn'); + $scope.options = { + maxDate: '1984-01-01' + }; + element = $compile('')($scope); + $scope.$digest(); + + expect($log.warn).toHaveBeenCalledWith('Literal date support has been deprecated, please switch to date object usage'); + }); + + it('should suppress warning when using literals for max date', function() { + module(function($provide) { + $provide.value('$datepickerLiteralWarning', false); + }); + inject(function(_$log_, _$rootScope_, _$compile_) { + $log = _$log_; + $scope = _$rootScope_.$new(); + $compile = _$compile_; + }); + + spyOn($log, 'warn'); + $scope.options = { + maxDate: '1984-01-01' + }; + element = $compile('')($scope); + $scope.$digest(); + + expect($log.warn).not.toHaveBeenCalled(); + }); + }); + describe('$datepickerSuppressError', function() { var $compile, $log, diff --git a/src/datepickerPopup/popup.js b/src/datepickerPopup/popup.js index 59af66517f..318a949440 100644 --- a/src/datepickerPopup/popup.js +++ b/src/datepickerPopup/popup.js @@ -1,5 +1,7 @@ angular.module('ui.bootstrap.datepickerPopup', ['ui.bootstrap.datepicker', 'ui.bootstrap.position']) +.value('$datepickerPopupLiteralWarning', true) + .constant('uibDatepickerPopupConfig', { altInputFormats: [], appendToBody: false, @@ -20,8 +22,8 @@ angular.module('ui.bootstrap.datepickerPopup', ['ui.bootstrap.datepicker', 'ui.b placement: 'auto bottom-left' }) -.controller('UibDatepickerPopupController', ['$scope', '$element', '$attrs', '$compile', '$log', '$parse', '$window', '$document', '$rootScope', '$uibPosition', 'dateFilter', 'uibDateParser', 'uibDatepickerPopupConfig', '$timeout', 'uibDatepickerConfig', -function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $rootScope, $position, dateFilter, dateParser, datepickerPopupConfig, $timeout, datepickerConfig) { +.controller('UibDatepickerPopupController', ['$scope', '$element', '$attrs', '$compile', '$log', '$parse', '$window', '$document', '$rootScope', '$uibPosition', 'dateFilter', 'uibDateParser', 'uibDatepickerPopupConfig', '$timeout', 'uibDatepickerConfig', '$datepickerPopupLiteralWarning', +function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $rootScope, $position, dateFilter, dateParser, datepickerPopupConfig, $timeout, datepickerConfig, $datepickerPopupLiteralWarning) { var cache = {}, isHtml5DateInput = false; var dateFormat, closeOnDateSelection, appendToBody, onOpenFocus, @@ -203,6 +205,10 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $ } else if (angular.isDate($scope.datepickerOptions[key])) { dates[key] = dateParser.fromTimezone(new Date($scope.datepickerOptions[key]), timezone); } else { + if ($datepickerPopupLiteralWarning) { + $log.warn('Literal date support has been deprecated, please switch to date object usage'); + } + dates[key] = new Date(dateFilter($scope.datepickerOptions[key], 'medium')); } });