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

Date parsing error in ZipOutputParser #129

Open
sankarsuda opened this issue Mar 27, 2017 · 2 comments
Open

Date parsing error in ZipOutputParser #129

sankarsuda opened this issue Mar 27, 2017 · 2 comments

Comments

@sankarsuda
Copy link

Hi
Zippy throwing the following error while extracting on cent os server.

PHP Fatal error:  Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (03-27-2017 16:49) at position 0 (0): Unexpected character' in vendor/alchemy/zippy/src/Parser/ZipOutputParser.php:71
Stack trace:
#0 vendor/alchemy/zippy/src/Parser/ZipOutputParser.php(74): DateTime->__construct('03-27-2017 16:4...')
#1 vendor/alchemy/zippy/src/Adapter/ZipAdapter.php(119): Alchemy\Zippy\Parser\ZipOutputParser->parseFileListing('Archive:  /var/...')
#2 vendor/alchemy/zippy/src/Adapter/AbstractAdapter.php(68): Alchemy\Zippy\Adapter\ZipAdapter->doListMembers(Object(Alchemy\Zippy\Adapter\Resource\FileResource))
#3 vendor/alchemy/zippy/src/Archive/Archive.php(94): Alchemy\Zippy\Adapter\AbstractAdapter->listMembers(Object(Alchemy\Zippy\Adapter\Resource\FileResource))
#4 vendor/alchemy/zippy/src/Archive/Archive.php(86): Alchemy\Zippy\Archive\Archive->getMembers()
#5 /var/www/htm in vendor/alchemy/zippy/src/Parser/ZipOutputParser.php on line 71

I am using latest version of Zippy.

I am able fix the issue by chaning some code

            $chunks[2] = date('Y-m-d H:i', strtotime(str_replace('-', '/', $chunks[2])));

            $mtime = \DateTime::createFromFormat($this->dateFormat, $chunks[2]);

            if ($mtime === false) {
                // See https://github.com/alchemy-fr/Zippy/issues/111#issuecomment-251668427
                $mtime = \DateTime::createFromFormat('H:i Y-m-d', $chunks[2]);
            }

from $chunks[2] = date('Y-m-d H:i', strtotime(str_replace('-', '/', $chunks[2])));

        $mtime = \DateTime::createFromFormat($this->dateFormat, $chunks[2]);

        if ($mtime === false) {
            // See https://github.com/alchemy-fr/Zippy/issues/111#issuecomment-251668427
            $mtime = \DateTime::createFromFormat('H:i Y-m-d', $chunks[2]);
        }

Is it correct? or any other alernate wasy fix issue. 
I have also checked the other issues reported on same. But those are not helped
@gh640
Copy link

gh640 commented Oct 3, 2017

I met the same issue on CentOS. The format of date is not always the expected one and it looks a little difficult to fix this for me.

Fortunately in my use case, the modified date is not important and I used this package with a little twist like following.

--- a/src/Parser/ZipOutputParser.php
+++ b/src/Parser/ZipOutputParser.php
@@ -60,16 +60,7 @@ class ZipOutputParser implements ParserInterface
                 continue;
             }
 
-            $mtime = \DateTime::createFromFormat($this->dateFormat, $chunks[2]);
-
-            if ($mtime === false) {
-                // See https://github.com/alchemy-fr/Zippy/issues/111#issuecomment-251668427
-                $mtime = \DateTime::createFromFormat('H:i Y-m-d', $chunks[2]);
-            }
-
-            if ($mtime === false) {
-                $mtime = new \DateTime($chunks[2]);
-            }
+            $mtime = new \DateTime();
 
             $members[] = array(
                 'location'  => $chunks[3],

@patrickconroy
Copy link

If anyone's running into this, just run this with the correct format:

\Alchemy\Zippy\Parser\ParserFactory::setZipDateFormat('m-d-Y H:i');

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

No branches or pull requests

3 participants