diff --git a/src/PhpSpreadsheet/Document/Properties.php b/src/PhpSpreadsheet/Document/Properties.php index 1030d98cc9..99e66756c2 100644 --- a/src/PhpSpreadsheet/Document/Properties.php +++ b/src/PhpSpreadsheet/Document/Properties.php @@ -172,6 +172,8 @@ private static function intOrFloatTimestamp($timestamp) $timestamp = (float) $timestamp; } else { $timestamp = preg_replace('/[.][0-9]*$/', '', $timestamp) ?? ''; + $timestamp = preg_replace('/^(\\d{4})- (\\d)/', '$1-0$2', $timestamp) ?? ''; + $timestamp = preg_replace('/^(\\d{4}-\\d{2})- (\\d)/', '$1-0$2', $timestamp) ?? ''; $timestamp = (float) (new DateTime($timestamp))->format('U'); } } diff --git a/src/PhpSpreadsheet/Reader/Xlsx/Properties.php b/src/PhpSpreadsheet/Reader/Xlsx/Properties.php index fb341f71f5..82b5172b58 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx/Properties.php +++ b/src/PhpSpreadsheet/Reader/Xlsx/Properties.php @@ -52,8 +52,8 @@ public function readCoreProperties(string $propertyData): void $this->docProps->setCreator((string) self::getArrayItem($xmlCore->xpath('dc:creator'))); $this->docProps->setLastModifiedBy((string) self::getArrayItem($xmlCore->xpath('cp:lastModifiedBy'))); - $this->docProps->setCreated((int) strtotime((string) self::getArrayItem($xmlCore->xpath('dcterms:created')))); //! respect xsi:type - $this->docProps->setModified((int) strtotime((string) self::getArrayItem($xmlCore->xpath('dcterms:modified')))); //! respect xsi:type + $this->docProps->setCreated((string) self::getArrayItem($xmlCore->xpath('dcterms:created'))); //! respect xsi:type + $this->docProps->setModified((string) self::getArrayItem($xmlCore->xpath('dcterms:modified'))); //! respect xsi:type $this->docProps->setTitle((string) self::getArrayItem($xmlCore->xpath('dc:title'))); $this->docProps->setDescription((string) self::getArrayItem($xmlCore->xpath('dc:description'))); $this->docProps->setSubject((string) self::getArrayItem($xmlCore->xpath('dc:subject'))); diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue2331Test.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue2331Test.php new file mode 100644 index 0000000000..afa2ff5240 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue2331Test.php @@ -0,0 +1,26 @@ +load($filename); + $properties = $spreadsheet->getProperties(); + $created = (string) $properties->getCreated(); + $modified = (string) $properties->getModified(); + + self::assertEquals('2021-08-02', Date::formattedDateTimeFromTimestamp($created, 'Y-m-d', new DateTimeZone('UTC'))); + self::assertEquals('2021-09-03', Date::formattedDateTimeFromTimestamp($modified, 'Y-m-d', new DateTimeZone('UTC'))); + $spreadsheet->disconnectWorksheets(); + } +} diff --git a/tests/data/Reader/XLSX/issue.2331c.xlsx b/tests/data/Reader/XLSX/issue.2331c.xlsx new file mode 100644 index 0000000000..0f069bcd8c Binary files /dev/null and b/tests/data/Reader/XLSX/issue.2331c.xlsx differ