Skip to content
Snippets Groups Projects
Commit b3f978ec authored by Jared Hancock's avatar Jared Hancock
Browse files

Honor system date format on custom date fields

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