MCPcopy Create free account
hub / github.com/cli/cli / FuzzyAgoAbbr

Function FuzzyAgoAbbr

internal/text/text.go:77–91  ·  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

75// FuzzyAgoAbbr is an abbreviated version of FuzzyAgo. It returns a human readable string of the
76// time duration between a and b that is estimated to the nearest unit of time.
77func FuzzyAgoAbbr(a, b time.Time) string {
78 ago := a.Sub(b)
79
80 if ago < time.Hour {
81 return fmt.Sprintf("%d%s", int(ago.Minutes()), "m")
82 }
83 if ago < 24*time.Hour {
84 return fmt.Sprintf("%d%s", int(ago.Hours()), "h")
85 }
86 if ago < 30*24*time.Hour {
87 return fmt.Sprintf("%d%s", int(ago.Hours())/24, "d")
88 }
89
90 return b.Format("Jan _2, 2006")
91}
92
93// DisplayURL returns a copy of the string urlStr removing everything except the scheme, hostname, and path.
94// If the scheme is not specified, "https" is assumed.

Callers 3

printHumanCommentFunction · 0.92
formatCommentFunction · 0.92
TestFuzzyAgoAbbrFunction · 0.85

Calls 2

SubMethod · 0.80
MinutesMethod · 0.80

Tested by 1

TestFuzzyAgoAbbrFunction · 0.68