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

Honor the local timezone, fix for #369, stop time travel! #735

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions dist/jszip.js
Expand Up @@ -558,17 +558,17 @@ var generateZipParts = function(streamInfo, streamedContent, streamingEnded, off
// @see http://www.delorie.com/djgpp/doc/rbinter/it/65/16.html
// @see http://www.delorie.com/djgpp/doc/rbinter/it/66/16.html

dosTime = date.getUTCHours();
dosTime = date.getHours();
dosTime = dosTime << 6;
dosTime = dosTime | date.getUTCMinutes();
dosTime = dosTime | date.getMinutes();
dosTime = dosTime << 5;
dosTime = dosTime | date.getUTCSeconds() / 2;
dosTime = dosTime | date.getSeconds() / 2;

dosDate = date.getUTCFullYear() - 1980;
dosDate = date.getFullYear() - 1980;
dosDate = dosDate << 4;
dosDate = dosDate | (date.getUTCMonth() + 1);
dosDate = dosDate | (date.getMonth() + 1);
dosDate = dosDate << 5;
dosDate = dosDate | date.getUTCDate();
dosDate = dosDate | date.getDate();

if (useUTF8ForFileName) {
// set the unicode path extra field. unzip needs at least one extra
Expand Down Expand Up @@ -1897,13 +1897,13 @@ DataReader.prototype = {
*/
readDate: function() {
var dostime = this.readInt(4);
return new Date(Date.UTC(
return new Date(
((dostime >> 25) & 0x7f) + 1980, // year
((dostime >> 21) & 0x0f) - 1, // month
(dostime >> 16) & 0x1f, // day
(dostime >> 11) & 0x1f, // hour
(dostime >> 5) & 0x3f, // minute
(dostime & 0x1f) << 1)); // second
(dostime & 0x1f) << 1); // second
}
};
module.exports = DataReader;
Expand Down
2 changes: 1 addition & 1 deletion dist/jszip.min.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions lib/generate/ZipFileWorker.js
Expand Up @@ -144,17 +144,17 @@ var generateZipParts = function(streamInfo, streamedContent, streamingEnded, off
// @see http://www.delorie.com/djgpp/doc/rbinter/it/65/16.html
// @see http://www.delorie.com/djgpp/doc/rbinter/it/66/16.html

dosTime = date.getUTCHours();
dosTime = date.getHours();
dosTime = dosTime << 6;
dosTime = dosTime | date.getUTCMinutes();
dosTime = dosTime | date.getMinutes();
dosTime = dosTime << 5;
dosTime = dosTime | date.getUTCSeconds() / 2;
dosTime = dosTime | date.getSeconds() / 2;

dosDate = date.getUTCFullYear() - 1980;
dosDate = date.getFullYear() - 1980;
dosDate = dosDate << 4;
dosDate = dosDate | (date.getUTCMonth() + 1);
dosDate = dosDate | (date.getMonth() + 1);
dosDate = dosDate << 5;
dosDate = dosDate | date.getUTCDate();
dosDate = dosDate | date.getDate();

if (useUTF8ForFileName) {
// set the unicode path extra field. unzip needs at least one extra
Expand Down
4 changes: 2 additions & 2 deletions lib/reader/DataReader.js
Expand Up @@ -104,13 +104,13 @@ DataReader.prototype = {
*/
readDate: function() {
var dostime = this.readInt(4);
return new Date(Date.UTC(
return new Date(
((dostime >> 25) & 0x7f) + 1980, // year
((dostime >> 21) & 0x0f) - 1, // month
(dostime >> 16) & 0x1f, // day
(dostime >> 11) & 0x1f, // hour
(dostime >> 5) & 0x3f, // minute
(dostime & 0x1f) << 1)); // second
(dostime & 0x1f) << 1); // second
}
};
module.exports = DataReader;
12 changes: 12 additions & 0 deletions test/369utc.js
@@ -0,0 +1,12 @@
JSZip = require ("../dist/jszip");
fs = require ("fs");

var zip = new JSZip();

zip.file("Hello.txt", "Hello World\n");

zip.generateAsync({type: "nodebuffer",compression: "DEFLATE"}).then(function(content) {
// see FileSaver.js
fs.writeFileSync("example.zip",content);
}).catch((e) =>console.log(e) );

26 changes: 26 additions & 0 deletions test/369utc.sh
@@ -0,0 +1,26 @@

#!/bin/sh -xe
# test case for https://github.com/Stuk/jszip/issues/369

rm -f example.zip Hello.txt
export TZ=EST5EDT
node 369utc.js #creates exmaple.zip
unzip example.zip
echo mod time
ls -l --full-time Hello.txt
echo create time
ls -cl --full-time Hello.txt
moddatestring=`ls -l --full-time Hello.txt | awk '// {print $6, $7 , $8}' `
echo $moddatestring
modseconds=`date --date="${moddatestring}" +"%s"`
echo mod seconds $modseconds
nowseconds=` date +"%s"`
echo now $nowseconds
if [ $modseconds -gt $nowseconds ]; then
echo error - time travel is not possible - file is from the future
exit -4
fi
echo pass
exit 0;