mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-03 04:29:28 +01:00
Better handling of date-times without times, prevent double-conversion to server time
This commit is contained in:
parent
aef04880e9
commit
caec90f104
@ -316,37 +316,50 @@ class importexport_import_csv implements importexport_iface_import_record { //,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach((array)$fields['date-time'] as $name) {
|
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
|
// Need to handle format first
|
||||||
if($format == 1)
|
if($format == 1)
|
||||||
{
|
{
|
||||||
$formatted = egw_time::createFromFormat(
|
$formatted = egw_time::createFromFormat(
|
||||||
'!'.egw_time::$user_dateformat . '*' .egw_time::$user_timeformat,
|
'!'.egw_time::$user_dateformat . ' ' .egw_time::$user_timeformat,
|
||||||
$record[$name]
|
$record[$name],
|
||||||
|
egw_time::$user_timezone
|
||||||
);
|
);
|
||||||
|
|
||||||
if(!$formatted && $errors = egw_time::getLastErrors())
|
if(!$formatted && $errors = egw_time::getLastErrors())
|
||||||
{
|
{
|
||||||
// Try again, more options
|
// Try again, without time
|
||||||
try {
|
$formatted = egw_time::createFromFormat(
|
||||||
$formatted = new egw_time($record[$name]);
|
'!'.egw_time::$user_dateformat,
|
||||||
} catch (Exception $e) {
|
trim($record[$name]),
|
||||||
$warnings[] = $name.': ' . $e->getMessage();
|
egw_time::$user_timezone
|
||||||
continue;
|
);
|
||||||
}
|
|
||||||
$errors = egw_time::getLastErrors();
|
if(!$formatted && $errors = egw_time::getLastErrors())
|
||||||
foreach($errors['errors'] as $char => $msg)
|
|
||||||
{
|
{
|
||||||
$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();
|
$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']) &&
|
if(is_array(self::$cf_parse_cache[$appname][0]['date-time']) &&
|
||||||
in_array($name, 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)
|
// 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] = $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']) &&
|
if(is_array(self::$cf_parse_cache[$appname][0]['date']) &&
|
||||||
in_array($name, 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)
|
// Custom fields stored in a particular format (from customfields_widget)
|
||||||
|
Loading…
Reference in New Issue
Block a user