1
0
mirror of https://github.com/golang/go synced 2024-11-24 01:20:08 -07:00

archive/zip: use UTC for all FileInfo timestamps for consistency

This commit is contained in:
Jannis Andrija Schnitzer 2018-10-30 13:46:16 +01:00 committed by Jannis Andrija Schnitzer
parent 8cb8b4113d
commit 13e94be3f8
2 changed files with 3 additions and 4 deletions

View File

@ -159,7 +159,7 @@ func (fi headerFileInfo) ModTime() time.Time {
if fi.fh.Modified.IsZero() {
return fi.fh.ModTime()
}
return fi.fh.Modified
return fi.fh.Modified.UTC()
}
func (fi headerFileInfo) Mode() os.FileMode { return fi.fh.Mode() }
func (fi headerFileInfo) Sys() interface{} { return fi.fh }
@ -178,7 +178,6 @@ func FileInfoHeader(fi os.FileInfo) (*FileHeader, error) {
UncompressedSize64: uint64(size),
}
fh.SetModTime(fi.ModTime())
fh.Modified = fi.ModTime()
fh.SetMode(fi.Mode())
if fh.UncompressedSize64 > uint32max {
fh.UncompressedSize = uint32max

View File

@ -127,10 +127,10 @@ func TestFileHeaderRoundTripModified(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if got, want := fh2.Modified, fh.Modified; got != want {
if got, want := fh2.Modified, fh.Modified.UTC(); got != want {
t.Errorf("Modified: got %s, want %s\n", got, want)
}
if got, want := fi.ModTime(), fh.Modified; got != want {
if got, want := fi.ModTime(), fh.Modified.UTC(); got != want {
t.Errorf("Modified: got %s, want %s\n", got, want)
}
}