Skip to content

Add returnType and returnFormat configuration options #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits 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
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-bootstrap-datetimepicker",
"version": "0.3.7",
"version": "0.3.7.1",
"description": "This directive allows you to add a datetime-picker to your form.",
"author": "https://github.com/dalelotts/angular-bootstrap-datetimepicker/graphs/contributors",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-bootstrap-datetimepicker",
"version": "0.3.7",
"version": "0.3.7.1",
"description": "This directive allows you to add a datetime-picker to your form elements.",
"author": "https://github.com/dalelotts/ng-bootstrap-datetimepicker/graphs/contributors",
"bugs": {
Expand Down
15 changes: 12 additions & 3 deletions src/js/datetimepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
dropdownSelector: null,
minuteStep: 5,
minView: 'minute',
startView: 'day'
startView: 'day',
returnType: 'date',
returnFormat: 'YYYY-MM-DD'
})
.directive('datetimepicker', ['$log', 'dateTimePickerConfig', function datetimepickerDirective($log, defaultConfig) {

Expand All @@ -50,7 +52,7 @@
}

var validateConfiguration = function validateConfiguration(configuration) {
var validOptions = ['startView', 'minView', 'minuteStep', 'dropdownSelector'];
var validOptions = ['startView', 'minView', 'minuteStep', 'dropdownSelector', 'returnType', 'returnFormat'];

for (var prop in configuration) {
//noinspection JSUnfilteredForInLoop
Expand All @@ -61,6 +63,7 @@

// Order of the elements in the validViews array is significant.
var validViews = ['minute', 'hour', 'day', 'month', 'year'];
var validReturnTypes = ['moment', 'date'];

if (validViews.indexOf(configuration.startView) < 0) {
throw ('invalid startView value: ' + configuration.startView);
Expand All @@ -83,6 +86,10 @@
if (configuration.dropdownSelector !== null && !angular.isString(configuration.dropdownSelector)) {
throw ('dropdownSelector must be a string');
}

if (validReturnTypes.indexOf(configuration.returnType) < 0) {
throw ("returnType must be either moment or date. Received: " + configuration.returnType);
}

/* istanbul ignore next */
if (configuration.dropdownSelector !== null && ((typeof jQuery === 'undefined') || (typeof jQuery().dropdown !== 'function'))) {
Expand Down Expand Up @@ -336,7 +343,9 @@

setTime: function setTime(unixDate) {
var tempDate = new Date(unixDate);
var newDate = new Date(tempDate.getTime() + (tempDate.getTimezoneOffset() * 60000));
var newDate = configuration.returnType === 'date'
? new Date(tempDate.getTime() + (tempDate.getTimezoneOffset() * 60000))
: moment(tempDate).format(configuration.returnFormat);

var oldDate = ngModelController.$modelValue;
ngModelController.$setViewValue(newDate);
Expand Down