From caec90f104e5c52ccc30aa7b5b44d744039f28ac Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 7 Feb 2012 20:49:38 +0000 Subject: [PATCH] Better handling of date-times without times, prevent double-conversion to server time --- .../inc/class.importexport_import_csv.inc.php | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/importexport/inc/class.importexport_import_csv.inc.php b/importexport/inc/class.importexport_import_csv.inc.php index c7e540c1d3..0b99149026 100755 --- a/importexport/inc/class.importexport_import_csv.inc.php +++ b/importexport/inc/class.importexport_import_csv.inc.php @@ -316,37 +316,50 @@ class importexport_import_csv implements importexport_iface_import_record { //, } } foreach((array)$fields['date-time'] as $name) { - if ($record[$name] && !is_numeric($record[$name])) { + if ($record[$name] && !is_numeric($record[$name])) + { // Need to handle format first if($format == 1) { $formatted = egw_time::createFromFormat( - '!'.egw_time::$user_dateformat . '*' .egw_time::$user_timeformat, - $record[$name] + '!'.egw_time::$user_dateformat . ' ' .egw_time::$user_timeformat, + $record[$name], + egw_time::$user_timezone ); if(!$formatted && $errors = egw_time::getLastErrors()) { - // Try again, more options - try { - $formatted = new egw_time($record[$name]); - } catch (Exception $e) { - $warnings[] = $name.': ' . $e->getMessage(); - continue; - } - $errors = egw_time::getLastErrors(); - foreach($errors['errors'] as $char => $msg) + // Try again, without time + $formatted = egw_time::createFromFormat( + '!'.egw_time::$user_dateformat, + trim($record[$name]), + egw_time::$user_timezone + ); + + if(!$formatted && $errors = egw_time::getLastErrors()) { - $warnings[] = "$name: [$char] $msg"; + // Try again, anything goes + try { + $formatted = new egw_time($record[$name]); + } catch (Exception $e) { + $warnings[] = $name.': ' . $e->getMessage(); + continue; + } + $errors = egw_time::getLastErrors(); + foreach($errors['errors'] as $char => $msg) + { + $warnings[] = "$name: [$char] $msg"; + } } } - if($errors = egw_time::getLastErrors() && $errors['error_count'] == 0) + if($formatted) { $record[$name] = $formatted->getTimestamp(); + // Timestamp is apparently in server time, but apps will do the same conversion + $record[$name] = egw_time::server2user($record[$name],'ts'); } } - $record[$name] = egw_time::user2server($record[$name],'ts'); if(is_array(self::$cf_parse_cache[$appname][0]['date-time']) && in_array($name, self::$cf_parse_cache[$appname][0]['date-time'])) { // Custom fields stored in a particular format (from customfields_widget) @@ -365,7 +378,7 @@ class importexport_import_csv implements importexport_iface_import_record { //, $record[$name] = $formatted->getTimestamp(); } } - $record[$name] = egw_time::user2server($record[$name],'ts'); + $record[$name] = egw_time::server2user($record[$name],'ts'); if(is_array(self::$cf_parse_cache[$appname][0]['date']) && in_array($name, self::$cf_parse_cache[$appname][0]['date'])) { // Custom fields stored in a particular format (from customfields_widget)