MCPcopy
hub / github.com/cli/cli / FuzzyAgoAbbr

Function FuzzyAgoAbbr

internal/text/text.go:52–66  ·  view source on GitHub ↗

FuzzyAgoAbbr is an abbreviated version of FuzzyAgo. It returns a human readable string of the time duration between a and b that is estimated to the nearest unit of time.

(a, b time.Time)

Source from the content-addressed store, hash-verified

50// FuzzyAgoAbbr is an abbreviated version of FuzzyAgo. It returns a human readable string of the
51// time duration between a and b that is estimated to the nearest unit of time.
52func FuzzyAgoAbbr(a, b time.Time) string {
53 ago := a.Sub(b)
54
55 if ago < time.Hour {
56 return fmt.Sprintf("%d%s", int(ago.Minutes()), "m")
57 }
58 if ago < 24*time.Hour {
59 return fmt.Sprintf("%d%s", int(ago.Hours()), "h")
60 }
61 if ago < 30*24*time.Hour {
62 return fmt.Sprintf("%d%s", int(ago.Hours())/24, "d")
63 }
64
65 return b.Format("Jan _2, 2006")
66}
67
68// DisplayURL returns a copy of the string urlStr removing everything except the scheme, hostname, and path.
69// If the scheme is not specified, "https" is assumed.

Callers 3

printHumanCommentFunction · 0.92
formatCommentFunction · 0.92
TestFuzzyAgoAbbrFunction · 0.85

Calls 1

MinutesMethod · 0.80

Tested by 1

TestFuzzyAgoAbbrFunction · 0.68