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

Commit

Permalink
feat(dateparser): use uib- prefix
Browse files Browse the repository at this point in the history
Closes #4504
  • Loading branch information
wesleycho committed Oct 2, 2015
1 parent 298ec8c commit 0fa851f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/dateparser/dateparser.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
}]);
35 changes: 33 additions & 2 deletions src/dateparser/test/dateparser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.']);
});
}));
});
2 changes: 1 addition & 1 deletion src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 0fa851f

Please sign in to comment.