From 1b30ed387050a88e2a167627033a011bb0db7741 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 24 Apr 2012 14:36:31 +0000 Subject: [PATCH] - Test multiple options for date format, stop when one works - Avoid deprecated format_datetime(), only format if there is a value --- etemplate/inc/class.bo_merge.inc.php | 37 +++++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/etemplate/inc/class.bo_merge.inc.php b/etemplate/inc/class.bo_merge.inc.php index bcf9343169..283a7f739f 100644 --- a/etemplate/inc/class.bo_merge.inc.php +++ b/etemplate/inc/class.bo_merge.inc.php @@ -197,7 +197,7 @@ abstract class bo_merge switch($name) { case 'created': case 'modified': - $value = $this->format_datetime($value); + if($value) $value = egw_time::to($value); break; case 'bday': if ($value) @@ -375,6 +375,7 @@ abstract class bo_merge */ protected function format_datetime($time,$format=null) { + trigger_error(__METHOD__ . ' is deprecated, use egw_time::to($time, $format)', E_USER_DEPRECATED); if (is_null($format)) $format = $this->datetime_format; return egw_time::to($time,$format); @@ -1045,6 +1046,13 @@ abstract class bo_merge //'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'//Excel WTF ))) return; + // Some different formats dates could be in, depending what they've been through + $formats = array( + '!'.egw_time::$user_dateformat . ' ' .egw_time::$user_timeformat.':s', + '!'.egw_time::$user_dateformat . '* ' .egw_time::$user_timeformat, + '!'.egw_time::$user_dateformat . '*', + ); + // Properly format values for spreadsheet foreach($names as $idx => &$field) { @@ -1054,16 +1062,27 @@ abstract class bo_merge { if(!is_numeric($values[$key])) { - try { - $date = egw_time::createFromFormat( - '!'.egw_time::$user_dateformat . ' ' .egw_time::$user_timeformat.':s', - $values[$key], - egw_time::$user_timezone - ); - } catch (Exception $e) { + // Try the different formats, stop when one works + foreach($formats as $f) + { + try { + $date = egw_time::createFromFormat( + $f, + $values[$key], + egw_time::$user_timezone + ); + if($date) break; + } catch (Exception $e) { + + } + } + if(!$date) + { // Couldn't get a date out of it... skip it trigger_error("Unable to parse date $key = '{$values[$key]}' - left as text", E_USER_NOTICE); - } + unset($names[$idx]); + continue; + } } else {