Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable0.8] fix and improve detection and import of ods, xlsx and csv documents #1478

Merged
merged 11 commits into from
Nov 28, 2024
Merged
Prev Previous commit
Next Next commit
fix(Import): accept Y-m-d formatted dates, as from CSV
Signed-off-by: Arthur Schiwon <[email protected]>
blizzz committed Nov 27, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 4ffffd95606a6393342a8d669d1733628f00bf0d
20 changes: 17 additions & 3 deletions lib/Service/ImportService.php
Original file line number Diff line number Diff line change
@@ -368,9 +368,17 @@ private function createRow(Row $row): void {
$value = $cell->getValue();
$hasData = $hasData || !empty($value);
if ($column->getType() === 'datetime' && $column->getSubtype() === '') {
$value = Date::excelToDateTimeObject($value)->format('Y-m-d H:i');
try {
$value = Date::excelToDateTimeObject($value)->format('Y-m-d H:i');
} catch (\TypeError) {
$value = (new \DateTimeImmutable($value))->format('Y-m-d H:i');
}
} elseif ($column->getType() === 'datetime' && $column->getSubtype() === 'date') {
$value = Date::excelToDateTimeObject($value)->format('Y-m-d');
try {
$value = Date::excelToDateTimeObject($value)->format('Y-m-d');
} catch (\TypeError) {
$value = (new \DateTimeImmutable($value))->format('Y-m-d');
}
} elseif ($column->getType() === 'number' && $column->getNumberSuffix() === '%') {
$value = $value * 100;
} elseif ($column->getType() === 'selection' && $column->getSubtype() === 'check') {
@@ -482,7 +490,13 @@ private function parseColumnDataType(Cell $cell): array {
'subtype' => 'line',
];

if (Date::isDateTime($cell) || $originDataType === DataType::TYPE_ISO_DATE) {
try {
$dateValue = new \DateTimeImmutable($value);
} catch (\Exception $e) {
}
if ((isset($dateValue) && $originDataType === DataType::TYPE_STRING)
|| Date::isDateTime($cell)
|| $originDataType === DataType::TYPE_ISO_DATE) {
$dataType = [
'type' => 'datetime',
'subtype' => $cell->getCalculateDateTimeType() === Cell::CALCULATE_DATE_TIME_ASIS ? 'date' : '',