Skip to content

Commit 04d3e00

Browse files
committed
fix(collect): anchor git date filters to local midnight
git's --since/--until parse a bare YYYY-MM-DD via approxidate, filling the missing time-of-day with the current wall-clock time. This skewed every reporting window by the time of day it was run -- e.g. the "Yesterday" preset swept in same-morning commits while "Today" missed them. Anchor bare ISO dates to 00:00:00 before passing them to git; relative strings like "7 days ago" pass through untouched.
1 parent 6adb3f6 commit 04d3e00

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎internal/collect/git.go‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,24 @@ import (
44
"os/exec"
55
"path/filepath"
66
"strings"
7+
"time"
78

89
"github.com/ashishxcode/commit-chronicle/internal/model"
910
)
1011

1112
const fieldSep = "\x1f" // ASCII unit separator
1213

14+
// anchorMidnight pins a bare YYYY-MM-DD to local midnight. git's --since/--until
15+
// parse a bare date via approxidate, which fills the missing time with the
16+
// *current* time of day — skewing every window by the wall clock. Relative
17+
// strings (e.g. "7 days ago") are passed through untouched.
18+
func anchorMidnight(when string) string {
19+
if _, err := time.Parse("2006-01-02", when); err == nil {
20+
return when + " 00:00:00"
21+
}
22+
return when
23+
}
24+
1325
// gitCommits returns de-duplicated commits authored by `author` in the range,
1426
// across all refs in each repo.
1527
func gitCommits(repos []string, author string, r model.Range) []model.Item {
@@ -25,10 +37,10 @@ func gitCommits(repos []string, author string, r model.Range) []model.Item {
2537
"--pretty=format:%h" + fieldSep + "%H" + fieldSep + "%ad" + fieldSep + "%s",
2638
}
2739
if r.Since != "" {
28-
args = append(args, "--since="+r.Since)
40+
args = append(args, "--since="+anchorMidnight(r.Since))
2941
}
3042
if r.Until != "" {
31-
args = append(args, "--until="+r.Until)
43+
args = append(args, "--until="+anchorMidnight(r.Until))
3244
}
3345

3446
out, err := exec.Command("git", args...).Output()

0 commit comments

Comments
 (0)