Add issue comment viewing

This commit is contained in:
Sam Coe 2020-11-13 11:16:54 +03:00
parent f4152454f2
commit c843a4fa13
No known key found for this signature in database
GPG key ID: 8E322C20F811D086
16 changed files with 1408 additions and 89 deletions

View file

@ -59,6 +59,22 @@ func FuzzyAgo(ago time.Duration) string {
return fmtDuration(int(ago.Hours()/24/365), "year")
}
func FuzzyAgoAbbr(now time.Time, createdAt time.Time) string {
ago := now.Sub(createdAt)
if ago < time.Hour {
return fmt.Sprintf("%d%s", int(ago.Minutes()), "m")
}
if ago < 24*time.Hour {
return fmt.Sprintf("%d%s", int(ago.Hours()), "h")
}
if ago < 30*24*time.Hour {
return fmt.Sprintf("%d%s", int(ago.Hours())/24, "d")
}
return createdAt.Format("Jan _2, 2006")
}
func Humanize(s string) string {
// Replaces - and _ with spaces.
replace := "_-"