diff options
author | Andrew Thornton <art27@cantab.net> | 2020-02-22 18:57:57 +0000 |
---|---|---|
committer | Andrew Thornton <art27@cantab.net> | 2020-02-23 09:52:24 +0000 |
commit | 1ffc59ee1161f9330058dc115e3589b4998ad09a (patch) | |
tree | 4e68fe7382b51483f6b4bb93618e65a7000e7fd9 /plumbing | |
parent | 1a7db85bca7027d90afdb5ce711622aaac9feaed (diff) | |
download | go-git-1ffc59ee1161f9330058dc115e3589b4998ad09a.tar.gz |
Fix date reading
In the British TZ the following time:
```
1579639200 +0100
```
will be erroneously parsed as being with the GMT TZ.
This leads to multiple errors with GPG validation.
This PR fixes this by using the provided TZ information to
create a FixedZone and sets that as the TZ
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'plumbing')
-rw-r--r-- | plumbing/object/object.go | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/plumbing/object/object.go b/plumbing/object/object.go index e960e50..0d891ad 100644 --- a/plumbing/object/object.go +++ b/plumbing/object/object.go @@ -138,17 +138,22 @@ func (s *Signature) decodeTimeAndTimeZone(b []byte) { return } - // Include a dummy year in this time.Parse() call to avoid a bug in Go: - // https://github.com/golang/go/issues/19750 - // - // Parsing the timezone with no other details causes the tl.Location() call - // below to return time.Local instead of the parsed zone in some cases - tl, err := time.Parse("2006 -0700", "1970 "+string(b[tzStart:tzStart+timeZoneLength])) + timezone := string(b[tzStart : tzStart+timeZoneLength]) + tzhours, err := strconv.ParseInt(timezone[0:3], 10, 64) if err != nil { return } + tzmins, err := strconv.ParseInt(timezone[3:], 10, 64) + if err != nil { + return + } + if tzhours < 0 { + tzmins *= -1 + } + + tz := time.FixedZone("", int(tzhours*60*60+tzmins*60)) - s.When = s.When.In(tl.Location()) + s.When = s.When.In(tz) } func (s *Signature) encodeTimeAndTimeZone(w io.Writer) error { |