From c102502951cfffee4fd4207827ff8fdfd99f7472 Mon Sep 17 00:00:00 2001 From: Ethan Koenig Date: Sun, 10 Dec 2017 02:04:04 -0800 Subject: [PATCH] Fix time parsing (#97) --- repo.go | 2 +- signature.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/repo.go b/repo.go index f87c73d..4306730 100644 --- a/repo.go +++ b/repo.go @@ -283,5 +283,5 @@ func GetLatestCommitTime(repoPath string) (time.Time, error) { return time.Time{}, err } commitTime := strings.TrimSpace(stdout) - return time.Parse("Mon Jan 02 15:04:05 2006 -0700", commitTime) + return time.Parse(GitTimeLayout, commitTime) } diff --git a/signature.go b/signature.go index 7dc9763..e6ab247 100644 --- a/signature.go +++ b/signature.go @@ -17,6 +17,11 @@ type Signature struct { When time.Time } +const ( + // GitTimeLayout is the (default) time layout used by git. + GitTimeLayout = "Mon Jan _2 15:04:05 2006 -0700" +) + // Helper to get a signature from the commit line, which looks like these: // author Patrick Gundlach 1378823654 +0200 // author Patrick Gundlach Thu, 07 Apr 2005 22:13:13 +0200 @@ -40,7 +45,7 @@ func newSignatureFromCommitline(line []byte) (_ *Signature, err error) { seconds, _ := strconv.ParseInt(timestring, 10, 64) sig.When = time.Unix(seconds, 0) } else { - sig.When, err = time.Parse("Mon Jan _2 15:04:05 2006 -0700", string(line[emailEnd+2:])) + sig.When, err = time.Parse(GitTimeLayout, string(line[emailEnd+2:])) if err != nil { return nil, err }