Skip to content

Commit a922281

Browse files
authored
Merge pull request go-git#2 from go-git/pr-1291
plumbing: object, fix date reading
2 parents 69f23a7 + 6562023 commit a922281

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ require (
2727
gopkg.in/src-d/go-git-fixtures.v3 v3.5.0
2828
gopkg.in/warnings.v0 v0.1.2 // indirect
2929
)
30+
31+
go 1.13

plumbing/object/object.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,19 @@ func (s *Signature) decodeTimeAndTimeZone(b []byte) {
138138
return
139139
}
140140

141-
// Include a dummy year in this time.Parse() call to avoid a bug in Go:
142-
// https://github.com/golang/go/issues/19750
143-
//
144-
// Parsing the timezone with no other details causes the tl.Location() call
145-
// below to return time.Local instead of the parsed zone in some cases
146-
tl, err := time.Parse("2006 -0700", "1970 "+string(b[tzStart:tzStart+timeZoneLength]))
147-
if err != nil {
141+
timezone := string(b[tzStart : tzStart+timeZoneLength])
142+
tzhours, err1 := strconv.ParseInt(timezone[0:3], 10, 64)
143+
tzmins, err2 := strconv.ParseInt(timezone[3:], 10, 64)
144+
if err1 != nil || err2 != nil {
148145
return
149146
}
147+
if tzhours < 0 {
148+
tzmins *= -1
149+
}
150+
151+
tz := time.FixedZone("", int(tzhours*60*60+tzmins*60))
150152

151-
s.When = s.When.In(tl.Location())
153+
s.When = s.When.In(tz)
152154
}
153155

154156
func (s *Signature) encodeTimeAndTimeZone(w io.Writer) error {

0 commit comments

Comments
 (0)