Source code of internal zip packer to fix timestams in UTC, instead of localtime

English support forum

Moderators: white, Hacker, petermad, Stefan2

User avatar
angel
Junior Member
Junior Member
Posts: 46
Joined: 2014-10-17, 06:54 UTC
Location: Sofia, Bulgaria, Europe

Re: Source code of internal zip packer to fix timestams in UTC, instead of localtime

Post by *angel »

ghisler(Author) wrote: 2021-12-30, 10:35 UTC Did you find out whether 7zip sets any flag in the file header when storing times as UTC? Otherwise it would be impossible to know whether a file contains timestamps in local time or UTC.
Sorry, for now I didn't find out whether 7zip sets any flag in the header. Maybe they don't use UTC in a way I am thinking, so the searching continue.

The major timestamps difference between the two versions in CPP/7zip/Archive/Zip/ZipHandler.h is:
In 7z912 (2010-03-24) the variable m_WriteNtfsTimeExtra = false
In 7z913 (2010-04-15) the variable m_WriteNtfsTimeExtra = true
In 7z913 7-Zip now stores NTFS file timestamps to ZIP archives
=>so from this version (7z913) they activate NTFS timestamps for zip archives
#381167 Single user license [08:50, 26.10.2022]
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Source code of internal zip packer to fix timestams in UTC, instead of localtime

Post by *ghisler(Author) »

It sounds like they store NTFS timestamps in an extra field, because the ZIP timestamps only have enough space for DOS timestamps (with a 2 second resolution instead of 100 nanosecond resolution).
Author of Total Commander
https://www.ghisler.com
User avatar
angel
Junior Member
Junior Member
Posts: 46
Joined: 2014-10-17, 06:54 UTC
Location: Sofia, Bulgaria, Europe

Re: Source code of internal zip packer to fix timestams in UTC, instead of localtime

Post by *angel »

ghisler(Author) wrote: 2021-12-31, 08:41 UTC It sounds like they store NTFS timestamps in an extra field, because the ZIP timestamps only have enough space for DOS timestamps (with a 2 second resolution instead of 100 nanosecond resolution).
That is correct and confirmed. Igor Pavlov (7-zip.org) said on 2014-10-09:

7-Zip uses extra fields from central directory at the end of ZIP archive.
There are two possible extra UTC fields:
- Unix UTC
- NTFS UTC
ZIP (like old FAT) uses 2 sec. precision for timestamps. There is extension (extra fileds) to ZIP format that allows better precision.
https://sourceforge.net/p/sevenzip/discussion/45797/thread/7fe2e341/#440f

Some interesting info:
At the time MS-DOS was created, timezone was not being used on those computers (Unix already had the concept, though, since 1970.) People who used MS-DOS were often in their office or at home and did not communicate with people in other states let alone other countries via the computer. Intranet was pretty expensive too at the time.
The company that created the zip file format made the mistake of using the FAT file system date format and it stuck. So zip files are created using local time (it doesn't have to, but it's the expected behavior, at least.)
The zip format offers ways to add extensions, though, including various timestamps.

As we can see, the NTFS and Unix blocks clearly define their timestamp as using UTC. The NTFS date has more precision (100ms) than the Unix timestamps (1s), it will also survive much longer since it uses 64 bits (see Year 2038 Problem for further details on the 32 bit timestamps).
https://stackoverflow.com/questions/26045471/system-io-compression-zip-doesnt-use-utc/55568458#55568458
#381167 Single user license [08:50, 26.10.2022]
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Source code of internal zip packer to fix timestams in UTC, instead of localtime

Post by *ghisler(Author) »

It's not clear whether 7zip now supports the WinZIP NTFS time extra field, or its own. Could you send me a small sample ZIP with these extra timestamps for testing?
Author of Total Commander
https://www.ghisler.com
User avatar
angel
Junior Member
Junior Member
Posts: 46
Joined: 2014-10-17, 06:54 UTC
Location: Sofia, Bulgaria, Europe

Re: Source code of internal zip packer to fix timestams in UTC, instead of localtime

Post by *angel »

