diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index 51f526f889..f7aaad1f31 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -29,7 +29,8 @@ size: 7597 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false - + created_unix: 1731254961 + updated_unix: 1731254961 - id: 2 owner_id: 2 diff --git a/modules/gitgraph/graph.go b/modules/gitgraph/graph.go index 331ad6b218..4db5598015 100644 --- a/modules/gitgraph/graph.go +++ b/modules/gitgraph/graph.go @@ -16,7 +16,7 @@ import ( // GetCommitGraph return a list of commit (GraphItems) from all branches func GetCommitGraph(r *git.Repository, page, maxAllowedColors int, hidePRRefs bool, branches, files []string) (*Graph, error) { - format := "DATA:%D|%H|%ad|%h|%s" + format := "DATA:%D|%H|%aD|%h|%s" if page == 0 { page = 1 diff --git a/modules/gitgraph/graph_models.go b/modules/gitgraph/graph_models.go index 82f460ecf0..8ff1a6e916 100644 --- a/modules/gitgraph/graph_models.go +++ b/modules/gitgraph/graph_models.go @@ -8,6 +8,7 @@ import ( "context" "fmt" "strings" + "time" asymkey_model "code.gitea.io/gitea/models/asymkey" "code.gitea.io/gitea/models/db" @@ -198,6 +199,11 @@ func NewCommit(row, column int, line []byte) (*Commit, error) { if len(data) < 5 { return nil, fmt.Errorf("malformed data section on line %d with commit: %s", row, string(line)) } + // Format is a slight modifcation from RFC1123Z + t, err := time.Parse("Mon, _2 Jan 2006 15:04:05 -0700", string(data[2])) + if err != nil { + return nil, fmt.Errorf("could not parse date of commit: %w", err) + } return &Commit{ Row: row, Column: column, @@ -205,8 +211,8 @@ func NewCommit(row, column int, line []byte) (*Commit, error) { Refs: newRefsFromRefNames(data[0]), // 1 matches git log --pretty=format:%H => commit hash Rev: string(data[1]), - // 2 matches git log --pretty=format:%ad => author date (format respects --date= option) - Date: string(data[2]), + // 2 matches git log --pretty=format:%aD => author date, RFC2822 style + Date: t, // 3 matches git log --pretty=format:%h => abbreviated commit hash ShortRev: string(data[3]), // 4 matches git log --pretty=format:%s => subject @@ -245,7 +251,7 @@ type Commit struct { Column int Refs []git.Reference Rev string - Date string + Date time.Time ShortRev string Subject string } diff --git a/modules/gitgraph/graph_test.go b/modules/gitgraph/graph_test.go index 18d427acd9..e7e437e42d 100644 --- a/modules/gitgraph/graph_test.go +++ b/modules/gitgraph/graph_test.go @@ -241,7 +241,7 @@ func TestParseGlyphs(t *testing.T) { } func TestCommitStringParsing(t *testing.T) { - dataFirstPart := "* DATA:|4e61bacab44e9b4730e44a6615d04098dd3a8eaf|2016-12-20 21:10:41 +0100|4e61bac|" + dataFirstPart := "* DATA:|4e61bacab44e9b4730e44a6615d04098dd3a8eaf|Tue, 20 Dec 2016 21:10:41 +0100|4e61bac|" tests := []struct { shouldPass bool testName string diff --git a/modules/templates/helper.go b/modules/templates/helper.go index a1f3f1aa2d..55de85646c 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -20,7 +20,6 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/svg" "code.gitea.io/gitea/modules/templates/eval" - "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/services/gitdiff" ) @@ -65,16 +64,18 @@ func NewFuncMap() template.FuncMap { // ----------------------------------------------------------------- // time / number / format - "FileSize": FileSizePanic, - "CountFmt": base.FormatNumberSI, - "TimeSince": timeutil.TimeSince, - "TimeSinceUnix": timeutil.TimeSinceUnix, - "DateTime": dateTimeLegacy, // for backward compatibility only, do not use it anymore - "Sec2Time": util.SecToTime, + "FileSize": FileSizePanic, + "CountFmt": base.FormatNumberSI, + "Sec2Time": util.SecToTime, "LoadTimes": func(startTime time.Time) string { return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms" }, + // for backward compatibility only, do not use them anymore + "TimeSince": timeSinceLegacy, + "TimeSinceUnix": timeSinceLegacy, + "DateTime": dateTimeLegacy, + // ----------------------------------------------------------------- // setting "AppName": func() string { diff --git a/modules/templates/util_date.go b/modules/templates/util_date.go index 10f7cdb508..f521b39b79 100644 --- a/modules/templates/util_date.go +++ b/modules/templates/util_date.go @@ -4,35 +4,40 @@ package templates import ( - "context" + "fmt" + "html" "html/template" + "strings" "time" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" + "code.gitea.io/gitea/modules/translation" ) -type DateUtils struct { - ctx context.Context -} +type DateUtils struct{} -func NewDateUtils(ctx context.Context) *DateUtils { - return &DateUtils{ctx} +func NewDateUtils() *DateUtils { + return (*DateUtils)(nil) // the util is stateless, and we do not need to create an instance } // AbsoluteShort renders in "Jan 01, 2006" format func (du *DateUtils) AbsoluteShort(time any) template.HTML { - return timeutil.DateTime("short", time) + return dateTimeFormat("short", time) } // AbsoluteLong renders in "January 01, 2006" format func (du *DateUtils) AbsoluteLong(time any) template.HTML { - return timeutil.DateTime("long", time) + return dateTimeFormat("long", time) } // FullTime renders in "Jan 01, 2006 20:33:44" format func (du *DateUtils) FullTime(time any) template.HTML { - return timeutil.DateTime("full", time) + return dateTimeFormat("full", time) +} + +func (du *DateUtils) TimeSince(time any) template.HTML { + return TimeSince(time) } // ParseLegacy parses the datetime in legacy format, eg: "2016-01-02" in server's timezone. @@ -56,5 +61,91 @@ func dateTimeLegacy(format string, datetime any, _ ...string) template.HTML { if s, ok := datetime.(string); ok { datetime = parseLegacy(s) } - return timeutil.DateTime(format, datetime) + return dateTimeFormat(format, datetime) +} + +func timeSinceLegacy(time any, _ translation.Locale) template.HTML { + if !setting.IsProd || setting.IsInTesting { + panic("timeSinceLegacy is for backward compatibility only, do not use it in new code") + } + return TimeSince(time) +} + +func anyToTime(any any) (t time.Time, isZero bool) { + switch v := any.(type) { + case nil: + // it is zero + case *time.Time: + if v != nil { + t = *v + } + case time.Time: + t = v + case timeutil.TimeStamp: + t = v.AsTime() + case timeutil.TimeStampNano: + t = v.AsTime() + case int: + t = timeutil.TimeStamp(v).AsTime() + case int64: + t = timeutil.TimeStamp(v).AsTime() + default: + panic(fmt.Sprintf("Unsupported time type %T", any)) + } + return t, t.IsZero() || t.Unix() == 0 +} + +func dateTimeFormat(format string, datetime any) template.HTML { + t, isZero := anyToTime(datetime) + if isZero { + return "-" + } + var textEscaped string + datetimeEscaped := html.EscapeString(t.Format(time.RFC3339)) + if format == "full" { + textEscaped = html.EscapeString(t.Format("2006-01-02 15:04:05 -07:00")) + } else { + textEscaped = html.EscapeString(t.Format("2006-01-02")) + } + + attrs := []string{`weekday=""`, `year="numeric"`} + switch format { + case "short", "long": // date only + attrs = append(attrs, `month="`+format+`"`, `day="numeric"`) + return template.HTML(fmt.Sprintf(`<absolute-date %s date="%s">%s</absolute-date>`, strings.Join(attrs, " "), datetimeEscaped, textEscaped)) + case "full": // full date including time + attrs = append(attrs, `format="datetime"`, `month="short"`, `day="numeric"`, `hour="numeric"`, `minute="numeric"`, `second="numeric"`, `data-tooltip-content`, `data-tooltip-interactive="true"`) + return template.HTML(fmt.Sprintf(`<relative-time %s datetime="%s">%s</relative-time>`, strings.Join(attrs, " "), datetimeEscaped, textEscaped)) + default: + panic(fmt.Sprintf("Unsupported format %s", format)) + } +} + +func timeSinceTo(then any, now time.Time) template.HTML { + thenTime, isZero := anyToTime(then) + if isZero { + return "-" + } + + friendlyText := thenTime.Format("2006-01-02 15:04:05 -07:00") + + // document: https://github.com/github/relative-time-element + attrs := `tense="past"` + isFuture := now.Before(thenTime) + if isFuture { + attrs = `tense="future"` + } + + // declare data-tooltip-content attribute to switch from "title" tooltip to "tippy" tooltip + htm := fmt.Sprintf(`<relative-time prefix="" %s datetime="%s" data-tooltip-content data-tooltip-interactive="true">%s</relative-time>`, + attrs, thenTime.Format(time.RFC3339), friendlyText) + return template.HTML(htm) +} + +// TimeSince renders relative time HTML given a time +func TimeSince(then any) template.HTML { + if setting.UI.PreferredTimestampTense == "absolute" { + return dateTimeFormat("full", then) + } + return timeSinceTo(then, time.Now()) } diff --git a/modules/templates/util_date_test.go b/modules/templates/util_date_test.go index e3dec5c8db..2f5c79f762 100644 --- a/modules/templates/util_date_test.go +++ b/modules/templates/util_date_test.go @@ -22,7 +22,7 @@ func TestDateTime(t *testing.T) { defer test.MockVariableValue(&setting.DefaultUILocation, testTz)() defer test.MockVariableValue(&setting.IsInTesting, false)() - du := NewDateUtils(nil) + du := NewDateUtils() refTimeStr := "2018-01-01T00:00:00Z" refDateStr := "2018-01-01" @@ -59,3 +59,24 @@ func TestDateTime(t *testing.T) { actual = du.FullTime(refTimeStamp) assert.EqualValues(t, `<relative-time weekday="" year="numeric" format="datetime" month="short" day="numeric" hour="numeric" minute="numeric" second="numeric" data-tooltip-content data-tooltip-interactive="true" datetime="2017-12-31T19:00:00-05:00">2017-12-31 19:00:00 -05:00</relative-time>`, actual) } + +func TestTimeSince(t *testing.T) { + testTz, _ := time.LoadLocation("America/New_York") + defer test.MockVariableValue(&setting.DefaultUILocation, testTz)() + defer test.MockVariableValue(&setting.IsInTesting, false)() + + du := NewDateUtils() + assert.EqualValues(t, "-", du.TimeSince(nil)) + + refTimeStr := "2018-01-01T00:00:00Z" + refTime, _ := time.Parse(time.RFC3339, refTimeStr) + + actual := du.TimeSince(refTime) + assert.EqualValues(t, `<relative-time prefix="" tense="past" datetime="2018-01-01T00:00:00Z" data-tooltip-content data-tooltip-interactive="true">2018-01-01 00:00:00 +00:00</relative-time>`, actual) + + actual = timeSinceTo(&refTime, time.Time{}) + assert.EqualValues(t, `<relative-time prefix="" tense="future" datetime="2018-01-01T00:00:00Z" data-tooltip-content data-tooltip-interactive="true">2018-01-01 00:00:00 +00:00</relative-time>`, actual) + + actual = timeSinceLegacy(timeutil.TimeStampNano(refTime.UnixNano()), nil) + assert.EqualValues(t, `<relative-time prefix="" tense="past" datetime="2017-12-31T19:00:00-05:00" data-tooltip-content data-tooltip-interactive="true">2017-12-31 19:00:00 -05:00</relative-time>`, actual) +} diff --git a/modules/timeutil/datetime.go b/modules/timeutil/datetime.go deleted file mode 100644 index 664e0320b0..0000000000 --- a/modules/timeutil/datetime.go +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2023 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -package timeutil - -import ( - "fmt" - "html" - "html/template" - "strings" - "time" -) - -// DateTime renders an absolute time HTML element by datetime. -func DateTime(format string, datetime any) template.HTML { - if p, ok := datetime.(*time.Time); ok { - datetime = *p - } - if p, ok := datetime.(*TimeStamp); ok { - datetime = *p - } - switch v := datetime.(type) { - case TimeStamp: - datetime = v.AsTime() - case int: - datetime = TimeStamp(v).AsTime() - case int64: - datetime = TimeStamp(v).AsTime() - } - - var datetimeEscaped, textEscaped string - switch v := datetime.(type) { - case nil: - return "-" - case time.Time: - if v.IsZero() || v.Unix() == 0 { - return "-" - } - datetimeEscaped = html.EscapeString(v.Format(time.RFC3339)) - if format == "full" { - textEscaped = html.EscapeString(v.Format("2006-01-02 15:04:05 -07:00")) - } else { - textEscaped = html.EscapeString(v.Format("2006-01-02")) - } - default: - panic(fmt.Sprintf("Unsupported time type %T", datetime)) - } - - attrs := []string{`weekday=""`, `year="numeric"`} - switch format { - case "short", "long": // date only - attrs = append(attrs, `month="`+format+`"`, `day="numeric"`) - return template.HTML(fmt.Sprintf(`<absolute-date %s date="%s">%s</absolute-date>`, strings.Join(attrs, " "), datetimeEscaped, textEscaped)) - case "full": // full date including time - attrs = append(attrs, `format="datetime"`, `month="short"`, `day="numeric"`, `hour="numeric"`, `minute="numeric"`, `second="numeric"`, `data-tooltip-content`, `data-tooltip-interactive="true"`) - return template.HTML(fmt.Sprintf(`<relative-time %s datetime="%s">%s</relative-time>`, strings.Join(attrs, " "), datetimeEscaped, textEscaped)) - default: - panic(fmt.Sprintf("Unsupported format %s", format)) - } -} diff --git a/modules/timeutil/since.go b/modules/timeutil/since.go index dba42c793a..2c89ae38d5 100644 --- a/modules/timeutil/since.go +++ b/modules/timeutil/since.go @@ -4,12 +4,9 @@ package timeutil import ( - "fmt" - "html/template" "strings" "time" - "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/translation" ) @@ -81,16 +78,11 @@ func computeTimeDiffFloor(diff int64, lang translation.Locale) (int64, string) { return diff, diffStr } -// MinutesToFriendly returns a user friendly string with number of minutes +// MinutesToFriendly returns a user-friendly string with number of minutes // converted to hours and minutes. func MinutesToFriendly(minutes int, lang translation.Locale) string { duration := time.Duration(minutes) * time.Minute - return TimeSincePro(time.Now().Add(-duration), lang) -} - -// TimeSincePro calculates the time interval and generate full user-friendly string. -func TimeSincePro(then time.Time, lang translation.Locale) string { - return timeSincePro(then, time.Now(), lang) + return timeSincePro(time.Now().Add(-duration), time.Now(), lang) } func timeSincePro(then, now time.Time, lang translation.Locale) string { @@ -114,32 +106,3 @@ func timeSincePro(then, now time.Time, lang translation.Locale) string { } return strings.TrimPrefix(timeStr, ", ") } - -func timeSinceUnix(then, now time.Time, _ translation.Locale) template.HTML { - friendlyText := then.Format("2006-01-02 15:04:05 -07:00") - - // document: https://github.com/github/relative-time-element - attrs := `tense="past"` - isFuture := now.Before(then) - if isFuture { - attrs = `tense="future"` - } - - // declare data-tooltip-content attribute to switch from "title" tooltip to "tippy" tooltip - htm := fmt.Sprintf(`<relative-time prefix="" %s datetime="%s" data-tooltip-content data-tooltip-interactive="true">%s</relative-time>`, - attrs, then.Format(time.RFC3339), friendlyText) - return template.HTML(htm) -} - -// TimeSince renders relative time HTML given a time.Time -func TimeSince(then time.Time, lang translation.Locale) template.HTML { - if setting.UI.PreferredTimestampTense == "absolute" { - return DateTime("full", then) - } - return timeSinceUnix(then, time.Now(), lang) -} - -// TimeSinceUnix renders relative time HTML given a TimeStamp -func TimeSinceUnix(then TimeStamp, lang translation.Locale) template.HTML { - return TimeSince(then.AsLocalTime(), lang) -} diff --git a/routers/web/repo/blame.go b/routers/web/repo/blame.go index eea3d4dc00..4f962d4c19 100644 --- a/routers/web/repo/blame.go +++ b/routers/web/repo/blame.go @@ -17,7 +17,6 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/templates" - "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/services/context" files_service "code.gitea.io/gitea/services/repository/files" @@ -254,7 +253,7 @@ func renderBlame(ctx *context.Context, blameParts []*git.BlamePart, commitNames commitCnt++ // User avatar image - commitSince := timeutil.TimeSinceUnix(timeutil.TimeStamp(commit.Author.When.Unix()), ctx.Locale) + commitSince := templates.TimeSince(commit.Author.When) var avatar string if commit.User != nil { diff --git a/routers/web/repo/issue_content_history.go b/routers/web/repo/issue_content_history.go index 16b250abda..4ce76b2bb9 100644 --- a/routers/web/repo/issue_content_history.go +++ b/routers/web/repo/issue_content_history.go @@ -14,7 +14,6 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/templates" - "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/services/context" "github.com/sergi/go-diff/diffmatchpatch" @@ -73,10 +72,10 @@ func GetContentHistoryList(ctx *context.Context) { class := avatars.DefaultAvatarClass + " tw-mr-2" name := html.EscapeString(username) avatarHTML := string(templates.AvatarHTML(src, 28, class, username)) - timeSinceText := string(timeutil.TimeSinceUnix(item.EditedUnix, ctx.Locale)) + timeSinceHTML := string(templates.TimeSince(item.EditedUnix)) results = append(results, map[string]any{ - "name": avatarHTML + "<strong>" + name + "</strong> " + actionText + " " + timeSinceText, + "name": avatarHTML + "<strong>" + name + "</strong> " + actionText + " " + timeSinceHTML, "value": item.HistoryID, }) } diff --git a/services/context/context.go b/services/context/context.go index 65796c3ee7..91e7b1849d 100644 --- a/services/context/context.go +++ b/services/context/context.go @@ -102,7 +102,6 @@ func NewTemplateContextForWeb(ctx *Context) TemplateContext { tmplCtx := NewTemplateContext(ctx) tmplCtx["Locale"] = ctx.Base.Locale tmplCtx["AvatarUtils"] = templates.NewAvatarUtils(ctx) - tmplCtx["DateUtils"] = templates.NewDateUtils(ctx) return tmplCtx } diff --git a/templates/admin/auth/list.tmpl b/templates/admin/auth/list.tmpl index 5b5affad8a..c162b7b74d 100644 --- a/templates/admin/auth/list.tmpl +++ b/templates/admin/auth/list.tmpl @@ -26,8 +26,8 @@ <td><a href="{{AppSubUrl}}/admin/auths/{{.ID}}">{{.Name}}</a></td> <td>{{.TypeName}}</td> <td>{{if .IsActive}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}</td> - <td>{{ctx.DateUtils.AbsoluteShort .UpdatedUnix}}</td> - <td>{{ctx.DateUtils.AbsoluteShort .CreatedUnix}}</td> + <td>{{DateUtils.AbsoluteShort .UpdatedUnix}}</td> + <td>{{DateUtils.AbsoluteShort .CreatedUnix}}</td> <td><a href="{{AppSubUrl}}/admin/auths/{{.ID}}">{{svg "octicon-pencil"}}</a></td> </tr> {{end}} diff --git a/templates/admin/cron.tmpl b/templates/admin/cron.tmpl index 64ae7858ba..ee37f6ca75 100644 --- a/templates/admin/cron.tmpl +++ b/templates/admin/cron.tmpl @@ -23,8 +23,8 @@ <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> <td>{{ctx.Locale.Tr (printf "admin.dashboard.%s" .Name)}}</td> <td>{{.Spec}}</td> - <td>{{ctx.DateUtils.FullTime .Next}}</td> - <td>{{if gt .Prev.Year 1}}{{ctx.DateUtils.FullTime .Prev}}{{else}}-{{end}}</td> + <td>{{DateUtils.FullTime .Next}}</td> + <td>{{if gt .Prev.Year 1}}{{DateUtils.FullTime .Prev}}{{else}}-{{end}}</td> <td>{{.ExecTimes}}</td> <td {{if ne .Status ""}}data-tooltip-content="{{.FormatLastMessage ctx.Locale}}"{{end}} >{{if eq .Status ""}}—{{else if eq .Status "finished"}}{{svg "octicon-check" 16}}{{else}}{{svg "octicon-x" 16}}{{end}}</td> </tr> diff --git a/templates/admin/notice.tmpl b/templates/admin/notice.tmpl index 2db0384f6d..04a0b64432 100644 --- a/templates/admin/notice.tmpl +++ b/templates/admin/notice.tmpl @@ -21,7 +21,7 @@ <td>{{.ID}}</td> <td>{{ctx.Locale.Tr .TrStr}}</td> <td class="view-detail auto-ellipsis tw-w-4/5"><span class="notice-description">{{.Description}}</span></td> - <td nowrap>{{ctx.DateUtils.AbsoluteShort .CreatedUnix}}</td> + <td nowrap>{{DateUtils.AbsoluteShort .CreatedUnix}}</td> <td class="view-detail"><a href="#">{{svg "octicon-note" 16}}</a></td> </tr> {{end}} diff --git a/templates/admin/org/list.tmpl b/templates/admin/org/list.tmpl index 6a6dc14609..d0805c85bc 100644 --- a/templates/admin/org/list.tmpl +++ b/templates/admin/org/list.tmpl @@ -63,7 +63,7 @@ <td>{{.NumTeams}}</td> <td>{{.NumMembers}}</td> <td>{{.NumRepos}}</td> - <td>{{ctx.DateUtils.AbsoluteShort .CreatedUnix}}</td> + <td>{{DateUtils.AbsoluteShort .CreatedUnix}}</td> <td><a href="{{.OrganisationLink}}/settings" data-tooltip-content="{{ctx.Locale.Tr "edit"}}">{{svg "octicon-pencil"}}</a></td> </tr> {{end}} diff --git a/templates/admin/packages/list.tmpl b/templates/admin/packages/list.tmpl index 9cc08772b7..aa38731d4f 100644 --- a/templates/admin/packages/list.tmpl +++ b/templates/admin/packages/list.tmpl @@ -71,7 +71,7 @@ {{end}} </td> <td>{{ctx.Locale.TrSize .CalculateBlobSize}}</td> - <td>{{ctx.DateUtils.AbsoluteShort .Version.CreatedUnix}}</td> + <td>{{DateUtils.AbsoluteShort .Version.CreatedUnix}}</td> <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> </tr> {{end}} diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index 992933154d..c4924c3fac 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -82,8 +82,8 @@ <td>{{.NumIssues}}</td> <td>{{ctx.Locale.TrSize .GitSize}}</td> <td>{{ctx.Locale.TrSize .LFSSize}}</td> - <td>{{ctx.DateUtils.AbsoluteShort .UpdatedUnix}}</td> - <td>{{ctx.DateUtils.AbsoluteShort .CreatedUnix}}</td> + <td>{{DateUtils.AbsoluteShort .UpdatedUnix}}</td> + <td>{{DateUtils.AbsoluteShort .CreatedUnix}}</td> <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> </tr> {{end}} diff --git a/templates/admin/stacktrace-row.tmpl b/templates/admin/stacktrace-row.tmpl index 694bf56d96..97c361ff90 100644 --- a/templates/admin/stacktrace-row.tmpl +++ b/templates/admin/stacktrace-row.tmpl @@ -13,7 +13,7 @@ </div> <div class="content tw-flex-1"> <div class="header">{{.Process.Description}}</div> - <div class="description">{{if ne .Process.Type "none"}}{{TimeSince .Process.Start ctx.Locale}}{{end}}</div> + <div class="description">{{if ne .Process.Type "none"}}{{DateUtils.TimeSince .Process.Start}}{{end}}</div> </div> <div> {{if or (eq .Process.Type "request") (eq .Process.Type "normal")}} diff --git a/templates/admin/user/list.tmpl b/templates/admin/user/list.tmpl index 42879d7917..9b3447f44a 100644 --- a/templates/admin/user/list.tmpl +++ b/templates/admin/user/list.tmpl @@ -96,9 +96,9 @@ <td>{{if .IsActive}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}</td> <td>{{if .IsRestricted}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}</td> <td>{{if index $.UsersTwoFaStatus .ID}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}</td> - <td>{{ctx.DateUtils.AbsoluteShort .CreatedUnix}}</td> + <td>{{DateUtils.AbsoluteShort .CreatedUnix}}</td> {{if .LastLoginUnix}} - <td>{{ctx.DateUtils.AbsoluteShort .LastLoginUnix}}</td> + <td>{{DateUtils.AbsoluteShort .LastLoginUnix}}</td> {{else}} <td><span>{{ctx.Locale.Tr "admin.users.never_login"}}</span></td> {{end}} diff --git a/templates/devtest/gitea-ui.tmpl b/templates/devtest/gitea-ui.tmpl index 8c5db4d887..5490f71784 100644 --- a/templates/devtest/gitea-ui.tmpl +++ b/templates/devtest/gitea-ui.tmpl @@ -167,13 +167,13 @@ <div> <h1>TimeSince</h1> - <div>Now: {{TimeSince .TimeNow ctx.Locale}}</div> - <div>5s past: {{TimeSince .TimePast5s ctx.Locale}}</div> - <div>5s future: {{TimeSince .TimeFuture5s ctx.Locale}}</div> - <div>2m past: {{TimeSince .TimePast2m ctx.Locale}}</div> - <div>2m future: {{TimeSince .TimeFuture2m ctx.Locale}}</div> - <div>1y past: {{TimeSince .TimePast1y ctx.Locale}}</div> - <div>1y future: {{TimeSince .TimeFuture1y ctx.Locale}}</div> + <div>Now: {{DateUtils.TimeSince .TimeNow}}</div> + <div>5s past: {{DateUtils.TimeSince .TimePast5s}}</div> + <div>5s future: {{DateUtils.TimeSince .TimeFuture5s}}</div> + <div>2m past: {{DateUtils.TimeSince .TimePast2m}}</div> + <div>2m future: {{DateUtils.TimeSince .TimeFuture2m}}</div> + <div>1y past: {{DateUtils.TimeSince .TimePast1y}}</div> + <div>1y future: {{DateUtils.TimeSince .TimeFuture1y}}</div> </div> <div> diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index 59bc6c8a95..f11f2e94ef 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -62,7 +62,7 @@ {{end}} </div> {{end}} - <div class="flex-item-body">{{ctx.Locale.Tr "org.repo_updated" (TimeSinceUnix .UpdatedUnix ctx.Locale)}}</div> + <div class="flex-item-body">{{ctx.Locale.Tr "org.repo_updated" (DateUtils.TimeSince .UpdatedUnix)}}</div> </div> </div> {{else}} diff --git a/templates/explore/user_list.tmpl b/templates/explore/user_list.tmpl index ff46f13c17..4128a489aa 100644 --- a/templates/explore/user_list.tmpl +++ b/templates/explore/user_list.tmpl @@ -21,7 +21,7 @@ <a href="mailto:{{.Email}}">{{.Email}}</a> </span> {{end}} - <span class="flex-text-inline">{{svg "octicon-calendar"}}{{ctx.Locale.Tr "user.joined_on" (ctx.DateUtils.AbsoluteShort .CreatedUnix)}}</span> + <span class="flex-text-inline">{{svg "octicon-calendar"}}{{ctx.Locale.Tr "user.joined_on" (DateUtils.AbsoluteShort .CreatedUnix)}}</span> </div> </div> </div> diff --git a/templates/package/shared/cleanup_rules/preview.tmpl b/templates/package/shared/cleanup_rules/preview.tmpl index ced1e5c11b..da034fec7a 100644 --- a/templates/package/shared/cleanup_rules/preview.tmpl +++ b/templates/package/shared/cleanup_rules/preview.tmpl @@ -22,7 +22,7 @@ <td><a href="{{.VersionWebLink}}">{{.Version.Version}}</a></td> <td><a href="{{.Creator.HomeLink}}">{{.Creator.Name}}</a></td> <td>{{ctx.Locale.TrSize .CalculateBlobSize}}</td> - <td>{{ctx.DateUtils.AbsoluteShort .Version.CreatedUnix}}</td> + <td>{{DateUtils.AbsoluteShort .Version.CreatedUnix}}</td> </tr> {{else}} <tr> diff --git a/templates/package/shared/list.tmpl b/templates/package/shared/list.tmpl index 36f8bc1522..19b41d0bc8 100644 --- a/templates/package/shared/list.tmpl +++ b/templates/package/shared/list.tmpl @@ -24,7 +24,7 @@ <span class="ui label">{{svg .Package.Type.SVGName 16}} {{.Package.Type.Name}}</span> </div> <div class="flex-item-body"> - {{$timeStr := TimeSinceUnix .Version.CreatedUnix ctx.Locale}} + {{$timeStr := DateUtils.TimeSince .Version.CreatedUnix}} {{$hasRepositoryAccess := false}} {{if .Repository}} {{$hasRepositoryAccess = index $.RepositoryAccessMap .Repository.ID}} diff --git a/templates/package/shared/versionlist.tmpl b/templates/package/shared/versionlist.tmpl index e5c568e059..7a1059e262 100644 --- a/templates/package/shared/versionlist.tmpl +++ b/templates/package/shared/versionlist.tmpl @@ -25,7 +25,7 @@ <div class="flex-item-main"> <a class="flex-item-title" href="{{.VersionWebLink}}">{{.Version.LowerVersion}}</a> <div class="flex-item-body"> - {{ctx.Locale.Tr "packages.published_by" (TimeSinceUnix .Version.CreatedUnix ctx.Locale) .Creator.HomeLink .Creator.GetDisplayName}} + {{ctx.Locale.Tr "packages.published_by" (DateUtils.TimeSince .Version.CreatedUnix) .Creator.HomeLink .Creator.GetDisplayName}} </div> </div> </div> diff --git a/templates/package/view.tmpl b/templates/package/view.tmpl index 59e4e53f12..170f38388d 100644 --- a/templates/package/view.tmpl +++ b/templates/package/view.tmpl @@ -8,7 +8,7 @@ <h1>{{.PackageDescriptor.Package.Name}} ({{.PackageDescriptor.Version.Version}})</h1> </div> <div> - {{$timeStr := TimeSinceUnix .PackageDescriptor.Version.CreatedUnix ctx.Locale}} + {{$timeStr := DateUtils.TimeSince .PackageDescriptor.Version.CreatedUnix}} {{if .HasRepositoryAccess}} {{ctx.Locale.Tr "packages.published_by_in" $timeStr .PackageDescriptor.Creator.HomeLink .PackageDescriptor.Creator.GetDisplayName .PackageDescriptor.Repository.Link .PackageDescriptor.Repository.FullName}} {{else}} @@ -48,7 +48,7 @@ {{if .HasRepositoryAccess}} <div class="item">{{svg "octicon-repo" 16 "tw-mr-2"}} <a href="{{.PackageDescriptor.Repository.Link}}">{{.PackageDescriptor.Repository.FullName}}</a></div> {{end}} - <div class="item">{{svg "octicon-calendar" 16 "tw-mr-2"}} {{TimeSinceUnix .PackageDescriptor.Version.CreatedUnix ctx.Locale}}</div> + <div class="item">{{svg "octicon-calendar" 16 "tw-mr-2"}} {{DateUtils.TimeSince .PackageDescriptor.Version.CreatedUnix}}</div> <div class="item">{{svg "octicon-download" 16 "tw-mr-2"}} {{.PackageDescriptor.Version.DownloadCount}}</div> {{template "package/metadata/alpine" .}} {{template "package/metadata/arch" .}} @@ -94,7 +94,7 @@ {{range .LatestVersions}} <div class="item tw-flex"> <a class="tw-flex-1 gt-ellipsis" title="{{.Version}}" href="{{$.PackageDescriptor.PackageWebLink}}/{{PathEscape .LowerVersion}}">{{.Version}}</a> - <span class="text small">{{ctx.DateUtils.AbsoluteShort .CreatedUnix}}</span> + <span class="text small">{{DateUtils.AbsoluteShort .CreatedUnix}}</span> </div> {{end}} </div> diff --git a/templates/repo/actions/runs_list.tmpl b/templates/repo/actions/runs_list.tmpl index 7bab492d7b..ef764fa357 100644 --- a/templates/repo/actions/runs_list.tmpl +++ b/templates/repo/actions/runs_list.tmpl @@ -33,7 +33,7 @@ <span class="ui label run-list-ref gt-ellipsis">{{.PrettyRef}}</span> {{end}} <div class="run-list-item-right"> - <div class="run-list-meta">{{svg "octicon-calendar" 16}}{{TimeSinceUnix .Updated ctx.Locale}}</div> + <div class="run-list-meta">{{svg "octicon-calendar" 16}}{{DateUtils.TimeSince .Updated}}</div> <div class="run-list-meta">{{svg "octicon-stopwatch" 16}}{{.Duration}}</div> </div> </div> diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index f5bffb097e..c60017ba87 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -27,7 +27,7 @@ <button class="btn interact-fg tw-px-1" data-clipboard-text="{{.DefaultBranchBranch.DBBranch.Name}}" data-tooltip-content="{{ctx.Locale.Tr "copy_branch"}}">{{svg "octicon-copy" 14}}</button> {{template "repo/commit_statuses" dict "Status" (index $.CommitStatus .DefaultBranchBranch.DBBranch.CommitID) "Statuses" (index $.CommitStatuses .DefaultBranchBranch.DBBranch.CommitID)}} </div> - <p class="info tw-flex tw-items-center tw-my-1">{{svg "octicon-git-commit" 16 "tw-mr-1"}}<a href="{{.RepoLink}}/commit/{{PathEscape .DefaultBranchBranch.DBBranch.CommitID}}">{{ShortSha .DefaultBranchBranch.DBBranch.CommitID}}</a> · <span class="commit-message">{{RenderCommitMessage $.Context .DefaultBranchBranch.DBBranch.CommitMessage (.Repository.ComposeMetas ctx)}}</span> · {{ctx.Locale.Tr "org.repo_updated" (TimeSince .DefaultBranchBranch.DBBranch.CommitTime.AsTime ctx.Locale)}} {{if .DefaultBranchBranch.DBBranch.Pusher}} {{template "shared/user/avatarlink" dict "user" .DefaultBranchBranch.DBBranch.Pusher}}{{template "shared/user/namelink" .DefaultBranchBranch.DBBranch.Pusher}}{{end}}</p> + <p class="info tw-flex tw-items-center tw-my-1">{{svg "octicon-git-commit" 16 "tw-mr-1"}}<a href="{{.RepoLink}}/commit/{{PathEscape .DefaultBranchBranch.DBBranch.CommitID}}">{{ShortSha .DefaultBranchBranch.DBBranch.CommitID}}</a> · <span class="commit-message">{{RenderCommitMessage $.Context .DefaultBranchBranch.DBBranch.CommitMessage (.Repository.ComposeMetas ctx)}}</span> · {{ctx.Locale.Tr "org.repo_updated" (DateUtils.TimeSince .DefaultBranchBranch.DBBranch.CommitTime)}}{{if .DefaultBranchBranch.DBBranch.Pusher}} {{template "shared/user/avatarlink" dict "user" .DefaultBranchBranch.DBBranch.Pusher}}{{template "shared/user/namelink" .DefaultBranchBranch.DBBranch.Pusher}}{{end}}</p> </td> <td class="right aligned middle aligned overflow-visible"> {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted)}} @@ -92,7 +92,7 @@ <span class="gt-ellipsis">{{.DBBranch.Name}}</span> <button class="btn interact-fg tw-px-1" data-clipboard-text="{{.DBBranch.Name}}" data-tooltip-content="{{ctx.Locale.Tr "copy_branch"}}">{{svg "octicon-copy" 14}}</button> </div> - <p class="info">{{ctx.Locale.Tr "repo.branch.deleted_by" .DBBranch.DeletedBy.Name}} {{TimeSinceUnix .DBBranch.DeletedUnix ctx.Locale}}</p> + <p class="info">{{ctx.Locale.Tr "repo.branch.deleted_by" .DBBranch.DeletedBy.Name}} {{DateUtils.TimeSince .DBBranch.DeletedUnix}}</p> {{else}} <div class="flex-text-block"> <a class="gt-ellipsis" href="{{$.RepoLink}}/src/branch/{{PathEscapeSegments .DBBranch.Name}}">{{.DBBranch.Name}}</a> @@ -102,7 +102,7 @@ <button class="btn interact-fg tw-px-1" data-clipboard-text="{{.DBBranch.Name}}" data-tooltip-content="{{ctx.Locale.Tr "copy_branch"}}">{{svg "octicon-copy" 14}}</button> {{template "repo/commit_statuses" dict "Status" (index $.CommitStatus .DBBranch.CommitID) "Statuses" (index $.CommitStatuses .DBBranch.CommitID)}} </div> - <p class="info tw-flex tw-items-center tw-my-1">{{svg "octicon-git-commit" 16 "tw-mr-1"}}<a href="{{$.RepoLink}}/commit/{{PathEscape .DBBranch.CommitID}}">{{ShortSha .DBBranch.CommitID}}</a> · <span class="commit-message">{{RenderCommitMessage $.Context .DBBranch.CommitMessage ($.Repository.ComposeMetas ctx)}}</span> · {{ctx.Locale.Tr "org.repo_updated" (TimeSince .DBBranch.CommitTime.AsTime ctx.Locale)}} {{if .DBBranch.Pusher}} {{template "shared/user/avatarlink" dict "user" .DBBranch.Pusher}} {{template "shared/user/namelink" .DBBranch.Pusher}}{{end}}</p> + <p class="info tw-flex tw-items-center tw-my-1">{{svg "octicon-git-commit" 16 "tw-mr-1"}}<a href="{{$.RepoLink}}/commit/{{PathEscape .DBBranch.CommitID}}">{{ShortSha .DBBranch.CommitID}}</a> · <span class="commit-message">{{RenderCommitMessage $.Context .DBBranch.CommitMessage ($.Repository.ComposeMetas ctx)}}</span> · {{ctx.Locale.Tr "org.repo_updated" (DateUtils.TimeSince .DBBranch.CommitTime)}}{{if .DBBranch.Pusher}} {{template "shared/user/avatarlink" dict "user" .DBBranch.Pusher}} {{template "shared/user/namelink" .DBBranch.Pusher}}{{end}}</p> {{end}} </td> <td class="two wide ui"> diff --git a/templates/repo/code/recently_pushed_new_branches.tmpl b/templates/repo/code/recently_pushed_new_branches.tmpl index d996acc5b2..dd663762db 100644 --- a/templates/repo/code/recently_pushed_new_branches.tmpl +++ b/templates/repo/code/recently_pushed_new_branches.tmpl @@ -1,7 +1,7 @@ {{range .RecentlyPushedNewBranches}} <div class="ui positive message tw-flex tw-items-center tw-gap-2"> <div class="tw-flex-1 tw-break-anywhere"> - {{$timeSince := TimeSince .CommitTime.AsTime ctx.Locale}} + {{$timeSince := DateUtils.TimeSince .CommitTime}} {{$repo := .GetRepo $.Context}} {{$name := .Name}} {{if ne $repo.ID $.Repository.ID}} diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl index 96ce8cf747..a25b450dbe 100644 --- a/templates/repo/commit_page.tmpl +++ b/templates/repo/commit_page.tmpl @@ -152,7 +152,7 @@ {{ctx.AvatarUtils.AvatarByEmail .Commit.Author.Email .Commit.Author.Email 28 "tw-mr-2"}} <strong>{{.Commit.Author.Name}}</strong> {{end}} - <span class="text grey tw-ml-2" id="authored-time">{{TimeSince .Commit.Author.When ctx.Locale}}</span> + <span class="text grey tw-ml-2" id="authored-time">{{DateUtils.TimeSince .Commit.Author.When}}</span> {{if or (ne .Commit.Committer.Name .Commit.Author.Name) (ne .Commit.Committer.Email .Commit.Author.Email)}} <span class="tw-ml-2">•</span> <span class="text grey tw-mx-2">{{ctx.Locale.Tr "repo.diff.committed_by"}}</span> @@ -274,7 +274,7 @@ {{else}} <strong>{{.NoteCommit.Author.Name}}</strong> {{end}} - <span class="text grey" id="note-authored-time">{{TimeSince .NoteCommit.Author.When ctx.Locale}}</span> + <span class="text grey" id="note-authored-time">{{DateUtils.TimeSince .NoteCommit.Author.When}}</span> </div> <div class="ui bottom attached info segment git-notes"> <pre class="commit-body">{{.NoteRendered | SanitizeHTML}}</pre> diff --git a/templates/repo/commits_list.tmpl b/templates/repo/commits_list.tmpl index c8c695e332..b23de20583 100644 --- a/templates/repo/commits_list.tmpl +++ b/templates/repo/commits_list.tmpl @@ -74,9 +74,9 @@ {{end}} </td> {{if .Committer}} - <td class="text right aligned">{{TimeSince .Committer.When ctx.Locale}}</td> + <td class="text right aligned">{{DateUtils.TimeSince .Committer.When}}</td> {{else}} - <td class="text right aligned">{{TimeSince .Author.When ctx.Locale}}</td> + <td class="text right aligned">{{DateUtils.TimeSince .Author.When}}</td> {{end}} <td class="text right aligned tw-py-0"> <button class="btn interact-bg tw-p-2" data-tooltip-content="{{ctx.Locale.Tr "copy_hash"}}" data-clipboard-text="{{.ID}}">{{svg "octicon-copy"}}</button> diff --git a/templates/repo/diff/comments.tmpl b/templates/repo/diff/comments.tmpl index e2597af0e3..b36f20269e 100644 --- a/templates/repo/diff/comments.tmpl +++ b/templates/repo/diff/comments.tmpl @@ -1,6 +1,6 @@ {{range .comments}} -{{$createdStr:= TimeSinceUnix .CreatedUnix ctx.Locale}} +{{$createdStr:= DateUtils.TimeSince .CreatedUnix}} <div class="comment" id="{{.HashTag}}"> {{if .OriginalAuthor}} <span class="avatar">{{ctx.AvatarUtils.Avatar nil}}</span> diff --git a/templates/repo/diff/compare.tmpl b/templates/repo/diff/compare.tmpl index 26c6b77971..612d08ec4f 100644 --- a/templates/repo/diff/compare.tmpl +++ b/templates/repo/diff/compare.tmpl @@ -212,7 +212,7 @@ {{if .Repository.ArchivedUnix.IsZero}} {{ctx.Locale.Tr "repo.archive.title"}} {{else}} - {{ctx.Locale.Tr "repo.archive.title_date" (ctx.DateUtils.AbsoluteLong .Repository.ArchivedUnix)}} + {{ctx.Locale.Tr "repo.archive.title_date" (DateUtils.AbsoluteLong .Repository.ArchivedUnix)}} {{end}} </div> {{end}} diff --git a/templates/repo/empty.tmpl b/templates/repo/empty.tmpl index d7f05223af..d3a81bc51d 100644 --- a/templates/repo/empty.tmpl +++ b/templates/repo/empty.tmpl @@ -10,7 +10,7 @@ {{if .Repository.ArchivedUnix.IsZero}} {{ctx.Locale.Tr "repo.archive.title"}} {{else}} - {{ctx.Locale.Tr "repo.archive.title_date" (ctx.DateUtils.AbsoluteLong .Repository.ArchivedUnix)}} + {{ctx.Locale.Tr "repo.archive.title_date" (DateUtils.AbsoluteLong .Repository.ArchivedUnix)}} {{end}} </div> {{end}} diff --git a/templates/repo/graph/commits.tmpl b/templates/repo/graph/commits.tmpl index 2ec4166308..f0ff0d2970 100644 --- a/templates/repo/graph/commits.tmpl +++ b/templates/repo/graph/commits.tmpl @@ -71,7 +71,7 @@ {{$userName}} {{end}} </span> - <span class="time tw-flex tw-items-center">{{ctx.DateUtils.FullTime $commit.Date}}</span> + <span class="time tw-flex tw-items-center">{{DateUtils.FullTime $commit.Date}}</span> {{end}} </li> {{end}} diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index 777453e4b1..2215c27886 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -74,7 +74,7 @@ <div class="fork-flag"> {{ctx.Locale.Tr "repo.mirror_from"}} <a target="_blank" rel="noopener noreferrer" href="{{$.PullMirror.RemoteAddress}}">{{$.PullMirror.RemoteAddress}}</a> - {{if $.PullMirror.UpdatedUnix}}{{ctx.Locale.Tr "repo.mirror_sync"}} {{TimeSinceUnix $.PullMirror.UpdatedUnix ctx.Locale}}{{end}} + {{if $.PullMirror.UpdatedUnix}}{{ctx.Locale.Tr "repo.mirror_sync"}} {{DateUtils.TimeSince $.PullMirror.UpdatedUnix}}{{end}} </div> {{end}} {{if .IsFork}}<div class="fork-flag">{{ctx.Locale.Tr "repo.forked_from"}} <a href="{{.BaseRepo.Link}}">{{.BaseRepo.FullName}}</a></div>{{end}} diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index d16e616a81..5fa31f15c2 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -53,7 +53,7 @@ {{if .Repository.ArchivedUnix.IsZero}} {{ctx.Locale.Tr "repo.archive.title"}} {{else}} - {{ctx.Locale.Tr "repo.archive.title_date" (ctx.DateUtils.AbsoluteLong .Repository.ArchivedUnix)}} + {{ctx.Locale.Tr "repo.archive.title_date" (DateUtils.AbsoluteLong .Repository.ArchivedUnix)}} {{end}} </div> {{end}} diff --git a/templates/repo/issue/card.tmpl b/templates/repo/issue/card.tmpl index 0b255d6705..c29c14a54b 100644 --- a/templates/repo/issue/card.tmpl +++ b/templates/repo/issue/card.tmpl @@ -24,7 +24,7 @@ <div class="meta"> <span class="text light grey muted-links"> {{if not $.Page.Repository}}{{.Repo.FullName}}{{end}}#{{.Index}} - {{$timeStr := TimeSinceUnix .GetLastEventTimestamp ctx.Locale}} + {{$timeStr := DateUtils.TimeSince .GetLastEventTimestamp}} {{if .OriginalAuthor}} {{ctx.Locale.Tr .GetLastEventLabelFake $timeStr .OriginalAuthor}} {{else if gt .Poster.ID 0}} diff --git a/templates/repo/issue/milestone_issues.tmpl b/templates/repo/issue/milestone_issues.tmpl index bfd64a3205..8b8b194f46 100644 --- a/templates/repo/issue/milestone_issues.tmpl +++ b/templates/repo/issue/milestone_issues.tmpl @@ -30,7 +30,7 @@ <progress class="milestone-progress-big" value="{{.Milestone.Completeness}}" max="100"></progress> <div class="tw-flex tw-gap-4"> <div class="tw-flex tw-items-center"> - {{$closedDate:= TimeSinceUnix .Milestone.ClosedDateUnix ctx.Locale}} + {{$closedDate:= DateUtils.TimeSince .Milestone.ClosedDateUnix}} {{if .IsClosed}} {{svg "octicon-clock"}} {{ctx.Locale.Tr "repo.milestones.closed" $closedDate}} {{else}} @@ -38,7 +38,7 @@ {{if .Milestone.DeadlineString}} <span{{if .IsOverdue}} class="text red"{{end}}> {{svg "octicon-calendar"}} - {{ctx.DateUtils.AbsoluteShort (.Milestone.DeadlineString|ctx.DateUtils.ParseLegacy)}} + {{DateUtils.AbsoluteShort (.Milestone.DeadlineString|DateUtils.ParseLegacy)}} </span> {{else}} {{svg "octicon-calendar"}} diff --git a/templates/repo/issue/milestones.tmpl b/templates/repo/issue/milestones.tmpl index 978f81598e..fab483c79d 100644 --- a/templates/repo/issue/milestones.tmpl +++ b/templates/repo/issue/milestones.tmpl @@ -49,19 +49,19 @@ {{if .UpdatedUnix}} <div class="flex-text-block"> {{svg "octicon-clock"}} - {{ctx.Locale.Tr "repo.milestones.update_ago" (TimeSinceUnix .UpdatedUnix ctx.Locale)}} + {{ctx.Locale.Tr "repo.milestones.update_ago" (DateUtils.TimeSince .UpdatedUnix)}} </div> {{end}} <div class="flex-text-block"> {{if .IsClosed}} - {{$closedDate:= TimeSinceUnix .ClosedDateUnix ctx.Locale}} + {{$closedDate:= DateUtils.TimeSince .ClosedDateUnix}} {{svg "octicon-clock" 14}} {{ctx.Locale.Tr "repo.milestones.closed" $closedDate}} {{else}} {{if .DeadlineString}} <span class="flex-text-inline {{if .IsOverdue}}text red{{end}}"> {{svg "octicon-calendar" 14}} - {{ctx.DateUtils.AbsoluteShort (.DeadlineString|ctx.DateUtils.ParseLegacy)}} + {{DateUtils.AbsoluteShort (.DeadlineString|DateUtils.ParseLegacy)}} </span> {{else}} {{svg "octicon-calendar" 14}} diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index 947a480df1..bd52198264 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -6,7 +6,7 @@ <input type="hidden" id="issueIndex" value="{{.Issue.Index}}"> <input type="hidden" id="type" value="{{.IssueType}}"> - {{$createdStr:= TimeSinceUnix .Issue.CreatedUnix ctx.Locale}} + {{$createdStr:= DateUtils.TimeSince .Issue.CreatedUnix}} <div class="issue-content-left comment-list prevent-before-timeline"> <div class="ui timeline"> <div id="{{.Issue.HashTag}}" class="timeline-item comment first"> diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 828191e5e1..c8eabb9345 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -1,7 +1,7 @@ {{template "base/alert"}} {{range .Issue.Comments}} {{if call $.ShouldShowCommentType .Type}} - {{$createdStr:= TimeSinceUnix .CreatedUnix ctx.Locale}} + {{$createdStr:= DateUtils.TimeSince .CreatedUnix}} <!-- 0 = COMMENT, 1 = REOPEN, 2 = CLOSE, 3 = ISSUE_REF, 4 = COMMIT_REF, 5 = COMMENT_REF, 6 = PULL_REF, 7 = COMMENT_LABEL, 8 = MILESTONE_CHANGE, @@ -137,7 +137,7 @@ {{else if eq .RefAction 2}} {{$refTr = "repo.issues.ref_reopening_from"}} {{end}} - {{$createdStr:= TimeSinceUnix .CreatedUnix ctx.Locale}} + {{$createdStr:= DateUtils.TimeSince .CreatedUnix}} <div class="timeline-item event" id="{{.HashTag}}"> <span class="badge">{{svg "octicon-bookmark"}}</span> {{template "shared/user/avatarlink" dict "user" .Poster}} @@ -300,7 +300,7 @@ {{template "shared/user/avatarlink" dict "user" .Poster}} <span class="text grey muted-links"> {{template "shared/user/authorlink" .Poster}} - {{$dueDate := ctx.DateUtils.AbsoluteLong (.Content|ctx.DateUtils.ParseLegacy)}} + {{$dueDate := DateUtils.AbsoluteLong (.Content|DateUtils.ParseLegacy)}} {{ctx.Locale.Tr "repo.issues.due_date_added" $dueDate $createdStr}} </span> </div> @@ -312,8 +312,8 @@ {{template "shared/user/authorlink" .Poster}} {{$parsedDeadline := StringUtils.Split .Content "|"}} {{if eq (len $parsedDeadline) 2}} - {{$to := ctx.DateUtils.AbsoluteLong ((index $parsedDeadline 0)|ctx.DateUtils.ParseLegacy)}} - {{$from := ctx.DateUtils.AbsoluteLong ((index $parsedDeadline 1)|ctx.DateUtils.ParseLegacy)}} + {{$to := DateUtils.AbsoluteLong ((index $parsedDeadline 0)|DateUtils.ParseLegacy)}} + {{$from := DateUtils.AbsoluteLong ((index $parsedDeadline 1)|DateUtils.ParseLegacy)}} {{ctx.Locale.Tr "repo.issues.due_date_modified" $to $from $createdStr}} {{end}} </span> @@ -324,7 +324,7 @@ {{template "shared/user/avatarlink" dict "user" .Poster}} <span class="text grey muted-links"> {{template "shared/user/authorlink" .Poster}} - {{$dueDate := ctx.DateUtils.AbsoluteLong (.Content|ctx.DateUtils.ParseLegacy)}} + {{$dueDate := DateUtils.AbsoluteLong (.Content|DateUtils.ParseLegacy)}} {{ctx.Locale.Tr "repo.issues.due_date_remove" $dueDate $createdStr}} </span> </div> diff --git a/templates/repo/issue/view_content/conversation.tmpl b/templates/repo/issue/view_content/conversation.tmpl index 4492eb1d88..1e7a5c1401 100644 --- a/templates/repo/issue/view_content/conversation.tmpl +++ b/templates/repo/issue/view_content/conversation.tmpl @@ -51,7 +51,7 @@ <div id="code-comments-{{(index .comments 0).ID}}" class="comment-code-cloud ui segment{{if $resolved}} tw-hidden{{end}}"> <div class="ui comments tw-mb-0"> {{range .comments}} - {{$createdSubStr:= TimeSinceUnix .CreatedUnix ctx.Locale}} + {{$createdSubStr:= DateUtils.TimeSince .CreatedUnix}} <div class="comment code-comment tw-pb-4" id="{{.HashTag}}"> <div class="content"> <div class="header comment-header"> diff --git a/templates/repo/issue/view_content/pull.tmpl b/templates/repo/issue/view_content/pull.tmpl index bbbb8bf720..58d85dbf1b 100644 --- a/templates/repo/issue/view_content/pull.tmpl +++ b/templates/repo/issue/view_content/pull.tmpl @@ -202,7 +202,7 @@ {{if or $prUnit.PullRequestsConfig.AllowMerge $prUnit.PullRequestsConfig.AllowRebase $prUnit.PullRequestsConfig.AllowRebaseMerge $prUnit.PullRequestsConfig.AllowSquash $prUnit.PullRequestsConfig.AllowFastForwardOnly}} {{$hasPendingPullRequestMergeTip := ""}} {{if .HasPendingPullRequestMerge}} - {{$createdPRMergeStr := TimeSinceUnix .PendingPullRequestMerge.CreatedUnix ctx.Locale}} + {{$createdPRMergeStr := DateUtils.TimeSince .PendingPullRequestMerge.CreatedUnix}} {{$hasPendingPullRequestMergeTip = ctx.Locale.Tr "repo.pulls.auto_merge_has_pending_schedule" .PendingPullRequestMerge.Doer.Name $createdPRMergeStr}} {{end}} <div class="divider"></div> diff --git a/templates/repo/issue/view_content/sidebar/due_deadline.tmpl b/templates/repo/issue/view_content/sidebar/due_deadline.tmpl index 1a87af6973..f2b00fd0b9 100644 --- a/templates/repo/issue/view_content/sidebar/due_deadline.tmpl +++ b/templates/repo/issue/view_content/sidebar/due_deadline.tmpl @@ -9,7 +9,7 @@ <div class="tw-flex tw-justify-between tw-items-center"> <div class="due-date {{if .Issue.IsOverdue}}text red{{end}}" {{if .Issue.IsOverdue}}data-tooltip-content="{{ctx.Locale.Tr "repo.issues.due_date_overdue"}}"{{end}}> {{svg "octicon-calendar" 16 "tw-mr-2"}} - {{ctx.DateUtils.AbsoluteLong .Issue.DeadlineUnix}} + {{DateUtils.AbsoluteLong .Issue.DeadlineUnix}} </div> <div> {{if and .HasIssuesOrPullsWritePermission (not .Repository.IsArchived)}} diff --git a/templates/repo/issue/view_title.tmpl b/templates/repo/issue/view_title.tmpl index 13580ebbf9..5e30cf3684 100644 --- a/templates/repo/issue/view_title.tmpl +++ b/templates/repo/issue/view_title.tmpl @@ -60,7 +60,7 @@ {{$baseHref = HTMLFormat `<a href="%s">%s</a>` .BaseBranchLink $baseHref}} {{end}} {{if .Issue.PullRequest.HasMerged}} - {{$mergedStr:= TimeSinceUnix .Issue.PullRequest.MergedUnix ctx.Locale}} + {{$mergedStr:= DateUtils.TimeSince .Issue.PullRequest.MergedUnix}} {{if .Issue.OriginalAuthor}} {{.Issue.OriginalAuthor}} <span class="pull-desc">{{ctx.Locale.TrN .NumCommits "repo.pulls.merged_title_desc_one" "repo.pulls.merged_title_desc_few" .NumCommits $headHref $baseHref $mergedStr}}</span> @@ -126,7 +126,7 @@ </span> {{end}} {{else}} - {{$createdStr:= TimeSinceUnix .Issue.CreatedUnix ctx.Locale}} + {{$createdStr:= DateUtils.TimeSince .Issue.CreatedUnix}} <span class="time-desc"> {{if .Issue.OriginalAuthor}} {{ctx.Locale.Tr "repo.issues.opened_by_fake" $createdStr .Issue.OriginalAuthor}} diff --git a/templates/repo/pulse.tmpl b/templates/repo/pulse.tmpl index a630c7c3f2..082fc8eb92 100644 --- a/templates/repo/pulse.tmpl +++ b/templates/repo/pulse.tmpl @@ -1,5 +1,5 @@ <h2 class="ui header activity-header"> - <span>{{ctx.DateUtils.AbsoluteLong .DateFrom}} - {{ctx.DateUtils.AbsoluteLong .DateUntil}}</span> + <span>{{DateUtils.AbsoluteLong .DateFrom}} - {{DateUtils.AbsoluteLong .DateUntil}}</span> <!-- Period --> <div class="ui floating dropdown jump filter"> <div class="ui basic compact button"> @@ -135,7 +135,7 @@ {{.TagName}} <a class="title" href="{{$.RepoLink}}/releases/tag/{{.TagName | PathEscapeSegments}}">{{.Title | RenderEmoji $.Context | RenderCodeBlock}}</a> {{end}} - {{TimeSinceUnix .CreatedUnix ctx.Locale}} + {{DateUtils.TimeSince .CreatedUnix}} </p> {{end}} </div> @@ -154,7 +154,7 @@ <p class="desc"> <span class="ui purple label">{{ctx.Locale.Tr "repo.activity.merged_prs_label"}}</span> #{{.Index}} <a class="title" href="{{$.RepoLink}}/pulls/{{.Index}}">{{RenderRefIssueTitle $.Context .Issue.Title}}</a> - {{TimeSinceUnix .MergedUnix ctx.Locale}} + {{DateUtils.TimeSince .MergedUnix}} </p> {{end}} </div> @@ -173,7 +173,7 @@ <p class="desc"> <span class="ui green label">{{ctx.Locale.Tr "repo.activity.opened_prs_label"}}</span> #{{.Index}} <a class="title" href="{{$.RepoLink}}/pulls/{{.Index}}">{{RenderRefIssueTitle $.Context .Issue.Title}}</a> - {{TimeSinceUnix .Issue.CreatedUnix ctx.Locale}} + {{DateUtils.TimeSince .Issue.CreatedUnix}} </p> {{end}} </div> @@ -192,7 +192,7 @@ <p class="desc"> <span class="ui red label">{{ctx.Locale.Tr "repo.activity.closed_issue_label"}}</span> #{{.Index}} <a class="title" href="{{$.RepoLink}}/issues/{{.Index}}">{{RenderRefIssueTitle $.Context .Title}}</a> - {{TimeSinceUnix .ClosedUnix ctx.Locale}} + {{DateUtils.TimeSince .ClosedUnix}} </p> {{end}} </div> @@ -211,7 +211,7 @@ <p class="desc"> <span class="ui green label">{{ctx.Locale.Tr "repo.activity.new_issue_label"}}</span> #{{.Index}} <a class="title" href="{{$.RepoLink}}/issues/{{.Index}}">{{RenderRefIssueTitle $.Context .Title}}</a> - {{TimeSinceUnix .CreatedUnix ctx.Locale}} + {{DateUtils.TimeSince .CreatedUnix}} </p> {{end}} </div> @@ -232,7 +232,7 @@ {{else}} <a class="title" href="{{$.RepoLink}}/issues/{{.Index}}">{{RenderRefIssueTitle $.Context .Title}}</a> {{end}} - {{TimeSinceUnix .UpdatedUnix ctx.Locale}} + {{DateUtils.TimeSince .UpdatedUnix}} </p> {{end}} </div> diff --git a/templates/repo/release/list.tmpl b/templates/repo/release/list.tmpl index 4c7f13dda7..a760e0730e 100644 --- a/templates/repo/release/list.tmpl +++ b/templates/repo/release/list.tmpl @@ -51,7 +51,7 @@ {{ctx.Locale.Tr "repo.released_this"}} </span> {{if $release.CreatedUnix}} - <span class="time">{{TimeSinceUnix $release.CreatedUnix ctx.Locale}}</span> + <span class="time">{{DateUtils.TimeSince $release.CreatedUnix}}</span> {{end}} {{if and (not $release.IsDraft) ($.Permission.CanRead $.UnitTypeCode)}} | <span class="ahead"><a href="{{$.RepoLink}}/compare/{{$release.TagName | PathEscapeSegments}}...{{$release.TargetBehind | PathEscapeSegments}}">{{ctx.Locale.Tr "repo.release.ahead.commits" $release.NumCommitsBehind}}</a> {{ctx.Locale.Tr "repo.release.ahead.target" $release.TargetBehind}}</span> diff --git a/templates/repo/settings/deploy_keys.tmpl b/templates/repo/settings/deploy_keys.tmpl index 9c7e1f38cd..91ef1df623 100644 --- a/templates/repo/settings/deploy_keys.tmpl +++ b/templates/repo/settings/deploy_keys.tmpl @@ -55,7 +55,7 @@ {{.Fingerprint}} </div> <div class="flex-item-body"> - <p>{{ctx.Locale.Tr "settings.added_on" (ctx.DateUtils.AbsoluteShort .CreatedUnix)}} — {{svg "octicon-info"}} {{if .HasUsed}}{{ctx.Locale.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="text green"{{end}}>{{ctx.DateUtils.AbsoluteShort .UpdatedUnix}}</span>{{else}}{{ctx.Locale.Tr "settings.no_activity"}}{{end}} - <span>{{ctx.Locale.Tr "settings.can_read_info"}}{{if not .IsReadOnly}} / {{ctx.Locale.Tr "settings.can_write_info"}} {{end}}</span></p> + <p>{{ctx.Locale.Tr "settings.added_on" (DateUtils.AbsoluteShort .CreatedUnix)}} — {{svg "octicon-info"}} {{if .HasUsed}}{{ctx.Locale.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="text green"{{end}}>{{DateUtils.AbsoluteShort .UpdatedUnix}}</span>{{else}}{{ctx.Locale.Tr "settings.no_activity"}}{{end}} - <span>{{ctx.Locale.Tr "settings.can_read_info"}}{{if not .IsReadOnly}} / {{ctx.Locale.Tr "settings.can_write_info"}} {{end}}</span></p> </div> </div> <div class="flex-item-trailing"> diff --git a/templates/repo/settings/lfs.tmpl b/templates/repo/settings/lfs.tmpl index 6d7aac229d..069fdecb33 100644 --- a/templates/repo/settings/lfs.tmpl +++ b/templates/repo/settings/lfs.tmpl @@ -17,7 +17,7 @@ </a> </td> <td>{{ctx.Locale.TrSize .Size}}</td> - <td>{{TimeSince .CreatedUnix.AsTime ctx.Locale}}</td> + <td>{{DateUtils.TimeSince .CreatedUnix}}</td> <td class="right aligned"> <a class="ui primary button" href="{{$.Link}}/find?oid={{.Oid}}&size={{.Size}}">{{ctx.Locale.Tr "repo.settings.lfs_findcommits"}}</a> <button class="ui basic show-modal icon button red" data-modal="#delete-{{.Oid}}"> diff --git a/templates/repo/settings/lfs_file_find.tmpl b/templates/repo/settings/lfs_file_find.tmpl index 809a028b2c..4c6943618e 100644 --- a/templates/repo/settings/lfs_file_find.tmpl +++ b/templates/repo/settings/lfs_file_find.tmpl @@ -32,7 +32,7 @@ {{ctx.Locale.Tr "repo.diff.commit"}} <a class="ui primary sha label" href="{{$.RepoLink}}/commit/{{.SHA}}">{{ShortSha .SHA}}</a> </td> - <td>{{TimeSince .When ctx.Locale}}</td> + <td>{{DateUtils.TimeSince .When}}</td> </tr> {{else}} <tr> diff --git a/templates/repo/settings/lfs_locks.tmpl b/templates/repo/settings/lfs_locks.tmpl index 9a18f525e9..64c6b3a550 100644 --- a/templates/repo/settings/lfs_locks.tmpl +++ b/templates/repo/settings/lfs_locks.tmpl @@ -35,7 +35,7 @@ {{$lock.Owner.DisplayName}} </a> </td> - <td>{{TimeSince .Created ctx.Locale}}</td> + <td>{{DateUtils.TimeSince .Created}}</td> <td class="right aligned"> <form action="{{$.LFSFilesLink}}/locks/{{$lock.ID}}/unlock" method="post"> {{$.CsrfTokenHtml}} diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 04c159f11d..c466541382 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -154,7 +154,7 @@ <tr> <td>{{.PullMirror.RemoteAddress}}</td> <td>{{ctx.Locale.Tr "repo.settings.mirror_settings.direction.pull"}}</td> - <td>{{ctx.DateUtils.FullTime .PullMirror.UpdatedUnix}}</td> + <td>{{DateUtils.FullTime .PullMirror.UpdatedUnix}}</td> <td class="right aligned"> <form method="post" class="tw-inline-block"> {{.CsrfTokenHtml}} @@ -243,7 +243,7 @@ <tr> <td class="tw-break-anywhere">{{.RemoteAddress}}</td> <td>{{ctx.Locale.Tr "repo.settings.mirror_settings.direction.push"}}</td> - <td>{{if .LastUpdateUnix}}{{ctx.DateUtils.FullTime .LastUpdateUnix}}{{else}}{{ctx.Locale.Tr "never"}}{{end}} {{if .LastError}}<div class="ui red label" data-tooltip-content="{{.LastError}}">{{ctx.Locale.Tr "error"}}</div>{{end}}</td> + <td>{{if .LastUpdateUnix}}{{DateUtils.FullTime .LastUpdateUnix}}{{else}}{{ctx.Locale.Tr "never"}}{{end}} {{if .LastError}}<div class="ui red label" data-tooltip-content="{{.LastError}}">{{ctx.Locale.Tr "error"}}</div>{{end}}</td> <td>{{if not (eq (len .GetPublicKey) 0)}}<a data-clipboard-text="{{.GetPublicKey}}">{{ctx.Locale.Tr "repo.settings.mirror_settings.push_mirror.copy_public_key"}}</a>{{else}}{{ctx.Locale.Tr "repo.settings.mirror_settings.push_mirror.none_ssh"}}{{end}}</td> <td class="right aligned"> <button diff --git a/templates/repo/settings/webhook/history.tmpl b/templates/repo/settings/webhook/history.tmpl index 8ee1446a16..f82aec1390 100644 --- a/templates/repo/settings/webhook/history.tmpl +++ b/templates/repo/settings/webhook/history.tmpl @@ -29,7 +29,7 @@ <a class="ui primary sha label toggle button show-panel" data-panel="#info-{{.ID}}">{{.UUID}}</a> </div> <span class="text grey"> - {{TimeSince .Delivered.AsTime ctx.Locale}} + {{DateUtils.TimeSince .Delivered}} </span> </div> <div class="info tw-hidden" id="info-{{.ID}}"> diff --git a/templates/repo/tag/list.tmpl b/templates/repo/tag/list.tmpl index 82f3dc04a9..8aa4a806c8 100644 --- a/templates/repo/tag/list.tmpl +++ b/templates/repo/tag/list.tmpl @@ -27,7 +27,7 @@ <div class="download tw-flex tw-items-center"> {{if $.Permission.CanRead $.UnitTypeCode}} {{if .CreatedUnix}} - <span class="tw-mr-2">{{svg "octicon-clock" 16 "tw-mr-1"}}{{TimeSinceUnix .CreatedUnix ctx.Locale}}</span> + <span class="tw-mr-2">{{svg "octicon-clock" 16 "tw-mr-1"}}{{DateUtils.TimeSince .CreatedUnix}}</span> {{end}} <a class="tw-mr-2 tw-font-mono muted" href="{{$.RepoLink}}/src/commit/{{.Sha1}}" rel="nofollow">{{svg "octicon-git-commit" 16 "tw-mr-1"}}{{ShortSha .Sha1}}</a> diff --git a/templates/repo/user_cards.tmpl b/templates/repo/user_cards.tmpl index abf70a9607..fbd4ef0cee 100644 --- a/templates/repo/user_cards.tmpl +++ b/templates/repo/user_cards.tmpl @@ -20,7 +20,7 @@ {{else if .Location}} {{svg "octicon-location"}} {{.Location}} {{else}} - {{svg "octicon-calendar"}} {{ctx.Locale.Tr "user.joined_on" (ctx.DateUtils.AbsoluteShort .CreatedUnix)}} + {{svg "octicon-calendar"}} {{ctx.Locale.Tr "user.joined_on" (DateUtils.AbsoluteShort .CreatedUnix)}} {{end}} </div> </div> diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index d127c2ef24..b2443e82c4 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -18,7 +18,7 @@ {{if .LatestCommit}} {{if .LatestCommit.Committer}} <div class="text grey age"> - {{TimeSince .LatestCommit.Committer.When ctx.Locale}} + {{DateUtils.TimeSince .LatestCommit.Committer.When}} </div> {{end}} {{end}} diff --git a/templates/repo/view_list.tmpl b/templates/repo/view_list.tmpl index b750e9129e..6d6af58c48 100644 --- a/templates/repo/view_list.tmpl +++ b/templates/repo/view_list.tmpl @@ -8,7 +8,7 @@ </div> </div> </th> - <th class="text grey right age">{{if .LatestCommit}}{{if .LatestCommit.Committer}}{{TimeSince .LatestCommit.Committer.When ctx.Locale}}{{end}}{{end}}</th> + <th class="text grey right age">{{if .LatestCommit}}{{if .LatestCommit.Committer}}{{DateUtils.TimeSince .LatestCommit.Committer.When}}{{end}}{{end}}</th> </tr> </thead> <tbody> @@ -62,7 +62,7 @@ {{end}} </span> </td> - <td class="text right age three wide">{{if $commit}}{{TimeSince $commit.Committer.When ctx.Locale}}{{end}}</td> + <td class="text right age three wide">{{if $commit}}{{DateUtils.TimeSince $commit.Committer.When}}{{end}}</td> </tr> {{end}} </tbody> diff --git a/templates/repo/wiki/pages.tmpl b/templates/repo/wiki/pages.tmpl index 42c36a9f46..43ab0f9a14 100644 --- a/templates/repo/wiki/pages.tmpl +++ b/templates/repo/wiki/pages.tmpl @@ -19,7 +19,7 @@ <a href="{{$.RepoLink}}/wiki/{{.SubURL}}">{{.Name}}</a> <a class="wiki-git-entry" href="{{$.RepoLink}}/wiki/{{.GitEntryName | PathEscape}}" data-tooltip-content="{{ctx.Locale.Tr "repo.wiki.original_git_entry_tooltip"}}">{{svg "octicon-chevron-right"}}</a> </td> - {{$timeSince := TimeSinceUnix .UpdatedUnix ctx.Locale}} + {{$timeSince := DateUtils.TimeSince .UpdatedUnix}} <td class="text right">{{ctx.Locale.Tr "repo.wiki.last_updated" $timeSince}}</td> </tr> {{end}} diff --git a/templates/repo/wiki/revision.tmpl b/templates/repo/wiki/revision.tmpl index 7fca703843..045cc41d81 100644 --- a/templates/repo/wiki/revision.tmpl +++ b/templates/repo/wiki/revision.tmpl @@ -9,7 +9,7 @@ <a class="file-revisions-btn ui basic button" title="{{ctx.Locale.Tr "repo.wiki.back_to_wiki"}}" href="{{.RepoLink}}/wiki/{{.PageURL}}"><span>{{.revision}}</span> {{svg "octicon-home"}}</a> {{$title}} <div class="ui sub header tw-break-anywhere"> - {{$timeSince := TimeSince .Author.When ctx.Locale}} + {{$timeSince := DateUtils.TimeSince .Author.When}} {{ctx.Locale.Tr "repo.wiki.last_commit_info" .Author.Name $timeSince}} </div> </div> diff --git a/templates/repo/wiki/view.tmpl b/templates/repo/wiki/view.tmpl index 40af307524..9f77976f35 100644 --- a/templates/repo/wiki/view.tmpl +++ b/templates/repo/wiki/view.tmpl @@ -48,7 +48,7 @@ <a class="file-revisions-btn ui basic button" title="{{ctx.Locale.Tr "repo.wiki.file_revision"}}" href="{{.RepoLink}}/wiki/{{.PageURL}}?action=_revision" ><span>{{.CommitCount}}</span> {{svg "octicon-history"}}</a> {{$title}} <div class="ui sub header"> - {{$timeSince := TimeSince .Author.When ctx.Locale}} + {{$timeSince := DateUtils.TimeSince .Author.When}} {{ctx.Locale.Tr "repo.wiki.last_commit_info" .Author.Name $timeSince}} </div> </div> diff --git a/templates/shared/actions/runner_edit.tmpl b/templates/shared/actions/runner_edit.tmpl index d60f10b71f..54250f830b 100644 --- a/templates/shared/actions/runner_edit.tmpl +++ b/templates/shared/actions/runner_edit.tmpl @@ -13,7 +13,7 @@ </div> <div class="field tw-inline-block tw-mr-4"> <label>{{ctx.Locale.Tr "actions.runners.last_online"}}</label> - <span>{{if .Runner.LastOnline}}{{TimeSinceUnix .Runner.LastOnline ctx.Locale}}{{else}}{{ctx.Locale.Tr "never"}}{{end}}</span> + <span>{{if .Runner.LastOnline}}{{DateUtils.TimeSince .Runner.LastOnline}}{{else}}{{ctx.Locale.Tr "never"}}{{end}}</span> </div> <div class="field tw-inline-block tw-mr-4"> <label>{{ctx.Locale.Tr "actions.runners.labels"}}</label> @@ -70,7 +70,7 @@ <strong><a href="{{.GetCommitLink}}" target="_blank">{{ShortSha .CommitSHA}}</a></strong> </td> <td>{{if .IsStopped}} - <span>{{TimeSinceUnix .Stopped ctx.Locale}}</span> + <span>{{DateUtils.TimeSince .Stopped}}</span> {{else}}-{{end}}</td> </tr> {{end}} diff --git a/templates/shared/actions/runner_list.tmpl b/templates/shared/actions/runner_list.tmpl index abbf2204a8..5bc61f4f64 100644 --- a/templates/shared/actions/runner_list.tmpl +++ b/templates/shared/actions/runner_list.tmpl @@ -73,7 +73,7 @@ <td class="tw-flex tw-flex-wrap tw-gap-2 runner-tags"> {{range .AgentLabels}}<span class="ui label">{{.}}</span>{{end}} </td> - <td>{{if .LastOnline}}{{TimeSinceUnix .LastOnline ctx.Locale}}{{else}}{{ctx.Locale.Tr "never"}}{{end}}</td> + <td>{{if .LastOnline}}{{DateUtils.TimeSince .LastOnline}}{{else}}{{ctx.Locale.Tr "never"}}{{end}}</td> <td class="runner-ops"> {{if .Editable $.RunnerOwnerID $.RunnerRepoID}} <a href="{{$.Link}}/{{.ID}}">{{svg "octicon-pencil"}}</a> diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index 941a444612..7ce7cd6795 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -60,7 +60,7 @@ #{{.Index}} {{end}} </a> - {{$timeStr := TimeSinceUnix .GetLastEventTimestamp ctx.Locale}} + {{$timeStr := DateUtils.TimeSince .GetLastEventTimestamp}} {{if .OriginalAuthor}} {{ctx.Locale.Tr .GetLastEventLabelFake $timeStr .OriginalAuthor}} {{else if gt .Poster.ID 0}} @@ -117,7 +117,7 @@ <span class="due-date flex-text-inline" data-tooltip-content="{{ctx.Locale.Tr "repo.issues.due_date"}}"> <span{{if .IsOverdue}} class="text red"{{end}}> {{svg "octicon-calendar" 14}} - {{ctx.DateUtils.AbsoluteShort .DeadlineUnix}} + {{DateUtils.AbsoluteShort .DeadlineUnix}} </span> </span> {{end}} diff --git a/templates/shared/searchbottom.tmpl b/templates/shared/searchbottom.tmpl index bee0397259..4e0bd9570b 100644 --- a/templates/shared/searchbottom.tmpl +++ b/templates/shared/searchbottom.tmpl @@ -7,7 +7,7 @@ </div> <div class="tw-mr-4"> {{if not .result.UpdatedUnix.IsZero}} - <span class="ui grey text">{{ctx.Locale.Tr "explore.code_last_indexed_at" (TimeSinceUnix .result.UpdatedUnix ctx.Locale)}}</span> + <span class="ui grey text">{{ctx.Locale.Tr "explore.code_last_indexed_at" (DateUtils.TimeSince .result.UpdatedUnix)}}</span> {{end}} </div> </div> diff --git a/templates/shared/secrets/add_list.tmpl b/templates/shared/secrets/add_list.tmpl index 011635a20d..59596d1013 100644 --- a/templates/shared/secrets/add_list.tmpl +++ b/templates/shared/secrets/add_list.tmpl @@ -28,7 +28,7 @@ </div> <div class="flex-item-trailing"> <span class="color-text-light-2"> - {{ctx.Locale.Tr "settings.added_on" (ctx.DateUtils.AbsoluteShort .CreatedUnix)}} + {{ctx.Locale.Tr "settings.added_on" (DateUtils.AbsoluteShort .CreatedUnix)}} </span> <button class="ui btn interact-bg link-action tw-p-2" data-url="{{$.Link}}/delete?id={{.ID}}" diff --git a/templates/shared/user/profile_big_avatar.tmpl b/templates/shared/user/profile_big_avatar.tmpl index 67227bf330..c09fed5f1e 100644 --- a/templates/shared/user/profile_big_avatar.tmpl +++ b/templates/shared/user/profile_big_avatar.tmpl @@ -73,7 +73,7 @@ </li> {{end}} {{end}} - <li>{{svg "octicon-calendar"}} <span>{{ctx.Locale.Tr "user.joined_on" (ctx.DateUtils.AbsoluteShort .ContextUser.CreatedUnix)}}</span></li> + <li>{{svg "octicon-calendar"}} <span>{{ctx.Locale.Tr "user.joined_on" (DateUtils.AbsoluteShort .ContextUser.CreatedUnix)}}</span></li> {{if and .Orgs .HasOrgsVisible}} <li> <ul class="user-orgs"> diff --git a/templates/shared/variables/variable_list.tmpl b/templates/shared/variables/variable_list.tmpl index 0223e56f4e..7a0ab48cef 100644 --- a/templates/shared/variables/variable_list.tmpl +++ b/templates/shared/variables/variable_list.tmpl @@ -30,7 +30,7 @@ </div> <div class="flex-item-trailing"> <span class="color-text-light-2"> - {{ctx.Locale.Tr "settings.added_on" (ctx.DateUtils.AbsoluteShort .CreatedUnix)}} + {{ctx.Locale.Tr "settings.added_on" (DateUtils.AbsoluteShort .CreatedUnix)}} </span> <button class="btn interact-bg tw-p-2 show-modal" data-tooltip-content="{{ctx.Locale.Tr "actions.variables.edit"}}" diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index 60aa194534..73698abc71 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -78,7 +78,7 @@ {{$reviewer := index .GetIssueInfos 1}} {{ctx.Locale.Tr "action.review_dismissed" (printf "%s/pulls/%s" (.GetRepoLink ctx) $index) $index (.ShortRepoPath ctx) $reviewer}} {{end}} - {{TimeSince .GetCreate ctx.Locale}} + {{DateUtils.TimeSince .GetCreate}} </div> {{if .GetOpType.InActions "commit_repo" "mirror_sync_push"}} {{$push := ActionContent2Commits .}} diff --git a/templates/user/dashboard/milestones.tmpl b/templates/user/dashboard/milestones.tmpl index 15c14e46d3..6b315eccd3 100644 --- a/templates/user/dashboard/milestones.tmpl +++ b/templates/user/dashboard/milestones.tmpl @@ -104,19 +104,19 @@ {{if .UpdatedUnix}} <div class="flex-text-block"> {{svg "octicon-clock"}} - {{ctx.Locale.Tr "repo.milestones.update_ago" (TimeSinceUnix .UpdatedUnix ctx.Locale)}} + {{ctx.Locale.Tr "repo.milestones.update_ago" (DateUtils.TimeSince .UpdatedUnix)}} </div> {{end}} <div class="flex-text-block"> {{if .IsClosed}} - {{$closedDate:= TimeSinceUnix .ClosedDateUnix ctx.Locale}} + {{$closedDate:= DateUtils.TimeSince .ClosedDateUnix}} {{svg "octicon-clock" 14}} {{ctx.Locale.Tr "repo.milestones.closed" $closedDate}} {{else}} {{if .DeadlineString}} <span{{if .IsOverdue}} class="text red"{{end}}> {{svg "octicon-calendar" 14}} - {{ctx.DateUtils.AbsoluteShort (.DeadlineString|ctx.DateUtils.ParseLegacy)}} + {{DateUtils.AbsoluteShort (.DeadlineString|DateUtils.ParseLegacy)}} </span> {{else}} {{svg "octicon-calendar" 14}} diff --git a/templates/user/notification/notification_div.tmpl b/templates/user/notification/notification_div.tmpl index 5c27ba8b41..bf6a94410d 100644 --- a/templates/user/notification/notification_div.tmpl +++ b/templates/user/notification/notification_div.tmpl @@ -67,9 +67,9 @@ </a> <div class="notifications-updated tw-items-center tw-mr-2"> {{if .Issue}} - {{TimeSinceUnix .Issue.UpdatedUnix ctx.Locale}} + {{DateUtils.TimeSince .Issue.UpdatedUnix}} {{else}} - {{TimeSinceUnix .UpdatedUnix ctx.Locale}} + {{DateUtils.TimeSince .UpdatedUnix}} {{end}} </div> <div class="notifications-buttons tw-items-center tw-justify-end tw-gap-1 tw-px-1"> diff --git a/templates/user/settings/applications.tmpl b/templates/user/settings/applications.tmpl index 94365f71c0..2aeabc6903 100644 --- a/templates/user/settings/applications.tmpl +++ b/templates/user/settings/applications.tmpl @@ -36,7 +36,7 @@ </ul> </details> <div class="flex-item-body"> - <p>{{ctx.Locale.Tr "settings.added_on" (ctx.DateUtils.AbsoluteShort .CreatedUnix)}} — {{svg "octicon-info"}} {{if .HasUsed}}{{ctx.Locale.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="text green"{{end}}>{{ctx.DateUtils.AbsoluteShort .UpdatedUnix}}</span>{{else}}{{ctx.Locale.Tr "settings.no_activity"}}{{end}}</p> + <p>{{ctx.Locale.Tr "settings.added_on" (DateUtils.AbsoluteShort .CreatedUnix)}} — {{svg "octicon-info"}} {{if .HasUsed}}{{ctx.Locale.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="text green"{{end}}>{{DateUtils.AbsoluteShort .UpdatedUnix}}</span>{{else}}{{ctx.Locale.Tr "settings.no_activity"}}{{end}}</p> </div> </div> <div class="flex-item-trailing"> diff --git a/templates/user/settings/grants_oauth2.tmpl b/templates/user/settings/grants_oauth2.tmpl index 41e400767d..23ab8f5696 100644 --- a/templates/user/settings/grants_oauth2.tmpl +++ b/templates/user/settings/grants_oauth2.tmpl @@ -14,7 +14,7 @@ <div class="flex-item-main"> <div class="flex-item-title">{{.Application.Name}}</div> <div class="flex-item-body"> - <p>{{ctx.Locale.Tr "settings.added_on" (ctx.DateUtils.AbsoluteShort .CreatedUnix)}}</p> + <p>{{ctx.Locale.Tr "settings.added_on" (DateUtils.AbsoluteShort .CreatedUnix)}}</p> </div> </div> <div class="flex-item-trailing"> diff --git a/templates/user/settings/keys_gpg.tmpl b/templates/user/settings/keys_gpg.tmpl index 8e08da7fb3..05a4161661 100644 --- a/templates/user/settings/keys_gpg.tmpl +++ b/templates/user/settings/keys_gpg.tmpl @@ -63,9 +63,9 @@ <b>{{ctx.Locale.Tr "settings.subkeys"}}:</b> {{range .SubsKey}} {{.PaddedKeyID}} {{end}} </div> <div class="flex-item-body"> - <p>{{ctx.Locale.Tr "settings.added_on" (ctx.DateUtils.AbsoluteShort .AddedUnix)}}</p> + <p>{{ctx.Locale.Tr "settings.added_on" (DateUtils.AbsoluteShort .AddedUnix)}}</p> - - <p>{{if not .ExpiredUnix.IsZero}}{{ctx.Locale.Tr "settings.valid_until_date" (ctx.DateUtils.AbsoluteShort .ExpiredUnix)}}{{else}}{{ctx.Locale.Tr "settings.valid_forever"}}{{end}}</p> + <p>{{if not .ExpiredUnix.IsZero}}{{ctx.Locale.Tr "settings.valid_until_date" (DateUtils.AbsoluteShort .ExpiredUnix)}}{{else}}{{ctx.Locale.Tr "settings.valid_forever"}}{{end}}</p> </div> </div> <div class="flex-item-trailing"> diff --git a/templates/user/settings/keys_principal.tmpl b/templates/user/settings/keys_principal.tmpl index 0bb943054f..754bc374c2 100644 --- a/templates/user/settings/keys_principal.tmpl +++ b/templates/user/settings/keys_principal.tmpl @@ -22,7 +22,7 @@ <div class="flex-item-main"> <div class="flex-item-title">{{.Name}}</div> <div class="flex-item-body"> - <p>{{ctx.Locale.Tr "settings.added_on" (ctx.DateUtils.AbsoluteShort .CreatedUnix)}} — {{svg "octicon-info" 16}} {{if .HasUsed}}{{ctx.Locale.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="green"{{end}}>{{ctx.DateUtils.AbsoluteShort .UpdatedUnix}}</span>{{else}}{{ctx.Locale.Tr "settings.no_activity"}}{{end}}</p> + <p>{{ctx.Locale.Tr "settings.added_on" (DateUtils.AbsoluteShort .CreatedUnix)}} — {{svg "octicon-info" 16}} {{if .HasUsed}}{{ctx.Locale.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="green"{{end}}>{{DateUtils.AbsoluteShort .UpdatedUnix}}</span>{{else}}{{ctx.Locale.Tr "settings.no_activity"}}{{end}}</p> </div> </div> <div class="flex-item-trailing"> diff --git a/templates/user/settings/keys_ssh.tmpl b/templates/user/settings/keys_ssh.tmpl index 5ba58d2234..9cedc498fe 100644 --- a/templates/user/settings/keys_ssh.tmpl +++ b/templates/user/settings/keys_ssh.tmpl @@ -53,7 +53,7 @@ {{.Fingerprint}} </div> <div class="flex-item-body"> - <p>{{ctx.Locale.Tr "settings.added_on" (ctx.DateUtils.AbsoluteShort .CreatedUnix)}} — {{svg "octicon-info"}} {{if .HasUsed}}{{ctx.Locale.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="text green"{{end}}>{{ctx.DateUtils.AbsoluteShort .UpdatedUnix}}</span>{{else}}{{ctx.Locale.Tr "settings.no_activity"}}{{end}}</p> + <p>{{ctx.Locale.Tr "settings.added_on" (DateUtils.AbsoluteShort .CreatedUnix)}} — {{svg "octicon-info"}} {{if .HasUsed}}{{ctx.Locale.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="text green"{{end}}>{{DateUtils.AbsoluteShort .UpdatedUnix}}</span>{{else}}{{ctx.Locale.Tr "settings.no_activity"}}{{end}}</p> </div> </div> <div class="flex-item-trailing"> diff --git a/templates/user/settings/security/webauthn.tmpl b/templates/user/settings/security/webauthn.tmpl index 19ac8b28a6..b04bcf4291 100644 --- a/templates/user/settings/security/webauthn.tmpl +++ b/templates/user/settings/security/webauthn.tmpl @@ -12,7 +12,7 @@ <div class="flex-item-main"> <div class="flex-item-title">{{.Name}}</div> <div class="flex-item-body"> - <p>{{ctx.Locale.Tr "settings.added_on" (ctx.DateUtils.AbsoluteShort .CreatedUnix)}}</p> + <p>{{ctx.Locale.Tr "settings.added_on" (DateUtils.AbsoluteShort .CreatedUnix)}}</p> </div> </div> <div class="flex-item-trailing"> diff --git a/tests/integration/last_updated_time_test.go b/tests/integration/last_updated_time_test.go index aefcec5cc7..34ba9a471f 100644 --- a/tests/integration/last_updated_time_test.go +++ b/tests/integration/last_updated_time_test.go @@ -20,7 +20,7 @@ func TestRepoLastUpdatedTime(t *testing.T) { req := NewRequest(t, "GET", "/explore/repos?q=repo1") resp := session.MakeRequest(t, req, http.StatusOK) doc := NewHTMLParser(t, resp.Body) - node := doc.doc.Find(".flex-item-body").First() + node := doc.doc.Find(".flex-item-main:has(a[href='/user2/repo1']) .flex-item-body").First() { buf := "" findTextNonNested(t, node, &buf) @@ -28,10 +28,7 @@ func TestRepoLastUpdatedTime(t *testing.T) { } // Relative time should be present as a descendent - { - relativeTime := node.Find("relative-time").Text() - assert.True(t, strings.HasPrefix(relativeTime, "19")) // ~1970, might underflow with timezone - } + assert.Contains(t, node.Find("relative-time").Text(), "2024-11-10") } func TestBranchLastUpdatedTime(t *testing.T) {