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

Commit fc02fd1

Browse files
committed
feat(datepicker): deprecate literal usage
- Deprecate support for non-date objects with the datepicker Closes #5658 Closes #5732
1 parent 4fe5d99 commit fc02fd1

File tree

4 files changed

+98
-6
lines changed

4 files changed

+98
-6
lines changed

src/datepicker/datepicker.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
22

33
.value('$datepickerSuppressError', false)
44

5+
.value('$datepickerLiteralWarning', true)
6+
57
.constant('uibDatepickerConfig', {
68
datepickerMode: 'day',
79
formatDay: 'dd',
@@ -21,8 +23,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
2123
yearRows: 4
2224
})
2325

24-
.controller('UibDatepickerController', ['$scope', '$attrs', '$parse', '$interpolate', '$locale', '$log', 'dateFilter', 'uibDatepickerConfig', '$datepickerSuppressError', 'uibDateParser',
25-
function($scope, $attrs, $parse, $interpolate, $locale, $log, dateFilter, datepickerConfig, $datepickerSuppressError, dateParser) {
26+
.controller('UibDatepickerController', ['$scope', '$attrs', '$parse', '$interpolate', '$locale', '$log', 'dateFilter', 'uibDatepickerConfig', '$datepickerLiteralWarning', '$datepickerSuppressError', 'uibDateParser',
27+
function($scope, $attrs, $parse, $interpolate, $locale, $log, dateFilter, datepickerConfig, $datepickerLiteralWarning, $datepickerSuppressError, dateParser) {
2628
var self = this,
2729
ngModelCtrl = { $setViewValue: angular.noop }, // nullModelCtrl;
2830
ngModelOptions = {},
@@ -99,6 +101,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
99101
if (angular.isDate(value)) {
100102
self[key] = dateParser.fromTimezone(new Date(value), ngModelOptions.timezone);
101103
} else {
104+
if ($datepickerLiteralWarning) {
105+
$log.warn('Literal date support has been deprecated, please switch to date object usage');
106+
}
107+
102108
self[key] = new Date(dateFilter(value, 'medium'));
103109
}
104110
} else {

src/datepicker/docs/readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Apart from the previous settings, to configure the uib-datepicker you need to cr
8484
<small class="badge">C</small>
8585
<i class="glyphicon glyphicon-eye-open"></i>
8686
_(Default: `null`)_ -
87-
Defines the maximum available date.
87+
Defines the maximum available date. Requires a Javascript Date object.
8888

8989
* `maxMode`
9090
<small class="badge">C</small>
@@ -96,7 +96,7 @@ Apart from the previous settings, to configure the uib-datepicker you need to cr
9696
<small class="badge">C</small>
9797
<i class="glyphicon glyphicon-eye-open"></i>
9898
_(Default: `null`)_ -
99-
Defines the minimum available date.
99+
Defines the minimum available date. Requires a Javascript Date object.
100100

101101
* `minMode`
102102
<small class="badge">C</small>

src/datepicker/test/datepicker.spec.js

+80
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,86 @@ describe('datepicker', function() {
139139
element.trigger(e);
140140
}
141141

142+
describe('$datepickerLiteralWarning', function() {
143+
var $compile,
144+
$log,
145+
$scope;
146+
147+
it('should warn when using literals for min date by default', function() {
148+
inject(function(_$log_, _$rootScope_, _$compile_) {
149+
$log = _$log_;
150+
$scope = _$rootScope_.$new();
151+
$compile = _$compile_;
152+
});
153+
154+
spyOn($log, 'warn');
155+
$scope.options = {
156+
minDate: '1984-01-01'
157+
};
158+
element = $compile('<uib-datepicker ng-model="locals.date" datepicker-options="options"></uib-datepicker>')($scope);
159+
$scope.$digest();
160+
161+
expect($log.warn).toHaveBeenCalledWith('Literal date support has been deprecated, please switch to date object usage');
162+
});
163+
164+
it('should suppress warning when using literals for min date', function() {
165+
module(function($provide) {
166+
$provide.value('$datepickerLiteralWarning', false);
167+
});
168+
inject(function(_$log_, _$rootScope_, _$compile_) {
169+
$log = _$log_;
170+
$scope = _$rootScope_.$new();
171+
$compile = _$compile_;
172+
});
173+
174+
spyOn($log, 'warn');
175+
$scope.options = {
176+
minDate: '1984-01-01'
177+
};
178+
element = $compile('<uib-datepicker ng-model="locals.date" datepicker-options="options"></uib-datepicker>')($scope);
179+
$scope.$digest();
180+
181+
expect($log.warn).not.toHaveBeenCalled();
182+
});
183+
184+
it('should warn when using literals for max date by default', function() {
185+
inject(function(_$log_, _$rootScope_, _$compile_) {
186+
$log = _$log_;
187+
$scope = _$rootScope_.$new();
188+
$compile = _$compile_;
189+
});
190+
191+
spyOn($log, 'warn');
192+
$scope.options = {
193+
maxDate: '1984-01-01'
194+
};
195+
element = $compile('<uib-datepicker ng-model="locals.date" datepicker-options="options"></uib-datepicker>')($scope);
196+
$scope.$digest();
197+
198+
expect($log.warn).toHaveBeenCalledWith('Literal date support has been deprecated, please switch to date object usage');
199+
});
200+
201+
it('should suppress warning when using literals for max date', function() {
202+
module(function($provide) {
203+
$provide.value('$datepickerLiteralWarning', false);
204+
});
205+
inject(function(_$log_, _$rootScope_, _$compile_) {
206+
$log = _$log_;
207+
$scope = _$rootScope_.$new();
208+
$compile = _$compile_;
209+
});
210+
211+
spyOn($log, 'warn');
212+
$scope.options = {
213+
maxDate: '1984-01-01'
214+
};
215+
element = $compile('<uib-datepicker ng-model="locals.date" datepicker-options="options"></uib-datepicker>')($scope);
216+
$scope.$digest();
217+
218+
expect($log.warn).not.toHaveBeenCalled();
219+
});
220+
});
221+
142222
describe('$datepickerSuppressError', function() {
143223
var $compile,
144224
$log,

src/datepickerPopup/popup.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
angular.module('ui.bootstrap.datepickerPopup', ['ui.bootstrap.datepicker', 'ui.bootstrap.position'])
22

3+
.value('$datepickerPopupLiteralWarning', true)
4+
35
.constant('uibDatepickerPopupConfig', {
46
altInputFormats: [],
57
appendToBody: false,
@@ -20,8 +22,8 @@ angular.module('ui.bootstrap.datepickerPopup', ['ui.bootstrap.datepicker', 'ui.b
2022
placement: 'auto bottom-left'
2123
})
2224

23-
.controller('UibDatepickerPopupController', ['$scope', '$element', '$attrs', '$compile', '$log', '$parse', '$window', '$document', '$rootScope', '$uibPosition', 'dateFilter', 'uibDateParser', 'uibDatepickerPopupConfig', '$timeout', 'uibDatepickerConfig',
24-
function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $rootScope, $position, dateFilter, dateParser, datepickerPopupConfig, $timeout, datepickerConfig) {
25+
.controller('UibDatepickerPopupController', ['$scope', '$element', '$attrs', '$compile', '$log', '$parse', '$window', '$document', '$rootScope', '$uibPosition', 'dateFilter', 'uibDateParser', 'uibDatepickerPopupConfig', '$timeout', 'uibDatepickerConfig', '$datepickerPopupLiteralWarning',
26+
function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $rootScope, $position, dateFilter, dateParser, datepickerPopupConfig, $timeout, datepickerConfig, $datepickerPopupLiteralWarning) {
2527
var cache = {},
2628
isHtml5DateInput = false;
2729
var dateFormat, closeOnDateSelection, appendToBody, onOpenFocus,
@@ -203,6 +205,10 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $
203205
} else if (angular.isDate($scope.datepickerOptions[key])) {
204206
dates[key] = dateParser.fromTimezone(new Date($scope.datepickerOptions[key]), timezone);
205207
} else {
208+
if ($datepickerPopupLiteralWarning) {
209+
$log.warn('Literal date support has been deprecated, please switch to date object usage');
210+
}
211+
206212
dates[key] = new Date(dateFilter($scope.datepickerOptions[key], 'medium'));
207213
}
208214
});

0 commit comments

Comments
 (0)