From 04d3e00d4e042959389e0a1d1d72e9ced6a31189 Mon Sep 17 00:00:00 2001 From: Ashish Patel Date: Mon, 25 May 2026 14:56:59 +0530 Subject: [PATCH] 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. --- internal/collect/git.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/collect/git.go b/internal/collect/git.go index c3340cd..d2c2464 100644 --- a/internal/collect/git.go +++ b/internal/collect/git.go @@ -4,12 +4,24 @@ import ( "os/exec" "path/filepath" "strings" + "time" "github.com/ashishxcode/commit-chronicle/internal/model" ) const fieldSep = "\x1f" // ASCII unit separator +// anchorMidnight pins a bare YYYY-MM-DD to local midnight. git's --since/--until +// parse a bare date via approxidate, which fills the missing time with the +// *current* time of day — skewing every window by the wall clock. Relative +// strings (e.g. "7 days ago") are passed through untouched. +func anchorMidnight(when string) string { + if _, err := time.Parse("2006-01-02", when); err == nil { + return when + " 00:00:00" + } + return when +} + // gitCommits returns de-duplicated commits authored by `author` in the range, // across all refs in each repo. 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 { "--pretty=format:%h" + fieldSep + "%H" + fieldSep + "%ad" + fieldSep + "%s", } if r.Since != "" { - args = append(args, "--since="+r.Since) + args = append(args, "--since="+anchorMidnight(r.Since)) } if r.Until != "" { - args = append(args, "--until="+r.Until) + args = append(args, "--until="+anchorMidnight(r.Until)) } out, err := exec.Command("git", args...).Output()