Zippy
Zippy copied to clipboard
Date parsing error in ZipOutputParser
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
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],
If anyone's running into this, just run this with the correct format:
\Alchemy\Zippy\Parser\ParserFactory::setZipDateFormat('m-d-Y H:i');