Skip to content

Commit a67ba6e

Browse files
committed
fix(Import): distinguish between date only and date time on xlsx imports
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
1 parent a3e0833 commit a67ba6e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/Service/ColumnTypes/DatetimeDateBusiness.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class DatetimeDateBusiness extends SuperBusiness implements IColumnTypeBusiness
1717
* @return string
1818
*/
1919
public function parseValue($value, ?Column $column = null): string {
20-
return json_encode($this->isValidDate($value, 'Y-m-d') ? $value : '');
20+
return json_encode($this->isValidDate((string)$value, 'Y-m-d') ? (string)$value : '');
2121
}
2222

2323
/**
@@ -26,7 +26,7 @@ public function parseValue($value, ?Column $column = null): string {
2626
* @return bool
2727
*/
2828
public function canBeParsed($value, ?Column $column = null): bool {
29-
return $this->isValidDate($value, 'Y-m-d');
29+
return $this->isValidDate((string)$value, 'Y-m-d');
3030
}
3131

3232
}

lib/Service/ImportService.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private function getPreviewData(Worksheet $worksheet): array {
136136
$columns[] = [
137137
'title' => $title,
138138
'type' => $this->rawColumnDataTypes[$colIndex]['type'],
139-
'subtype' => $this->rawColumnDataTypes[$colIndex]['subtype'],
139+
'subtype' => $this->rawColumnDataTypes[$colIndex]['subtype'] ?? null,
140140
'numberDecimals' => $this->rawColumnDataTypes[$colIndex]['number_decimals'] ?? 0,
141141
'numberPrefix' => $this->rawColumnDataTypes[$colIndex]['number_prefix'] ?? '',
142142
'numberSuffix' => $this->rawColumnDataTypes[$colIndex]['number_suffix'] ?? '',
@@ -367,8 +367,10 @@ private function createRow(Row $row): void {
367367

368368
$value = $cell->getValue();
369369
$hasData = $hasData || !empty($value);
370-
if ($column->getType() === 'datetime') {
370+
if ($column->getType() === 'datetime' && $column->getSubtype() === '') {
371371
$value = Date::excelToDateTimeObject($value)->format('Y-m-d H:i');
372+
} elseif ($column->getType() === 'datetime' && $column->getSubtype() === 'date') {
373+
$value = Date::excelToDateTimeObject($value)->format('Y-m-d');
372374
} elseif ($column->getType() === 'number' && $column->getNumberSuffix() === '%') {
373375
$value = $value * 100;
374376
} elseif ($column->getType() === 'selection' && $column->getSubtype() === 'check') {
@@ -477,6 +479,7 @@ private function parseColumnDataType(Cell $cell): array {
477479
if (Date::isDateTime($cell) || $originDataType === DataType::TYPE_ISO_DATE) {
478480
$dataType = [
479481
'type' => 'datetime',
482+
'subtype' => $cell->getCalculateDateTimeType() === Cell::CALCULATE_DATE_TIME_ASIS ? 'date' : '',
480483
];
481484
} elseif ($originDataType === DataType::TYPE_NUMERIC) {
482485
if (str_contains($formattedValue, '%')) {

0 commit comments

Comments
 (0)