From cf1b23c001098411b6b18ea14a2bef17f6002e63 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Tue, 11 Oct 2022 13:05:17 +0000 Subject: [PATCH 1/7] Respect user's locale when rendering the date range in the repo activity page Previously, to make the date range understood by all, we used the format "2006-01-02" for the dates as it's locale-generic. This commit changes the rendering logic. Instead of rendering the date on the server, we send a formatted computer-readable timestamp. The client's javascript then renders it according to the user's locale. This approach is reusable across the codebase, any tag with the "data-format-text-according-to-datetime" attribute would get rendered according to the user's chosen locale. Signed-off-by: Yarden Shoham --- routers/web/repo/activity.go | 4 ++-- templates/repo/activity.tmpl | 2 +- web_src/js/features/formatting.js | 10 ++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/routers/web/repo/activity.go b/routers/web/repo/activity.go index a1f1106159c51..316cbcd95f3b6 100644 --- a/routers/web/repo/activity.go +++ b/routers/web/repo/activity.go @@ -47,8 +47,8 @@ func Activity(ctx *context.Context) { ctx.Data["Period"] = "weekly" timeFrom = timeUntil.Add(-time.Hour * 168) } - ctx.Data["DateFrom"] = timeFrom.Format("2006-01-02") - ctx.Data["DateUntil"] = timeUntil.Format("2006-01-02") + ctx.Data["DateFrom"] = timeFrom.UTC().Format(time.RFC3339) + ctx.Data["DateUntil"] = timeUntil.UTC().Format(time.RFC3339) ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + ctx.Data["Period"].(string)) var err error diff --git a/templates/repo/activity.tmpl b/templates/repo/activity.tmpl index c2f6c2d982e05..963ff18c0f8a2 100644 --- a/templates/repo/activity.tmpl +++ b/templates/repo/activity.tmpl @@ -2,7 +2,7 @@
{{template "repo/header" .}}
-

{{.DateFrom}} - {{.DateUntil}} +

-