Zippy icon indicating copy to clipboard operation
Zippy copied to clipboard

Date parsing error in ZipOutputParser

Open sankarsuda opened this issue 7 years ago • 2 comments

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

sankarsuda avatar Mar 27 '17 11:03 sankarsuda

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],

gh640 avatar Oct 03 '17 13:10 gh640

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

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

patrickconroy avatar Nov 20 '17 15:11 patrickconroy