diff --git a/src/dateparser/dateparser.js b/src/dateparser/dateparser.js index 783696ce08..a135974b43 100644 --- a/src/dateparser/dateparser.js +++ b/src/dateparser/dateparser.js @@ -1,6 +1,6 @@ angular.module('ui.bootstrap.dateparser', []) -.service('dateParser', ['$log', '$locale', 'orderByFilter', function($log, $locale, orderByFilter) { +.service('uibDateParser', ['$log', '$locale', 'orderByFilter', function($log, $locale, orderByFilter) { // Pulled from https://github.com/mbostock/d3/blob/master/src/format/requote.js var SPECIAL_CHARACTERS_REGEXP = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g; @@ -210,3 +210,17 @@ angular.module('ui.bootstrap.dateparser', []) return true; } }]); + +/* Deprecated dateparser below */ + +angular.module('ui.bootstrap.dateparser') + +.value('$dateParserSuppressWarning', false) + +.service('dateParser', ['$log', '$dateParserSuppressWarning', 'uibDateParser', function($log, $dateParserSuppressWarning, uibDateParser) { + if (!$dateParserSuppressWarning) { + $log.warn('dateParser is now deprecated. Use uibDateParser instead.'); + } + + angular.extend(this, uibDateParser); +}]); diff --git a/src/dateparser/test/dateparser.spec.js b/src/dateparser/test/dateparser.spec.js index 6a1225bf01..fb8897c832 100644 --- a/src/dateparser/test/dateparser.spec.js +++ b/src/dateparser/test/dateparser.spec.js @@ -2,8 +2,8 @@ describe('date parser', function() { var dateParser; beforeEach(module('ui.bootstrap.dateparser')); - beforeEach(inject(function (_dateParser_) { - dateParser = _dateParser_; + beforeEach(inject(function (uibDateParser) { + dateParser = uibDateParser; })); function expectParse(input, format, date) { @@ -224,3 +224,34 @@ describe('date parser', function() { expect(dateParser.init).toHaveBeenCalled(); })); }); + +/* Deprecation tests below */ + +describe('date parser deprecation', function() { + beforeEach(module('ui.bootstrap.dateparser')); + + it('should suppress warning', function() { + module(function($provide) { + $provide.value('$dateParserSuppressWarning', true); + }); + + inject(function($log, dateParser) { + spyOn($log, 'warn'); + + dateParser.parse('01.10.2015', 'dd.MM.yyyy'); + + expect($log.warn.calls.count()).toBe(0); + }); + }); + + it('should give warning by default', inject(function($log) { + spyOn($log, 'warn'); + + inject(function(dateParser) { + dateParser.parse('01.10.2015', 'dd.MM.yyyy'); + + expect($log.warn.calls.count()).toBe(1); + expect($log.warn.calls.argsFor(0)).toEqual(['dateParser is now deprecated. Use uibDateParser instead.']); + }); + })); +}); diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index f6c35cd137..350da2e75c 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -492,7 +492,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst onOpenFocus: true }) -.directive('datepickerPopup', ['$compile', '$parse', '$document', '$rootScope', '$position', 'dateFilter', 'dateParser', 'datepickerPopupConfig', '$timeout', +.directive('datepickerPopup', ['$compile', '$parse', '$document', '$rootScope', '$position', 'dateFilter', 'uibDateParser', 'datepickerPopupConfig', '$timeout', function($compile, $parse, $document, $rootScope, $position, dateFilter, dateParser, datepickerPopupConfig, $timeout) { return { restrict: 'EA',