|
28 | 28 | dropdownSelector: null,
|
29 | 29 | minuteStep: 5,
|
30 | 30 | minView: 'minute',
|
31 |
| - startView: 'day' |
| 31 | + startView: 'day', |
| 32 | + returnType: 'date', |
| 33 | + returnFormat: 'YYYY-MM-DD' |
32 | 34 | })
|
33 | 35 | .directive('datetimepicker', ['$log', 'dateTimePickerConfig', function datetimepickerDirective($log, defaultConfig) {
|
34 | 36 |
|
|
50 | 52 | }
|
51 | 53 |
|
52 | 54 | var validateConfiguration = function validateConfiguration(configuration) {
|
53 |
| - var validOptions = ['startView', 'minView', 'minuteStep', 'dropdownSelector']; |
| 55 | + var validOptions = ['startView', 'minView', 'minuteStep', 'dropdownSelector', 'returnType', 'returnFormat']; |
54 | 56 |
|
55 | 57 | for (var prop in configuration) {
|
56 | 58 | //noinspection JSUnfilteredForInLoop
|
|
61 | 63 |
|
62 | 64 | // Order of the elements in the validViews array is significant.
|
63 | 65 | var validViews = ['minute', 'hour', 'day', 'month', 'year'];
|
| 66 | + var validReturnTypes = ['moment', 'date']; |
64 | 67 |
|
65 | 68 | if (validViews.indexOf(configuration.startView) < 0) {
|
66 | 69 | throw ('invalid startView value: ' + configuration.startView);
|
|
83 | 86 | if (configuration.dropdownSelector !== null && !angular.isString(configuration.dropdownSelector)) {
|
84 | 87 | throw ('dropdownSelector must be a string');
|
85 | 88 | }
|
| 89 | + |
| 90 | + if (validReturnTypes.indexOf(configuration.returnType) < 0) { |
| 91 | + throw ("returnType must be either moment or date. Received: " + configuration.returnType); |
| 92 | + } |
86 | 93 |
|
87 | 94 | /* istanbul ignore next */
|
88 | 95 | if (configuration.dropdownSelector !== null && ((typeof jQuery === 'undefined') || (typeof jQuery().dropdown !== 'function'))) {
|
|
336 | 343 |
|
337 | 344 | setTime: function setTime(unixDate) {
|
338 | 345 | var tempDate = new Date(unixDate);
|
339 |
| - var newDate = new Date(tempDate.getTime() + (tempDate.getTimezoneOffset() * 60000)); |
| 346 | + var newDate = configuration.returnType === 'date' |
| 347 | + ? new Date(tempDate.getTime() + (tempDate.getTimezoneOffset() * 60000)) |
| 348 | + : moment(newDate).format(configuration.returnFormat); |
340 | 349 |
|
341 | 350 | var oldDate = ngModelController.$modelValue;
|
342 | 351 | ngModelController.$setViewValue(newDate);
|
|
0 commit comments