aboutsummaryrefslogtreecommitdiffstats
path: root/modules/templates
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-11-02 12:08:28 +0800
committerGitHub <noreply@github.com>2024-11-02 04:08:28 +0000
commitfec6b3d50072e48bb51c18c5c4ea682dc6319573 (patch)
treea2a90692cb4c91ea10ecc85d39b5c582e2af0b25 /modules/templates
parent7dcccc3bb19655a6f83dd495ffc332708d0c8678 (diff)
downloadgitea-fec6b3d50072e48bb51c18c5c4ea682dc6319573.tar.gz
gitea-fec6b3d50072e48bb51c18c5c4ea682dc6319573.zip
Replace DateTime with DateUtils (#32383)
Diffstat (limited to 'modules/templates')
-rw-r--r--modules/templates/helper.go1
-rw-r--r--modules/templates/util_date.go34
2 files changed, 35 insertions, 0 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index 5f73e6b278..5038e8a132 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -54,6 +54,7 @@ func NewFuncMap() template.FuncMap {
"StringUtils": NewStringUtils,
"SliceUtils": NewSliceUtils,
"JsonUtils": NewJsonUtils,
+ "DateUtils": NewDateUtils, // TODO: to be replaced by DateUtils
// -----------------------------------------------------------------
// svg / avatar / icon / color
diff --git a/modules/templates/util_date.go b/modules/templates/util_date.go
new file mode 100644
index 0000000000..ec48a7e4be
--- /dev/null
+++ b/modules/templates/util_date.go
@@ -0,0 +1,34 @@
+// Copyright 2024 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package templates
+
+import (
+ "context"
+ "html/template"
+
+ "code.gitea.io/gitea/modules/timeutil"
+)
+
+type DateUtils struct {
+ ctx context.Context
+}
+
+func NewDateUtils(ctx context.Context) *DateUtils {
+ return &DateUtils{ctx}
+}
+
+// AbsoluteShort renders in "Jan 01, 2006" format
+func (du *DateUtils) AbsoluteShort(time any) template.HTML {
+ return timeutil.DateTime("short", time)
+}
+
+// AbsoluteLong renders in "January 01, 2006" format
+func (du *DateUtils) AbsoluteLong(time any) template.HTML {
+ return timeutil.DateTime("short", time)
+}
+
+// FullTime renders in "Jan 01, 2006 20:33:44" format
+func (du *DateUtils) FullTime(time any) template.HTML {
+ return timeutil.DateTime("full", time)
+}