From 8ef7956b230d4cdc221cd740d55fd8b4c0f74440 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Thu, 22 May 2014 21:29:46 +0000 Subject: [PATCH] bug: Fix date formatting issues --- include/class.forms.php | 10 ++------- scp/js/scp.js | 48 ++++++++++++++++++++--------------------- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/include/class.forms.php b/include/class.forms.php index 586309465..7b5fab20a 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -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; diff --git a/scp/js/scp.js b/scp/js/scp.js index d77060212..6da384df2 100644 --- a/scp/js/scp.js +++ b/scp/js/scp.js @@ -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 *****************/ -- GitLab