From b97c58c016c0ee85745d5be7eed8f7fbca8179e5 Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 13 Sep 2023 15:10:36 -0600 Subject: [PATCH] Importexport: Fix filtering by date customfields Date customfields can have different data formats (default Y-m-d) and we were only considering timestamps --- importexport/inc/class.importexport_export_ui.inc.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/importexport/inc/class.importexport_export_ui.inc.php b/importexport/inc/class.importexport_export_ui.inc.php index aa99a70f8b..6e4abaeb7d 100644 --- a/importexport/inc/class.importexport_export_ui.inc.php +++ b/importexport/inc/class.importexport_export_ui.inc.php @@ -286,9 +286,15 @@ class importexport_export_ui { { unset($filter[$key]); } + // Format for date from/to + $date_format = 'ts'; + if($key[0] == Api\Storage::CF_PREFIX && ($cf = (Api\Storage\Customfields::get($_appname) ?: [])[substr($key, 1)])) + { + $date_format = $cf['values']['format'] ?? ($cf['type'] == 'date' ? 'Y-m-d' : "Y-m-d H:i:s"); + } if(is_array($value) && array_key_exists('from', $value) && $value['from']) { - $filter[$key]['from'] = Api\DateTime::to($value['from'],'ts'); + $filter[$key]['from'] = Api\DateTime::to($value['from'], $date_format); } // If user selects an end date, they most likely want entries including that date if(is_array($value) && array_key_exists('to',$value) && $value['to'] ) @@ -296,7 +302,7 @@ class importexport_export_ui { // Adjust time to 23:59:59 $filter[$key]['to'] = new Api\DateTime($value['to']); $filter[$key]['to']->setTime(23,59,59); - $filter[$key]['to'] = $filter[$key]['to']->format('ts'); + $filter[$key]['to'] = $filter[$key]['to']->format($date_format); } } }