Skip to content
Snippets Groups Projects
Commit 8ef7956b authored by Peter Rotich's avatar Peter Rotich
Browse files

bug: Fix date formatting issues

parent 9b8ebe22
No related branches found
No related tags found
No related merge requests found
......@@ -26,9 +26,6 @@ class Form {
var $_errors = null;
var $_source = false;
function Form() {
call_user_func_array(array($this, '__construct'), func_get_args());
}
function __construct($fields=array(), $source=null, $options=array()) {
$this->fields = $fields;
foreach ($fields as $f)
......@@ -1193,11 +1190,8 @@ class DatetimePickerWidget extends Widget {
$data = $this->field->getSource();
$config = $this->field->getConfiguration();
if ($datetime = parent::getValue()) {
$datetime = (is_int($datetime) ? $datetime :
(($dt = DateTime::createFromFormat($cfg->getDateFormat() . ' G:i',
$datetime . ' 00:00'))
? (int) $dt->format('U') : false)
);
$datetime = is_int($datetime) ? $datetime :
strtotime($datetime);
if ($datetime && isset($data[$this->name . ':time'])) {
list($hr, $min) = explode(':', $data[$this->name . ':time']);
$datetime += $hr * 3600 + $min * 60;
......
......@@ -246,22 +246,18 @@ var scp_prep = function() {
.fail(function() { });
});
/* Multifile uploads */
var elems = $('.multifile');
if (elems.exists()) {
/* Get config settings from the backend */
getConfig().then(function(c) {
elems.multifile({
container: '.uploads',
max_uploads: c.max_file_uploads || 1,
file_types: c.file_types || ".*",
max_file_size: c.max_file_size || 0
});
});
}
/* Datepicker */
/* Get config settings from the backend */
getConfig().then(function(c) {
// Multifile uploads
$('.multifile').multifile({
container: '.uploads',
max_uploads: c.max_file_uploads || 1,
file_types: c.file_types || ".*",
max_file_size: c.max_file_size || 0
});
// Datepicker
$('.dp').datepicker({
numberOfMonths: 2,
showButtonPanel: true,
......@@ -269,17 +265,7 @@ var scp_prep = function() {
showOn:'both',
dateFormat: $.translate_format(c.date_format||'m/d/Y')
});
$(document).on('submit', 'form', function() {
$('.dp', $(this)).each(function(i, e) {
var $e = $(e),
d = $e.datepicker('getDate');
if (!d) return;
var day = ('0'+d.getDate()).substr(-2),
month = ('0'+(d.getMonth()+1)).substr(-2),
year = d.getFullYear();
$e.val(year+'-'+month+'-'+day);
});
});
});
/* Typeahead tickets lookup */
......@@ -463,6 +449,18 @@ var scp_prep = function() {
$(document).ready(scp_prep);
$(document).on('pjax:complete', scp_prep);
$(document).on('submit', 'form', function() {
// Reformat dates
$('.dp', $(this)).each(function(i, e) {
var $e = $(e),
d = $e.datepicker('getDate');
if (!d) return;
var day = ('0'+d.getDate()).substr(-2),
month = ('0'+(d.getMonth()+1)).substr(-2),
year = d.getFullYear();
$e.val(year+'-'+month+'-'+day);
});
});
/************ global inits *****************/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment