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

Merge pull request #97 from greezybacon/issue/custom-date-field-format


Honor system date format on custom date fields

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents b62c64fa b3f978ec
No related branches found
No related tags found
No related merge requests found
......@@ -906,21 +906,24 @@ class CheckboxWidget extends Widget {
class DatetimePickerWidget extends Widget {
function render() {
global $cfg;
$config = $this->field->getConfiguration();
if ($this->value) {
$this->value = (is_int($this->value) ? $this->value :
strtotime($this->value));
DateTime::createFromFormat($cfg->getDateFormat(), $this->value)
->format('U'));
if ($config['gmt'])
$this->value += 3600 *
$_SESSION['TZ_OFFSET']+($_SESSION['TZ_DST']?date('I',$this->value):0);
list($hr, $min) = explode(':', date('H:i', $this->value));
$this->value = date('m/d/Y', $this->value);
$this->value = date($cfg->getDateFormat(), $this->value);
}
?>
<input type="text" name="<?php echo $this->name; ?>"
value="<?php echo Format::htmlchars($this->value); ?>" size="12"
autocomplete="off" />
autocomplete="off" class="dp" />
<script type="text/javascript">
$(function() {
$('input[name="<?php echo $this->name; ?>"]').datepicker({
......@@ -935,7 +938,8 @@ class DatetimePickerWidget extends Widget {
numberOfMonths: 2,
showButtonPanel: true,
buttonImage: './images/cal.png',
showOn:'both'
showOn:'both',
dateFormat: $.translate_format(<?php echo $cfg->getDateFormat(); ?>),
});
});
</script>
......
......@@ -265,28 +265,31 @@ $(document).ready(function(){
});
}
/* Datepicker */
getConfig().then(function(c) {
var df = c.date_format||'m/d/Y',
translation = {
'd':'dd',
'j':'d',
'z':'o',
'm':'mm',
'F':'MM',
'n':'m',
'Y':'yy'
};
$.translate_format = function(str) {
var translation = {
'd':'dd',
'j':'d',
'z':'o',
'm':'mm',
'F':'MM',
'n':'m',
'Y':'yy'
};
// Change PHP formats to datepicker ones
$.each(translation, function(php, jqdp) {
df = df.replace(php, jqdp);
str = str.replace(php, jqdp);
});
return str;
};
/* Datepicker */
getConfig().then(function(c) {
$('.dp').datepicker({
numberOfMonths: 2,
showButtonPanel: true,
buttonImage: './images/cal.png',
showOn:'both',
dateFormat: df,
dateFormat: $.translate_format(c.date_format||'m/d/Y'),
});
$(document).on('submit', 'form', function() {
$('.dp', $(this)).each(function(i, e) {
......
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