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

feat(dateparser): use uib- prefix #4504

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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