Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
archive/zip: f.ModTime()'s yyyy/mm/dd hh:mm:ss should match Go 1.9 #22738
The result of f.ModTime().Format("2006-01-02 15:04:05") has changed from Go 1.9 to Go 1.10. Given that ModTime is working with bit fields that encode yyyy/mm/dd hh:mm:ss, printing those fields should continue to reproduce their actual values (as Go 1.9 and earlier versions did).
https://swtch.com/tmp/ziptime.zip is this file:
The extra field beginning at offset 006d encodes the Unix time 0x386d4380 aka 2000-01-01 00:00:00 UTC. The MS-DOS time fields at offset 000c encode time=0x9800=19:00:00 date=0x279f=1999-12-31, aka what that Unix time displayed as in US Eastern time.
Here's a program that prints the zip.FileInfo's ModTime result:
The output has changed since Go 1.9:
This is clearly an improvement: the time instant is correct now and was incorrect in Go 1.9. However, it's also a regression, in that previously if you did t := f.ModTime() and then queried t.Year, t.Month, t.Day, t.Hour, t.Minute, t.Second, they all matched the encoded MS-DOS bits in the zip file. Now they don't.
Obviously the result of f.ModTime must change given the cleanup here. But in the Go 1.9 result the time zone was incorrect and the Year/Month/Day/Hour/Minute/Second was correct. I don't see why Go 1.10 is preserving the incorrect timezone and changing (breaking) the Year/Month/Day/Hour/Minute/Second. It seems like it should be preserving the correct Year/Month/Day/Hour/Minute/Second and changing (fixing) the time zone.
If you uncomment the Go 1.10-specific line in my program above, it prints:
It seems to me that ModTime() should simply return f.Modified directly, without the UTC coercion. That will effect the fix I suggested.
Then the original Go 1.9 vs Go 1.10 comparison becomes:
and that looks like a bug fix (instead of a bug being introduced).
An alternative would be to have ModTime continue to return the different time instant