Skip to content

Commit 7f6220c

Browse files
committed
replace DateTime
1 parent 58eb16e commit 7f6220c

File tree

33 files changed

+73
-37
lines changed

33 files changed

+73
-37
lines changed

modules/templates/helper.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func NewFuncMap() template.FuncMap {
5454
"StringUtils": NewStringUtils,
5555
"SliceUtils": NewSliceUtils,
5656
"JsonUtils": NewJsonUtils,
57+
"DateUtils": NewDateUtils, // TODO: to be replaced by DateUtils
5758

5859
// -----------------------------------------------------------------
5960
// svg / avatar / icon / color

modules/templates/util_date.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package templates
5+
6+
import (
7+
"context"
8+
"html/template"
9+
10+
"code.gitea.io/gitea/modules/timeutil"
11+
)
12+
13+
type DateUtils struct {
14+
ctx context.Context
15+
}
16+
17+
func NewDateUtils(ctx context.Context) *DateUtils {
18+
return &DateUtils{ctx}
19+
}
20+
21+
// AbsoluteShort renders in "Jan 01, 2006" format
22+
func (du *DateUtils) AbsoluteShort(time any) template.HTML {
23+
return timeutil.DateTime("short", time)
24+
}
25+
26+
// AbsoluteLong renders in "January 01, 2006" format
27+
func (du *DateUtils) AbsoluteLong(time any) template.HTML {
28+
return timeutil.DateTime("short", time)
29+
}
30+
31+
// FullTime renders in "Jan 01, 2006 20:33:44" format
32+
func (du *DateUtils) FullTime(time any) template.HTML {
33+
return timeutil.DateTime("full", time)
34+
}

routers/web/repo/activity.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ func Activity(ctx *context.Context) {
4848
ctx.Data["Period"] = "weekly"
4949
timeFrom = timeUntil.Add(-time.Hour * 168)
5050
}
51-
ctx.Data["DateFrom"] = timeFrom.UTC().Format(time.RFC3339)
52-
ctx.Data["DateUntil"] = timeUntil.UTC().Format(time.RFC3339)
51+
ctx.Data["DateFrom"] = timeFrom
52+
ctx.Data["DateUntil"] = timeUntil
5353
ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + ctx.Data["Period"].(string))
5454

5555
var err error

services/context/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func NewTemplateContextForWeb(ctx *Context) TemplateContext {
100100
tmplCtx := NewTemplateContext(ctx)
101101
tmplCtx["Locale"] = ctx.Base.Locale
102102
tmplCtx["AvatarUtils"] = templates.NewAvatarUtils(ctx)
103+
tmplCtx["DateUtils"] = templates.NewDateUtils(ctx)
103104
tmplCtx["RootData"] = ctx.Data
104105
tmplCtx["Consts"] = map[string]any{
105106
"RepoUnitTypeCode": unit.TypeCode,

templates/admin/auth/list.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
<td><a href="{{AppSubUrl}}/-/admin/auths/{{.ID}}">{{.Name}}</a></td>
2727
<td>{{.TypeName}}</td>
2828
<td>{{svg (Iif .IsActive "octicon-check" "octicon-x")}}</td>
29-
<td>{{DateTime "short" .UpdatedUnix}}</td>
30-
<td>{{DateTime "short" .CreatedUnix}}</td>
29+
<td>{{ctx.DateUtils.AbsoluteShort .UpdatedUnix}}</td>
30+
<td>{{ctx.DateUtils.AbsoluteShort .CreatedUnix}}</td>
3131
<td><a href="{{AppSubUrl}}/-/admin/auths/{{.ID}}">{{svg "octicon-pencil"}}</a></td>
3232
</tr>
3333
{{end}}

templates/admin/cron.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
<td><button type="submit" class="ui primary button" name="op" value="{{.Name}}" title="{{ctx.Locale.Tr "admin.dashboard.operation_run"}}">{{svg "octicon-triangle-right"}}</button></td>
2424
<td>{{ctx.Locale.Tr (printf "admin.dashboard.%s" .Name)}}</td>
2525
<td>{{.Spec}}</td>
26-
<td>{{DateTime "full" .Next}}</td>
27-
<td>{{if gt .Prev.Year 1}}{{DateTime "full" .Prev}}{{else}}-{{end}}</td>
26+
<td>{{ctx.DateUtils.FullTime .Next}}</td>
27+
<td>{{if gt .Prev.Year 1}}{{ctx.DateUtils.FullTime .Prev}}{{else}}-{{end}}</td>
2828
<td>{{.ExecTimes}}</td>
2929
<td {{if ne .Status ""}}data-tooltip-content="{{.FormatLastMessage ctx.Locale}}"{{end}} >{{if eq .Status ""}}—{{else}}{{svg (Iif (eq .Status "finished") "octicon-check" "octicon-x") 16}}{{end}}</td>
3030
</tr>

templates/admin/notice.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<td>{{.ID}}</td>
2222
<td>{{ctx.Locale.Tr .TrStr}}</td>
2323
<td class="view-detail auto-ellipsis tw-w-4/5"><span class="notice-description">{{.Description}}</span></td>
24-
<td nowrap>{{DateTime "short" .CreatedUnix}}</td>
24+
<td nowrap>{{ctx.DateUtils.AbsoluteShort .CreatedUnix}}</td>
2525
<td class="view-detail"><a href="#">{{svg "octicon-note" 16}}</a></td>
2626
</tr>
2727
{{end}}

templates/admin/org/list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<td>{{.NumTeams}}</td>
6464
<td>{{.NumMembers}}</td>
6565
<td>{{.NumRepos}}</td>
66-
<td>{{DateTime "short" .CreatedUnix}}</td>
66+
<td>{{ctx.DateUtils.AbsoluteShort .CreatedUnix}}</td>
6767
<td><a href="{{.OrganisationLink}}/settings" data-tooltip-content="{{ctx.Locale.Tr "edit"}}">{{svg "octicon-pencil"}}</a></td>
6868
</tr>
6969
{{end}}

templates/admin/packages/list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
{{end}}
7272
</td>
7373
<td>{{FileSize .CalculateBlobSize}}</td>
74-
<td>{{DateTime "short" .Version.CreatedUnix}}</td>
74+
<td>{{ctx.DateUtils.AbsoluteShort .Version.CreatedUnix}}</td>
7575
<td><a class="delete-button" href="" data-url="{{$.Link}}/delete?page={{$.Page.Paginater.Current}}&sort={{$.SortType}}" data-id="{{.Version.ID}}" data-name="{{.Package.Name}}" data-data-version="{{.Version.Version}}">{{svg "octicon-trash"}}</a></td>
7676
</tr>
7777
{{end}}

templates/admin/repo/list.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
<td>{{.NumIssues}}</td>
8383
<td>{{FileSize .GitSize}}</td>
8484
<td>{{FileSize .LFSSize}}</td>
85-
<td>{{DateTime "short" .UpdatedUnix}}</td>
86-
<td>{{DateTime "short" .CreatedUnix}}</td>
85+
<td>{{ctx.DateUtils.AbsoluteShort .UpdatedUnix}}</td>
86+
<td>{{ctx.DateUtils.AbsoluteShort .CreatedUnix}}</td>
8787
<td><a class="delete-button" href="" data-url="{{$.Link}}/delete?page={{$.Page.Paginater.Current}}&sort={{$.SortType}}" data-id="{{.ID}}" data-name="{{.Name}}">{{svg "octicon-trash"}}</a></td>
8888
</tr>
8989
{{end}}

0 commit comments

Comments
 (0)