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)
| 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. |
| 52 | func 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. |