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

On load excel - Document properties setCreated error #2331

Closed
gorbertous opened this issue Oct 12, 2021 · 2 comments
Closed

On load excel - Document properties setCreated error #2331

gorbertous opened this issue Oct 12, 2021 · 2 comments

Comments

@gorbertous
Copy link

This is:

- [ x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

e.g. $reader = IOFactory::createReaderForFile($some_file_path);
$spreadsheet = $reader->load($some_file_path);

should load excel file, but it fails because the date created is not in a correct format

What is the current behavior?

error: DateTime::__construct(): Failed to parse time string (2021- 9-13T13:24:38Z) at position 4 (-): Unexpected character

What are the steps to reproduce?

Error path : ROOT/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Document/Properties.php
Error thrown - see the code with stars

private static function intOrFloatTimestamp($timestamp)
    {
        if ($timestamp === null) {
            $timestamp = (float) (new DateTime())->format('U');
        } elseif (is_string($timestamp)) {
            if (is_numeric($timestamp)) {
                $timestamp = (float) $timestamp;
            } else {
                $timestamp = preg_replace('/[.][0-9]*$/', '', $timestamp) ?? '';
                **$timestamp = (float) (new DateTime($timestamp))->format('U');**
            }
        }
        return IntOrFloat::evaluate($timestamp);
    }

// add code that show the issue here...
this can be fixed by adding the
$timestamp = date('Y-m-d h:i:s', strtotime($timestamp));

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet 1.18,
PHP 7.4.8
CakePHP 4.2.9

@oleibman
Copy link
Collaborator

The date and strtotime functions aren't Y2038-compliant for 32-bit PHP, which PhpSpreadsheet supports. Getting to your problem, the space between the hyphen and the 9 is indeed unexpected, and should be be a zero. How was your spreadsheet created?

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Oct 13, 2021
See issue PHPOffice#2331. Timestamp is expected in format yyyy-mm-dd (plus other information), with the expectation that month and day are 2 digits zero-filled on the left if needed. The user's file instead used a space rather than zero as filler. Although I don't know how the unexpected timestamp was created, it was easy enough to alter the timestamp in an otherwise normal spreadsheet, and use that file as a test case.
oleibman added a commit that referenced this issue Oct 24, 2021
See issue #2331. Timestamp is expected in format yyyy-mm-dd (plus other information), with the expectation that month and day are 2 digits zero-filled on the left if needed. The user's file instead used a space rather than zero as filler. Although I don't know how the unexpected timestamp was created, it was easy enough to alter the timestamp in an otherwise normal spreadsheet, and use that file as a test case.
@PowerKiKi
Copy link
Member

Fixed in 1.19.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants