-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Last Modified time for zip entries is UTC time #369
Comments
It seems the timestamp is usually stored in local time while time related extra fields (NTFS Extra Field, UNIX Extra Field or Extended Timestamp) use UTC. Which archive manager do you use ? |
I recently have this issue, too. It is just annoying that a file compressed by JSZip on my computer gets a wrong lastmodified time after extracted on the same computer. And I have to do the extra code work to adjust the time put and get from JSZip. In my opinion, if in convention the native zip timestamp is to store the local time, we'd better follow the convention to prevent unexpected results, before the extra fields is supported. Or, as a compromise, add an option to allow the user decide what to be stored and read. |
Agreed! I get the wrong last modified time when reading the zip using 7-zip and the Windows Explorer zip reader.
It seems like the commit should be reverted and the extra fields should also be supported. |
Is there a way to get the modified date to match the local time using the API or is the only option to modify the source code? I passed in |
I've found a workaround for this issue. Consider the following code: const zip = new JSZip();
const currDate = new Date();
const dateWithOffset = new Date(currDate.getTime() - currDate.getTimezoneOffset() * 60000);
zip.file('path/to/file/filename.txt', 'file content here', { date: dateWithOffset }); If works for file create/modified time but not for folders though. |
I am also having the same issue on macOS. @MEGApixel23 workaround works but I am just not sure why the author of the library is not providing a way to do this natively with the library. Every user of the library seems like they will bump into the same issue (in my case I spent a few hours trying to figure out why my build kept on rebuilding everything over and over, which turned out to be |
Seems like an author would not fix this. That's a great opportunity for adding the fix and create a pull request! |
yes, I have found a better method, it works for both files and folders: const currDate = new Date();
const dateWithOffset = new Date(currDate.getTime() - currDate.getTimezoneOffset() * 60000);
// replace the default date with dateWithOffset
JSZip.defaults.date = dateWithOffset; |
Better than nothing! I'm not the JS expert but I think that solution is not thread-safe, is it? |
This is astonishing behaviour. I've fixed this with this PR: #735 |
When will the problem be fixed |
😂 - thanks for not closing the PR.. But I fear maintainer may have left the building. |
I'm in a -4:00 timezone. When I create an archive then extract it, the extracted files have a correct created time, but their last modified times are created time + 4 hours.
If I modify the jszip source to the following, the created and last modified times are the same, which is what I would expect:
The text was updated successfully, but these errors were encountered: