diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index c82f88a42f..b7bef20560 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -139,6 +139,7 @@ func NewFuncMap() []template.FuncMap {
"CountFmt": base.FormatNumberSI,
"TimeSince": timeutil.TimeSince,
"TimeSinceUnix": timeutil.TimeSinceUnix,
+ "DateTime": timeutil.DateTime,
"Sec2Time": util.SecToTime,
"DateFmtLong": func(t time.Time) string {
return t.Format(time.RFC3339)
diff --git a/modules/timeutil/datetime.go b/modules/timeutil/datetime.go
new file mode 100644
index 0000000000..02275bca0c
--- /dev/null
+++ b/modules/timeutil/datetime.go
@@ -0,0 +1,25 @@
+// Copyright 2023 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package timeutil
+
+import (
+ "fmt"
+ "html"
+ "html/template"
+)
+
+// DateTime renders an absolute time HTML given a time as a string
+func DateTime(format, datetime, fallback string) template.HTML {
+ datetimeEscaped := html.EscapeString(datetime)
+ fallbackEscaped := html.EscapeString(fallback)
+ switch format {
+ case "short":
+ return template.HTML(fmt.Sprintf(`%s`, datetimeEscaped, fallbackEscaped))
+ case "long":
+ return template.HTML(fmt.Sprintf(`%s`, datetimeEscaped, fallbackEscaped))
+ case "full":
+ return template.HTML(fmt.Sprintf(`%s`, datetimeEscaped, fallbackEscaped))
+ }
+ return template.HTML("error in DateTime")
+}
diff --git a/templates/admin/auth/list.tmpl b/templates/admin/auth/list.tmpl
index 5350672026..f8e15eddef 100644
--- a/templates/admin/auth/list.tmpl
+++ b/templates/admin/auth/list.tmpl
@@ -26,8 +26,8 @@
{{.Name}} |
{{.TypeName}} |
{{if .IsActive}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}} |
- {{template "shared/datetime/short" (dict "Datetime" .UpdatedUnix.FormatLong "Fallback" .UpdatedUnix.FormatShort)}} |
- {{template "shared/datetime/short" (dict "Datetime" .CreatedUnix.FormatLong "Fallback" .CreatedUnix.FormatShort)}} |
+ {{DateTime "short" .UpdatedUnix.FormatLong .UpdatedUnix.FormatShort}} |
+ {{DateTime "short" .CreatedUnix.FormatLong .CreatedUnix.FormatShort}} |
{{svg "octicon-pencil"}} |
{{end}}
diff --git a/templates/admin/cron.tmpl b/templates/admin/cron.tmpl
index 51685112ba..5dd6314944 100644
--- a/templates/admin/cron.tmpl
+++ b/templates/admin/cron.tmpl
@@ -21,8 +21,8 @@
|
{{$.locale.Tr (printf "admin.dashboard.%s" .Name)}} |
{{.Spec}} |
- {{template "shared/datetime/full" (dict "Datetime" (DateFmtLong .Next) "Fallback" (DateFmtLong .Next) )}} |
- {{if gt .Prev.Year 1}}{{template "shared/datetime/full" (dict "Datetime" (DateFmtLong .Prev) "Fallback" (DateFmtLong .Prev) )}}{{else}}N/A{{end}} |
+ {{DateTime "full" (DateFmtLong .Next) (DateFmtLong .Next)}} |
+ {{if gt .Prev.Year 1}}{{DateTime "full" (DateFmtLong .Prev) (DateFmtLong .Prev)}}{{else}}N/A{{end}} |
{{.ExecTimes}} |
{{if eq .Status ""}}—{{else if eq .Status "finished"}}{{svg "octicon-check" 16}}{{else}}{{svg "octicon-x" 16}}{{end}} |
diff --git a/templates/admin/notice.tmpl b/templates/admin/notice.tmpl
index 82acb14247..51b0c6850a 100644
--- a/templates/admin/notice.tmpl
+++ b/templates/admin/notice.tmpl
@@ -26,7 +26,7 @@
{{.ID}} |
{{$.locale.Tr .TrStr}} |
{{.Description}} |
- {{template "shared/datetime/short" (dict "Datetime" .CreatedUnix.FormatLong "Fallback" .CreatedUnix.FormatShort)}} |
+ {{DateTime "short" .CreatedUnix.FormatLong .CreatedUnix.FormatShort}} |
{{svg "octicon-note" 16 "view-detail"}} |
{{end}}
diff --git a/templates/admin/org/list.tmpl b/templates/admin/org/list.tmpl
index 2e8a635985..73435fdd37 100644
--- a/templates/admin/org/list.tmpl
+++ b/templates/admin/org/list.tmpl
@@ -41,7 +41,7 @@
{{.NumTeams}} |
{{.NumMembers}} |
{{.NumRepos}} |
- {{template "shared/datetime/short" (dict "Datetime" .CreatedUnix.FormatLong "Fallback" .CreatedUnix.FormatShort)}} |
+ {{DateTime "short" .CreatedUnix.FormatLong .CreatedUnix.FormatShort}} |
{{svg "octicon-pencil"}} |
{{end}}
diff --git a/templates/admin/packages/list.tmpl b/templates/admin/packages/list.tmpl
index af98e76175..48046f4296 100644
--- a/templates/admin/packages/list.tmpl
+++ b/templates/admin/packages/list.tmpl
@@ -65,7 +65,7 @@
{{end}}
{{FileSize .CalculateBlobSize}} |
- {{template "shared/datetime/short" (dict "Datetime" .Version.CreatedUnix.FormatLong "Fallback" .Version.CreatedUnix.FormatShort)}} |
+ {{DateTime "short" .Version.CreatedUnix.FormatLong .Version.CreatedUnix.FormatShort}} |
{{svg "octicon-trash"}} |
{{end}}
diff --git a/templates/admin/queue.tmpl b/templates/admin/queue.tmpl
index b6ca0de117..79b20dc1a4 100644
--- a/templates/admin/queue.tmpl
+++ b/templates/admin/queue.tmpl
@@ -155,8 +155,8 @@
{{range .Queue.Workers}}
{{.Workers}}{{if .IsFlusher}}{{svg "octicon-sync"}}{{end}} |
- {{template "shared/datetime/full" (dict "Datetime" (DateFmtLong .Start) "Fallback" (DateFmtLong .Start) )}} |
- {{if .HasTimeout}}{{template "shared/datetime/full" (dict "Datetime" (DateFmtLong .Timeout) "Fallback" (DateFmtLong .Timeout) )}}{{else}}-{{end}} |
+ {{DateTime "full" (DateFmtLong .Start) (DateFmtLong .Start)}} |
+ {{if .HasTimeout}}{{DateTime "full" (DateFmtLong .Timeout) (DateFmtLong .Timeout)}}{{else}}-{{end}} |
{{svg "octicon-trash"}}
|
diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl
index 59aa36d19d..06c801774f 100644
--- a/templates/admin/repo/list.tmpl
+++ b/templates/admin/repo/list.tmpl
@@ -80,7 +80,7 @@
{{.NumForks}} |
{{.NumIssues}} |
{{FileSize .Size}} |
- {{template "shared/datetime/short" (dict "Datetime" .CreatedUnix.FormatLong "Fallback" .CreatedUnix.FormatShort)}} |
+ {{DateTime "short" .CreatedUnix.FormatLong .CreatedUnix.FormatShort}} |
{{svg "octicon-trash"}} |
{{end}}
diff --git a/templates/admin/user/list.tmpl b/templates/admin/user/list.tmpl
index c7644b3b4e..fef7c7b27f 100644
--- a/templates/admin/user/list.tmpl
+++ b/templates/admin/user/list.tmpl
@@ -91,9 +91,9 @@
{{if .IsRestricted}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}} |
{{if index $.UsersTwoFaStatus .ID}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}} |
{{.NumRepos}} |
- {{template "shared/datetime/short" (dict "Datetime" .CreatedUnix.FormatLong "Fallback" .CreatedUnix.FormatShort)}} |
+ {{DateTime "short" .CreatedUnix.FormatLong .CreatedUnix.FormatShort}} |
{{if .LastLoginUnix}}
- {{template "shared/datetime/short" (dict "Datetime" .LastLoginUnix.FormatLong "Fallback" .LastLoginUnix.FormatShort)}} |
+ {{DateTime "short" .LastLoginUnix.FormatLong .LastLoginUnix.FormatShort}} |
{{else}}
{{$.locale.Tr "admin.users.never_login"}} |
{{end}}
diff --git a/templates/explore/organizations.tmpl b/templates/explore/organizations.tmpl
index fe9359251b..e61a72b6ed 100644
--- a/templates/explore/organizations.tmpl
+++ b/templates/explore/organizations.tmpl
@@ -23,7 +23,7 @@
{{svg "octicon-link"}}
{{.Website}}
{{end}}
- {{svg "octicon-clock"}} {{$.locale.Tr "user.join_on"}} {{template "shared/datetime/short" (dict "Datetime" .CreatedUnix.FormatLong "Fallback" .CreatedUnix.FormatShort)}}
+ {{svg "octicon-clock"}} {{$.locale.Tr "user.join_on"}} {{DateTime "short" .CreatedUnix.FormatLong .CreatedUnix.FormatShort}}
diff --git a/templates/explore/users.tmpl b/templates/explore/users.tmpl
index 5dbc4ef6e7..4cab94ee86 100644
--- a/templates/explore/users.tmpl
+++ b/templates/explore/users.tmpl
@@ -18,7 +18,7 @@
{{svg "octicon-mail"}}
{{.Email}}
{{end}}
- {{svg "octicon-clock"}} {{$.locale.Tr "user.join_on"}} {{template "shared/datetime/short" (dict "Datetime" .CreatedUnix.FormatLong "Fallback" .CreatedUnix.FormatShort)}}
+ {{svg "octicon-clock"}} {{$.locale.Tr "user.join_on"}} {{DateTime "short" .CreatedUnix.FormatLong .CreatedUnix.FormatShort}}
diff --git a/templates/package/shared/cleanup_rules/preview.tmpl b/templates/package/shared/cleanup_rules/preview.tmpl
index f9c9bc71f0..ae1ce1b1d5 100644
--- a/templates/package/shared/cleanup_rules/preview.tmpl
+++ b/templates/package/shared/cleanup_rules/preview.tmpl
@@ -22,7 +22,7 @@
{{.Version.Version}} |
{{.Creator.Name}} |
{{FileSize .CalculateBlobSize}} |
- {{template "shared/datetime/short" (dict "Datetime" .Version.CreatedUnix.FormatLong "Fallback" .Version.CreatedUnix.FormatShort)}} |
+ {{DateTime "short" .Version.CreatedUnix.FormatLong .Version.CreatedUnix.FormatShort}} |
{{else}}
diff --git a/templates/package/view.tmpl b/templates/package/view.tmpl
index 7c622a91b3..36b0e8a8b3 100644
--- a/templates/package/view.tmpl
+++ b/templates/package/view.tmpl
@@ -86,7 +86,7 @@
{{range .LatestVersions}}
{{.Version}}
-
{{template "shared/datetime/short" (dict "Datetime" (.CreatedUnix.FormatDate) "Fallback" (.CreatedUnix.FormatDate))}}
+
{{DateTime "short" (.CreatedUnix.FormatDate) (.CreatedUnix.FormatDate)}}
{{end}}
diff --git a/templates/repo/activity.tmpl b/templates/repo/activity.tmpl
index aa71fe838b..26734e304a 100644
--- a/templates/repo/activity.tmpl
+++ b/templates/repo/activity.tmpl
@@ -2,7 +2,7 @@
{{template "repo/header" .}}
-
{{else if eq .Type 19}}
diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl
index bab9ff1936..a8ca0331c7 100644
--- a/templates/repo/issue/view_content/sidebar.tmpl
+++ b/templates/repo/issue/view_content/sidebar.tmpl
@@ -385,7 +385,7 @@
{{svg "octicon-calendar" 16 "gt-mr-3"}}
- {{template "shared/datetime/long" (dict "Datetime" .Issue.DeadlineUnix.FormatDate "Fallback" .Issue.DeadlineUnix.FormatDate)}}
+ {{DateTime "long" .Issue.DeadlineUnix.FormatDate .Issue.DeadlineUnix.FormatDate}}
{{if and .HasIssuesOrPullsWritePermission (not .Repository.IsArchived)}}
diff --git a/templates/repo/settings/deploy_keys.tmpl b/templates/repo/settings/deploy_keys.tmpl
index e577fcc5fa..584a6ee1a6 100644
--- a/templates/repo/settings/deploy_keys.tmpl
+++ b/templates/repo/settings/deploy_keys.tmpl
@@ -60,7 +60,7 @@
{{.Fingerprint}}
- {{$.locale.Tr "settings.add_on"}} {{template "shared/datetime/short" (dict "Datetime" .CreatedUnix.FormatLong "Fallback" .CreatedUnix.FormatShort)}} — {{svg "octicon-info"}} {{if .HasUsed}}{{$.locale.Tr "settings.last_used"}} {{template "shared/datetime/short" (dict "Datetime" .UpdatedUnix.FormatLong "Fallback" .UpdatedUnix.FormatShort)}}{{else}}{{$.locale.Tr "settings.no_activity"}}{{end}} - {{$.locale.Tr "settings.can_read_info"}}{{if not .IsReadOnly}} / {{$.locale.Tr "settings.can_write_info"}} {{end}}
+ {{$.locale.Tr "settings.add_on"}} {{DateTime "short" .CreatedUnix.FormatLong .CreatedUnix.FormatShort}} — {{svg "octicon-info"}} {{if .HasUsed}}{{$.locale.Tr "settings.last_used"}} {{DateTime "short" .UpdatedUnix.FormatLong .UpdatedUnix.FormatShort}}{{else}}{{$.locale.Tr "settings.no_activity"}}{{end}} - {{$.locale.Tr "settings.can_read_info"}}{{if not .IsReadOnly}} / {{$.locale.Tr "settings.can_write_info"}} {{end}}
diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl
index 9440f265fc..0f69dac53c 100644
--- a/templates/repo/settings/options.tmpl
+++ b/templates/repo/settings/options.tmpl
@@ -89,7 +89,7 @@
{{(MirrorRemoteAddress $.Context .Repository .Mirror.GetRemoteName false).Address}} |
{{$.locale.Tr "repo.settings.mirror_settings.direction.pull"}} |
- {{template "shared/datetime/full" (dict "Datetime" .Mirror.UpdatedUnix.FormatLong "Fallback" .Mirror.UpdatedUnix.AsTime)}} |
+ {{DateTime "full" .Mirror.UpdatedUnix.FormatLong .Mirror.UpdatedUnix.AsTime}} |
|