summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-11-11 19:23:57 +0800
committerEltrac <hi@guhub.cn>2025-11-11 19:23:57 +0800
commitad0e841fe94247ba5fc447bc38f779a2c46b2abc (patch)
treee179afd1060714cd8c36549a76592b82931ad650
parenta461fdfd9b010dafbdf422002c7549cb21023fc4 (diff)
fix: extra string in printRecentActivity()
-rw-r--r--print.go23
-rw-r--r--statistics.go8
2 files changed, 13 insertions, 18 deletions
diff --git a/print.go b/print.go
index 45601f4..e78bdc4 100644
--- a/print.go
+++ b/print.go
@@ -102,21 +102,14 @@ func printRecentActivity(installedVersion string, atime time.Time) {
}
// print usage info
- var format string
- var humanReadableDuration string
-
- humanReadableDuration = durafmt.ParseShort(time.Since(atime)).String()
- format = func() string {
- if atime.Nanosecond() == 0 {
- return "► You never used this."
- } else if time.Since(atime) < 24*7*time.Hour {
- return "► You used this in %s."
- } else {
- return "► You haven't used this for %s."
- }
- }()
-
- color.Blue(format, humanReadableDuration)
+ humanReadableDuration := durafmt.ParseShort(time.Since(atime)).String()
+ if atime.Nanosecond() == 0 {
+ color.Blue("► You never used this.")
+ } else if time.Since(atime) < 24*7*time.Hour {
+ color.Blue("► You used this in %s.", humanReadableDuration)
+ } else {
+ color.Blue("► You haven't used this for %s.", humanReadableDuration)
+ }
}
// === #Section: Metadata# === //
diff --git a/statistics.go b/statistics.go
index 428d19c..c83a25f 100644
--- a/statistics.go
+++ b/statistics.go
@@ -58,13 +58,15 @@ func UnifyInfo(formula *FormulaInfo, cask *CaskInfo, pkgName string) (*statistic
// === general === //
// get system atime
+ var atime time.Time
binPath := filepath.Join("/opt/homebrew/bin", pkgName)
info, err := os.Stat(binPath)
if err != nil {
- return nil // skip if no binary is found
+ atime = time.Time{} // skip if no binary is found
+ } else {
+ atime = time.Unix(info.Sys().(*syscall.Stat_t).Atimespec.Unix())
}
- atime := info.Sys().(*syscall.Stat_t).Atimespec
- statObject.LastAccessTime = time.Unix(atime.Unix())
+ statObject.LastAccessTime = atime
return &statObject
}