aboutsummaryrefslogtreecommitdiffhomepage
path: root/template
diff options
context:
space:
mode:
authorGravatar ariddell <ariddell@users.noreply.github.com>2018-11-11 06:43:42 -0500
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-11-17 12:09:02 -0800
commit3d04d92aa271c4b215460e086b9a50ade00eeea3 (patch)
treea22f0c047af6bf6eb18f9014c0628822c81e4776 /template
parent5cd7152ae7a136bc29a339aae4e363c1f9e7c1c5 (diff)
Improve time since post date displays
- 15 days now is "15 days" rather than "3 weeks" ago. - 32 days is now "1 month" rather than "2 months" ago. - 366 days is now "1 year" rather than "2 years" ago. Closes #267
Diffstat (limited to 'template')
-rw-r--r--template/functions.go8
-rw-r--r--template/functions_test.go6
2 files changed, 9 insertions, 5 deletions
diff --git a/template/functions.go b/template/functions.go
index 289de3d..84a02f4 100644
--- a/template/functions.go
+++ b/template/functions.go
@@ -162,16 +162,16 @@ func elapsedTime(printer *locale.Printer, tz string, t time.Time) string {
return printer.Plural("time_elapsed.hours", hours, hours)
case d == 1:
return printer.Printf("time_elapsed.yesterday")
- case d < 7:
+ case d < 21:
return printer.Plural("time_elapsed.days", d, d)
case d < 31:
- weeks := int(math.Ceil(float64(d) / 7))
+ weeks := int(math.Round(float64(d) / 7))
return printer.Plural("time_elapsed.weeks", weeks, weeks)
case d < 365:
- months := int(math.Ceil(float64(d) / 30))
+ months := int(math.Round(float64(d) / 30))
return printer.Plural("time_elapsed.months", months, months)
default:
- years := int(math.Ceil(float64(d) / 365))
+ years := int(math.Round(float64(d) / 365))
return printer.Plural("time_elapsed.years", years, years)
}
}
diff --git a/template/functions_test.go b/template/functions_test.go
index 10d5535..1bfb919 100644
--- a/template/functions_test.go
+++ b/template/functions_test.go
@@ -111,8 +111,12 @@ func TestElapsedTime(t *testing.T) {
{time.Now().Add(-time.Hour * 3), printer.Plural("time_elapsed.hours", 3, 3)},
{time.Now().Add(-time.Hour * 32), printer.Printf("time_elapsed.yesterday")},
{time.Now().Add(-time.Hour * 24 * 3), printer.Plural("time_elapsed.days", 3, 3)},
- {time.Now().Add(-time.Hour * 24 * 14), printer.Plural("time_elapsed.weeks", 2, 2)},
+ {time.Now().Add(-time.Hour * 24 * 14), printer.Plural("time_elapsed.days", 14, 14)},
+ {time.Now().Add(-time.Hour * 24 * 15), printer.Plural("time_elapsed.days", 15, 15)},
+ {time.Now().Add(-time.Hour * 24 * 21), printer.Plural("time_elapsed.weeks", 3, 3)},
+ {time.Now().Add(-time.Hour * 24 * 32), printer.Plural("time_elapsed.months", 1, 1)},
{time.Now().Add(-time.Hour * 24 * 60), printer.Plural("time_elapsed.months", 2, 2)},
+ {time.Now().Add(-time.Hour * 24 * 366), printer.Plural("time_elapsed.years", 1, 1)},
{time.Now().Add(-time.Hour * 24 * 365 * 3), printer.Plural("time_elapsed.years", 3, 3)},
}
for i, tt := range dt {