From 9748cf96be72240abb4e211bfdbfa86d13b326bb Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 8 May 2007 07:38:36 +0000 Subject: [PATCH] fix for bug #700: Date format d-M-Y not working in Infolog list display --- etemplate/inc/class.date_widget.inc.php | 13 ++++++++++++- phpgwapi/inc/class.jscalendar.inc.php | 10 ++++++++-- phpgwapi/inc/jscalendar-setup.php | 12 +++++++----- phpgwapi/js/jscalendar/calendar.js | 5 ++++- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/etemplate/inc/class.date_widget.inc.php b/etemplate/inc/class.date_widget.inc.php index 9950d36c09..eb20b5c978 100644 --- a/etemplate/inc/class.date_widget.inc.php +++ b/etemplate/inc/class.date_widget.inc.php @@ -164,7 +164,18 @@ } if ($value['m'] && strchr($this->dateformat,'M') !== false) { - $value['M'] = substr(lang(adodb_date('F',$value['m'])),0,3); + static $month = array('','January','February','March','April','Mai','June','July','August','September','October','November','December'); + static $substr; + if (is_null($substr)) $substr = function_exists('mb_substr') ? 'mb_substr' : 'substr'; + static $chars_shortcut; + if (is_null($chars_shortcut)) $chars_shortcut = (int)lang('3 number of chars for month-shortcut'); // < 0 to take the chars from the end + + $value['M'] = lang(substr($month[$value['m']],0,3)); // check if we have a translation of the short-cut + if ($substr($value['M'],-1) == '*') // if not generate one by truncating the translation of the long name + { + $value['M'] = $chars_shortcut > 0 ? $substr(lang($month[$value['m']]),0,$chars_shortcut) : + $substr(lang($month[$value['m']]),$chars_shortcut); + } } if ($readonly) // is readonly { diff --git a/phpgwapi/inc/class.jscalendar.inc.php b/phpgwapi/inc/class.jscalendar.inc.php index cc70265a4a..1f4ab99a35 100644 --- a/phpgwapi/inc/class.jscalendar.inc.php +++ b/phpgwapi/inc/class.jscalendar.inc.php @@ -83,10 +83,16 @@ class jscalendar $date = adodb_date($this->dateformat,$ts = adodb_mktime(12,0,0,$month,$day,$year)); if (strpos($this->dateformat,'M') !== false) { + static $substr; + if (is_null($substr)) $substr = function_exists('mb_substr') ? 'mb_substr' : 'substr'; + static $chars_shortcut; + if (is_null($chars_shortcut)) $chars_shortcut = (int)lang('3 number of chars for month-shortcut'); // < 0 to take the chars from the end + $short = lang(adodb_date('M',$ts)); // check if we have a translation of the short-cut - if (substr($short,-1) == '*') // if not generate one by truncating the translation of the long name + if ($substr($short,-1) == '*') // if not generate one by truncating the translation of the long name { - $short = substr(lang(adodb_date('F',$ts)),0,(int) lang('3 number of chars for month-shortcut')); + $short = $chars_shortcut > 0 ? $substr(lang(adodb_date('F',$ts)),0,$chars_shortcut) : + $substr(lang(adodb_date('F',$ts)),$chars_shortcut); } $date = str_replace(adodb_date('M',$ts),$short,$date); } diff --git a/phpgwapi/inc/jscalendar-setup.php b/phpgwapi/inc/jscalendar-setup.php index 1d4e7a6cad..e6a71b00c5 100644 --- a/phpgwapi/inc/jscalendar-setup.php +++ b/phpgwapi/inc/jscalendar-setup.php @@ -255,11 +255,13 @@ foreach($day2int as $name => $n) Calendar._SDN = new Array ( $n) { - echo "\n \"".($chars_shortcut > 0 ? substr(lang($name),0,$chars_shortcut) : - substr(lang($name),$chars_shortcut)).'"'.($n < 6 ? ',' : ''); + echo "\n \"".($chars_shortcut > 0 ? $substr(lang($name),0,$chars_shortcut) : + $substr(lang($name),$chars_shortcut)).'"'.($n < 6 ? ',' : ''); } ?>); Calendar._SDN_len = ; @@ -276,13 +278,13 @@ foreach($monthnames as $n => $name) Calendar._SMN = new Array ( $name) { $short = lang(substr($name,0,3)); // test if our lang-file have a translation for the english short with 3 chars - if (substr($short,-1) == '*') // else create one by truncating the full translation to x chars + if ($substr($short,-1) == '*') // else create one by truncating the full translation to x chars { - $chars_shortcut = (int)lang('3 number of chars for month-shortcut'); // < 0 to take the chars from the end - $short = $chars_shortcut > 0 ? substr(lang($name),0,$chars_shortcut) : substr(lang($name),$chars_shortcut); + $short = $chars_shortcut > 0 ? $substr(lang($name),0,$chars_shortcut) : $substr(lang($name),$chars_shortcut); } echo "\n \"".$short.'"'.($n < 11 ? ',' : ''); } diff --git a/phpgwapi/js/jscalendar/calendar.js b/phpgwapi/js/jscalendar/calendar.js index c4d7e71a5c..ccdcb58e55 100644 --- a/phpgwapi/js/jscalendar/calendar.js +++ b/phpgwapi/js/jscalendar/calendar.js @@ -61,6 +61,8 @@ Calendar = function (firstDayOfWeek, dateStr, onSelected, onClose) { ar[--i] = Calendar._DN[i].substr(0, Calendar._SDN_len); } Calendar._SDN = ar; + } + if (typeof Calendar._SMN == "undefined") { // table of short month names if (typeof Calendar._SMN_len == "undefined") Calendar._SMN_len = 3; @@ -1438,7 +1440,8 @@ Calendar.prototype.parseDate = function (str, fmt) { var y = 0; var m = -1; var d = 0; - var a = str.split(/\W+/); +// var a = str.split(/\W+/); does not work with multibyte chars, eg. german umlauts under utf-8 + var a = str.split(/[./-]/); if (!fmt) { fmt = this.dateFormat; }