ghisler(Author) wrote: 2022-01-03, 14:40 UTC It's not clear whether 7zip now supports the WinZIP NTFS time extra field, or its own. Could you send me a small sample ZIP with these extra timestamps for testing?
For me it is not clear too, but if I have to bet, 7zip supports its own extra fields for NTFS timestamps (UTC timestamps). Sorry, but i don't understand what exactly small zip to send you. Can you describe that? Thanks
#381167 Single user license [08:50, 26.10.2022]
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Source code of internal zip packer to fix timestams in UTC, instead of localtime

Post by *ghisler(Author) »

1. Create a new text file with Shift+F4
2. Write some short text in it
3. Pack the file with 7zip with the parameters needed to add that NTFS timestamp

This would save me a lot of time to find out what exactly needs to be configured in 7zip to use this feature.
Author of Total Commander
https://www.ghisler.com
User avatar
angel
Junior Member
Junior Member
Posts: 46
Joined: 2014-10-17, 06:54 UTC
Location: Sofia, Bulgaria, Europe

Re: Source code of internal zip packer to fix timestams in UTC, instead of localtime

Post by *angel »

ghisler(Author) wrote: 2022-01-05, 14:04 UTC ...
3. Pack the file with 7zip with the parameters needed to add that NTFS timestamp
...
The second part of point 3 is unclear to me? I pack the file with 7zip with TC + Alt+F5 + Packer ->7z (I am using total 7zip plugin). There are no any parameters. All files in the 7zip archive are with NTFS timestamps (UTC timestamps).
Sorry, I really want to save you time, but I am no familiar with the source code of 7zip.org, Recently, I have only a vague and superficial idea of it.
(that's why I propose to use 7z.dll/7za.dll as optional to WCMZIP32.DLL/WCMZIP64.DLL)
(my only other experience in this area is with "7Zip Plugin 0.7.6.6" - I only managed to compile the old 2016 and original source code for VS2010+PlatformToolset=Windows7.1 to the new one VS2019+PlatformToolset=VC142. Here is the tutorial for that)
#381167 Single user license [08:50, 26.10.2022]
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Source code of internal zip packer to fix timestams in UTC, instead of localtime

Post by *ghisler(Author) »

The second part of point 3 is unclear to me? I pack the file with 7zip with TC + Alt+F5 + Packer ->7z (I am using total 7zip plugin). There are no any parameters. All files in the 7zip archive are with NTFS timestamps (UTC timestamps).
This creates 7zip archives - I thought your request was about zip archives with NTFS timestamps?
Author of Total Commander
https://www.ghisler.com
User avatar
angel
Junior Member
Junior Member
Posts: 46
Joined: 2014-10-17, 06:54 UTC
Location: Sofia, Bulgaria, Europe

Re: Source code of internal zip packer to fix timestams in UTC, instead of localtime

Post by *angel »

ghisler(Author) wrote: 2022-01-07, 15:01 UTC This creates 7zip archives - I thought your request was about zip archives with NTFS timestamps?
Yes, my request was for zip + NTFS
I can create a pack with 7zip_zip (zip) with TC + Alt+F5 + Packer ->7zip_zip (I am using total 7zip plugin).
This will create better zip with NTFS timestamps (UTC timestamps), instead of standard local timestamp with normal zip packer
Is it your request?

if yes, here is some zip file created as:
1. Create a new text file with Shift+F4
2. Write some short text in it
3. Pack the file with 7zip (7zip_zip) with NTFS timestamp
http://lookingfor.click/temp.zip
(if it helps, I can set different DST and/or timezones)
#381167 Single user license [08:50, 26.10.2022]
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Source code of internal zip packer to fix timestams in UTC, instead of localtime

Post by *petermad »

2ghisler(Author)

You might not have the option to choose 7zip_zip as packer extension - if not you need to extend the
[PackerPlugins] section - here is my extension:

Code: Select all

[PackerPlugins]
7z=735,%COMMANDER_PATH%\PLUGINS\wcx\Total7zip\Total7zip.wcx
wim=735,%COMMANDER_PATH%\PLUGINS\wcx\Total7zip\Total7zip.wcx
xz=731,%COMMANDER_PATH%\PLUGINS\wcx\Total7zip\Total7zip.wcx
flv=964,%COMMANDER_PATH%\PLUGINS\wcx\Total7zip\Total7zip.wcx
7zip_7z=735,%COMMANDER_PATH%\PLUGINS\wcx\Total7zip\Total7zip.wcx
7zip_zip=735,%COMMANDER_PATH%\PLUGINS\wcx\Total7zip\Total7zip.wcx
7zip_tar=733,%COMMANDER_PATH%\PLUGINS\wcx\Total7zip\Total7zip.wcx
7zip_gzip=731,%COMMANDER_PATH%\PLUGINS\wcx\Total7zip\Total7zip.wcx
7zip_bzip2=731,%COMMANDER_PATH%\PLUGINS\wcx\Total7zip\Total7zip.wcx
7zip_jar=212,%COMMANDER_PATH%\PLUGINS\wcx\Total7zip\Total7zip.wcx
7zip_arj=196,%COMMANDER_PATH%\PLUGINS\wcx\Total7zip\Total7zip.wcx
7zip_rar=196,%COMMANDER_PATH%\PLUGINS\wcx\Total7zip\Total7zip.wcx
7zip_cab=708,%COMMANDER_PATH%\PLUGINS\wcx\Total7zip\Total7zip.wcx
iso=196,%COMMANDER_PATH%\PLUGINS\wcx\Total7zip\Total7zip.wcx
7zip_xpi=212,%COMMANDER_PATH%\PLUGINS\wcx\Total7zip\Total7zip.wcx
And the same formats have to be added to the [PackerPlugins64] section:

Code: Select all

[PackerPlugins64]
exts=7zip*7z_7z*7z_jar*7z*wim*xz*flv*7zip_7z*7zip_zip*7zip_tar*7zip_gzip*7zip_bzip2*7zip_jar*7zip_arj*7zip_rar*7zip_cab*iso*7zip_xpi
line
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Source code of internal zip packer to fix timestams in UTC, instead of localtime

Post by *ghisler(Author) »

Indeed I didn't have that 7zip_zip line, that seems to work. Btw, the [PackerPlugins64] section is updated automatically when the [PackerPlugins] section changes.

This seems to create a zip with an extra field in the header, but I haven't checked yet what field is added.
Author of Total Commander
https://www.ghisler.com
User avatar
angel
Junior Member
Junior Member
Posts: 46
Joined: 2014-10-17, 06:54 UTC
Location: Sofia, Bulgaria, Europe

Re: Source code of internal zip packer to fix timestams in UTC, instead of localtime

Post by *angel »

ghisler(Author) wrote: 2022-01-10, 10:48 UTC Indeed I didn't have that 7zip_zip line
Here is a quick solution how to use better zip (7zip_zip) and to preserve DST and different timezones plus 2-10% better compression than PKZip and WinZip plus AES-256 in zip archives via Total7zip 0.8.5.6 plug-in which uses the original 7-Zip.org files:
viewtopic.php?p=408612#p408612
#381167 Single user license [08:50, 26.10.2022]
User avatar
angel
Junior Member
Junior Member
Posts: 46
Joined: 2014-10-17, 06:54 UTC
Location: Sofia, Bulgaria, Europe

Re: Source code of internal zip packer to fix timestams in UTC, instead of localtime

Post by *angel »

ghisler(Author) wrote: 2021-12-27, 16:07 UTC angel
I will integrate it into TC.
Any progress of integrating of UTC timestamps to provide different timezones and summer time (DST)/normal time in genuine zip archives?
#381167 Single user license [08:50, 26.10.2022]
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Source code of internal zip packer to fix timestams in UTC, instead of localtime

Post by *ghisler(Author) »

I haven't started working on this yet because it will require a lot of changes, which will take a long time and bear the risk of a lot of new bugs.
I can't just add it to unpacking, otherwise there will be inconsistencies with comparing, synchronizing, packing etc.
Author of Total Commander
https://www.ghisler.com
Post Reply