From 947755676eabe3f281d12e8c9d42825d2c2d107d Mon Sep 17 00:00:00 2001 From: nathangray Date: Fri, 18 Sep 2020 10:06:04 -0600 Subject: [PATCH] ImportExport: Another fix for exporting custom date fields with custom format. - PHP base DateTime class was being used instead of our own Api\DateTime - User's preferred date format was not being respected - Custom formatting was only parsed if the first entry had a value in that field --- importexport/inc/class.importexport_export_csv.inc.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/importexport/inc/class.importexport_export_csv.inc.php b/importexport/inc/class.importexport_export_csv.inc.php index 104c2a9931..59f781b29b 100644 --- a/importexport/inc/class.importexport_export_csv.inc.php +++ b/importexport/inc/class.importexport_export_csv.inc.php @@ -246,16 +246,17 @@ class importexport_export_csv implements importexport_iface_export_record switch($c_field['type']) { case 'date': case 'date-time': - if ($c_field['values']['format'] && (is_array($record) ? $record[$name] : $record->$name)) + if ($c_field['values']['format']) { // Date has custom format. Convert so it's standard, don't do normal processing + $type = $c_field['type']; $format = $c_field['values']['format']; - $methods[$name] = function($val) use ($format) + $methods[$name] = function($val) use ($type, $format) { $date = Api\DateTime::createFromFormat($format, $val, Api\DateTime::$user_timezone); if($date) { - return $date->format(APi\DateTime::DATABASE); + return Api\DateTime::to($date, $type == 'date' ? true : ''); } }; }