From e1c36b440b79a775da9ec973e645dc07c3168f69 Mon Sep 17 00:00:00 2001 From: Ihor Kroosh Date: Wed, 10 Dec 2014 12:46:37 +0200 Subject: [PATCH] added parsing of time like from 0315 => 03:15 --- jquery.datetimepicker.js | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/jquery.datetimepicker.js b/jquery.datetimepicker.js index b0d3de1..ad889c1 100644 --- a/jquery.datetimepicker.js +++ b/jquery.datetimepicker.js @@ -989,16 +989,28 @@ input .off('blur.xdsoft') .on('blur.xdsoft', function () { - if (options.allowBlank && !$.trim($(this).val()).length) { - $(this).val(null); - datetimepicker.data('xdsoft_datetime').empty(); - } else if (!Date.parseDate($(this).val(), options.format)) { - $(this).val((_xdsoft_datetime.now()).dateFormat(options.format)); - datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val()); - } else { - datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val()); - } - datetimepicker.trigger('changedatetime.xdsoft'); + if (options.allowBlank && !$.trim($(this).val()).length) { + $(this).val(null); + datetimepicker.data('xdsoft_datetime').empty(); + } else if (!Date.parseDate($(this).val(), options.format)) { + var splittedHours = +([$(this).val()[0], $(this).val()[1]].join('')), + splittedMinutes = +([$(this).val()[2], $(this).val()[3]].join('')); + + // parse the numbers as 0312 => 03:12 + if(!options.datepicker && options.timepicker && splittedHours >= 0 && splittedHours < 24 && splittedMinutes >= 0 && splittedMinutes < 60) { + $(this).val([splittedHours, splittedMinutes].map(function(item) { + return item > 9 ? item : '0' + item + }).join(':')); + } else { + $(this).val((_xdsoft_datetime.now()).dateFormat(options.format)); + } + + datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val()); + } else { + datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val()); + } + + datetimepicker.trigger('changedatetime.xdsoft'); }); } options.dayOfWeekStartPrev = (options.dayOfWeekStart === 0) ? 6 : options.dayOfWeekStart - 1;