Skip to content

Commit

Permalink
templates: add months and years to relative_time function
Browse files Browse the repository at this point in the history
  • Loading branch information
janos committed Aug 17, 2018
1 parent b97aa01 commit 00d01d4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion templates/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ func relativeTimeFunc(t time.Time) string {
return fmt.Sprintf("%d hours ago", d/time.Hour)
case d < 2*day:
return "one day ago"
case d < 30*day:
return fmt.Sprintf("%d days ago", d/day)
case d < 60*day:
return "one month ago"
case d < 2*365*day:
return fmt.Sprintf("%d months ago", d/30/day)
}
return fmt.Sprintf("%d days ago", d/day)
return fmt.Sprintf("%d years ago", d/365/day)
}

func yearRangeFunc(year int) string {
Expand Down

0 comments on commit 00d01d4

Please sign in to comment.