`zipfile` and `tarfile` docs should cover local timezone impact on entry timestamps
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
In a project that aims to emit reproducible archives, tar.xz archives were working as expected, but zip archives were ending up with timestamp discrepancies between local builds in AEST (UTC+10) and CI builds in UTC.
I eventually tracked this down to differing timestamp handling conventions in tarfile and zipfile (these conventions aren't unique to Python, so we can't readily eliminate the discrepancy, we can only document it):
tarfileuses the timestamps as they are, so if the filesystem stores timestamps in UTC (as most common filesystems other than FAT/FAT32/VFAT will do), they will be added to the file as UTC. If the filesystem stores local time, it will still be used without modification, but will probably be interpreted as UTC when the archive is extractedzipfileexplicitly interprets the filesystem timestamps withtime.localtime, so they will be added to the file as local time by default. If the filesystem already uses local time, the timezone offset will be applied a second time (potentially resulting in a stored modification time in the future for local timezones with a positive offset from UTC)
tarfile has an additional timezone related complication in that some compression formats (at least gzip) include a file creation time header: https://github.com/python/cpython/issues/75707
Discourse thread: https://discuss.python.org/t/tarfile-vs-zipfile-timezone-discrepancy-in-handling-modification-times/61016
Linked PRs
- gh-155195
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the zipfile and tarfile documentation alongside the linked Discourse thread and gzip timestamp issue. Document how local timezone handling affects entry timestamps in both archive formats, including the additional gzip creation-time complication; the linked PR gh-155195 shows that work is already underway.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100