Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit c102502

Browse files
ethantkoeniglafriks
authored andcommitted
Fix time parsing (#97)
1 parent 02eccf8 commit c102502

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,5 +283,5 @@ func GetLatestCommitTime(repoPath string) (time.Time, error) {
283283
return time.Time{}, err
284284
}
285285
commitTime := strings.TrimSpace(stdout)
286-
return time.Parse("Mon Jan 02 15:04:05 2006 -0700", commitTime)
286+
return time.Parse(GitTimeLayout, commitTime)
287287
}

signature.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ type Signature struct {
1717
When time.Time
1818
}
1919

20+
const (
21+
// GitTimeLayout is the (default) time layout used by git.
22+
GitTimeLayout = "Mon Jan _2 15:04:05 2006 -0700"
23+
)
24+
2025
// Helper to get a signature from the commit line, which looks like these:
2126
// author Patrick Gundlach <[email protected]> 1378823654 +0200
2227
// author Patrick Gundlach <[email protected]> Thu, 07 Apr 2005 22:13:13 +0200
@@ -40,7 +45,7 @@ func newSignatureFromCommitline(line []byte) (_ *Signature, err error) {
4045
seconds, _ := strconv.ParseInt(timestring, 10, 64)
4146
sig.When = time.Unix(seconds, 0)
4247
} else {
43-
sig.When, err = time.Parse("Mon Jan _2 15:04:05 2006 -0700", string(line[emailEnd+2:]))
48+
sig.When, err = time.Parse(GitTimeLayout, string(line[emailEnd+2:]))
4449
if err != nil {
4550
return nil, err
4651
}

0 commit comments

Comments
 (0)