diff options
author | Yarden Shoham <git@yardenshoham.com> | 2023-04-23 22:12:33 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-23 15:12:33 -0400 |
commit | 70bb4984cdad9a15d676708bd345b590aa42d72a (patch) | |
tree | dda9461e4928839fa08641d68cf1c5bb29252b3d | |
parent | cbe2e99aed5e479b0fae38726e16baefacb1a7f1 (diff) | |
download | gitea-70bb4984cdad9a15d676708bd345b590aa42d72a.tar.gz gitea-70bb4984cdad9a15d676708bd345b590aa42d72a.zip |
Allow using localized absolute date times within phrases with place holders and localize issue due date events (#24275)
This refactors the `shared/datetime/short|long|full` templates into a
template helper function, which allows us to render absolute date times
within translatable phrases.
- Follows #23988
- The first attempt was in #24055
- This should help #22664
Changes:
1. Added the `DateTime` template helper that replaces the
`shared/datetime/short|long|full` templates
2. Used find-and-replace with varying regexes to replace the templates
from step 1 (for example, `\{\{template "shared/datetime/(\S+) \(dict
"Datetime" ([^"]+) "Fallback" ([^\)]+\)?) ?\)?\}\}` -> `{{DateTime "$1
$2 $3}}`)
3. Used the new `DateTime` helper in the issue due date timestamp
rendering
# Before
![image](https://user-images.githubusercontent.com/20454870/233791256-b454c455-aca0-4b76-b300-7866c7bd529e.png)
# After
![image](https://user-images.githubusercontent.com/20454870/233790809-c4913355-2822-4657-bb29-2298deb6d4b3.png)
---------
Signed-off-by: Yarden Shoham <git@yardenshoham.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
33 files changed, 64 insertions, 39 deletions
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(`<relative-time format="datetime" year="numeric" month="short" day="numeric" weekday="" datetime="%s">%s</relative-time>`, datetimeEscaped, fallbackEscaped)) + case "long": + return template.HTML(fmt.Sprintf(`<relative-time format="datetime" year="numeric" month="long" day="numeric" weekday="" datetime="%s">%s</relative-time>`, datetimeEscaped, fallbackEscaped)) + case "full": + return template.HTML(fmt.Sprintf(`<relative-time format="datetime" weekday="" year="numeric" month="short" day="numeric" hour="numeric" minute="numeric" second="numeric" datetime="%s">%s</relative-time>`, 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 @@ <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>{{template "shared/datetime/short" (dict "Datetime" .UpdatedUnix.FormatLong "Fallback" .UpdatedUnix.FormatShort)}}</td> - <td>{{template "shared/datetime/short" (dict "Datetime" .CreatedUnix.FormatLong "Fallback" .CreatedUnix.FormatShort)}}</td> + <td>{{DateTime "short" .UpdatedUnix.FormatLong .UpdatedUnix.FormatShort}}</td> + <td>{{DateTime "short" .CreatedUnix.FormatLong .CreatedUnix.FormatShort}}</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 51685112ba..5dd6314944 100644 --- a/templates/admin/cron.tmpl +++ b/templates/admin/cron.tmpl @@ -21,8 +21,8 @@ <td><button type="submit" class="ui green button" name="op" value="{{.Name}}" title="{{$.locale.Tr "admin.dashboard.operation_run"}}">{{svg "octicon-triangle-right"}}</button></td> <td>{{$.locale.Tr (printf "admin.dashboard.%s" .Name)}}</td> <td>{{.Spec}}</td> - <td>{{template "shared/datetime/full" (dict "Datetime" (DateFmtLong .Next) "Fallback" (DateFmtLong .Next) )}}</td> - <td>{{if gt .Prev.Year 1}}{{template "shared/datetime/full" (dict "Datetime" (DateFmtLong .Prev) "Fallback" (DateFmtLong .Prev) )}}{{else}}N/A{{end}}</td> + <td>{{DateTime "full" (DateFmtLong .Next) (DateFmtLong .Next)}}</td> + <td>{{if gt .Prev.Year 1}}{{DateTime "full" (DateFmtLong .Prev) (DateFmtLong .Prev)}}{{else}}N/A{{end}}</td> <td>{{.ExecTimes}}</td> <td {{if ne .Status ""}}data-tooltip-content="{{.FormatLastMessage $.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 82acb14247..51b0c6850a 100644 --- a/templates/admin/notice.tmpl +++ b/templates/admin/notice.tmpl @@ -26,7 +26,7 @@ <td>{{.ID}}</td> <td>{{$.locale.Tr .TrStr}}</td> <td class="view-detail"><span class="notice-description text truncate">{{.Description}}</span></td> - <td>{{template "shared/datetime/short" (dict "Datetime" .CreatedUnix.FormatLong "Fallback" .CreatedUnix.FormatShort)}}</td> + <td>{{DateTime "short" .CreatedUnix.FormatLong .CreatedUnix.FormatShort}}</td> <td><a href="#">{{svg "octicon-note" 16 "view-detail"}}</a></td> </tr> {{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 @@ <td>{{.NumTeams}}</td> <td>{{.NumMembers}}</td> <td>{{.NumRepos}}</td> - <td>{{template "shared/datetime/short" (dict "Datetime" .CreatedUnix.FormatLong "Fallback" .CreatedUnix.FormatShort)}}</td> + <td>{{DateTime "short" .CreatedUnix.FormatLong .CreatedUnix.FormatShort}}</td> <td><a href="{{.OrganisationLink}}/settings">{{svg "octicon-pencil"}}</a></td> </tr> {{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}} </td> <td>{{FileSize .CalculateBlobSize}}</td> - <td>{{template "shared/datetime/short" (dict "Datetime" .Version.CreatedUnix.FormatLong "Fallback" .Version.CreatedUnix.FormatShort)}}</td> + <td>{{DateTime "short" .Version.CreatedUnix.FormatLong .Version.CreatedUnix.FormatShort}}</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/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}} <tr> <td>{{.Workers}}{{if .IsFlusher}}<span title="{{$.locale.Tr "admin.monitor.queue.flush"}}">{{svg "octicon-sync"}}</span>{{end}}</td> - <td>{{template "shared/datetime/full" (dict "Datetime" (DateFmtLong .Start) "Fallback" (DateFmtLong .Start) )}}</td> - <td>{{if .HasTimeout}}{{template "shared/datetime/full" (dict "Datetime" (DateFmtLong .Timeout) "Fallback" (DateFmtLong .Timeout) )}}{{else}}-{{end}}</td> + <td>{{DateTime "full" (DateFmtLong .Start) (DateFmtLong .Start)}}</td> + <td>{{if .HasTimeout}}{{DateTime "full" (DateFmtLong .Timeout) (DateFmtLong .Timeout)}}{{else}}-{{end}}</td> <td> <a class="delete-button" href="" data-url="{{$.Link}}/cancel/{{.PID}}" data-id="{{.PID}}" data-name="{{.Workers}}" title="{{$.locale.Tr "remove"}}">{{svg "octicon-trash"}}</a> </td> 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 @@ <td>{{.NumForks}}</td> <td>{{.NumIssues}}</td> <td>{{FileSize .Size}}</td> - <td>{{template "shared/datetime/short" (dict "Datetime" .CreatedUnix.FormatLong "Fallback" .CreatedUnix.FormatShort)}}</td> + <td>{{DateTime "short" .CreatedUnix.FormatLong .CreatedUnix.FormatShort}}</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/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 @@ <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>{{.NumRepos}}</td> - <td>{{template "shared/datetime/short" (dict "Datetime" .CreatedUnix.FormatLong "Fallback" .CreatedUnix.FormatShort)}}</td> + <td>{{DateTime "short" .CreatedUnix.FormatLong .CreatedUnix.FormatShort}}</td> {{if .LastLoginUnix}} - <td>{{template "shared/datetime/short" (dict "Datetime" .LastLoginUnix.FormatLong "Fallback" .LastLoginUnix.FormatShort)}}</td> + <td>{{DateTime "short" .LastLoginUnix.FormatLong .LastLoginUnix.FormatShort}}</td> {{else}} <td><span>{{$.locale.Tr "admin.users.never_login"}}</span></td> {{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"}} <a href="{{.Website}}" rel="nofollow">{{.Website}}</a> {{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}} </div> </div> </div> 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"}} <a href="mailto:{{.Email}}" rel="nofollow">{{.Email}}</a> {{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}} </div> </div> </div> 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 @@ <td><a href="{{.FullWebLink}}">{{.Version.Version}}</a></td> <td><a href="{{.Creator.HomeLink}}">{{.Creator.Name}}</a></td> <td>{{FileSize .CalculateBlobSize}}</td> - <td>{{template "shared/datetime/short" (dict "Datetime" .Version.CreatedUnix.FormatLong "Fallback" .Version.CreatedUnix.FormatShort)}}</td> + <td>{{DateTime "short" .Version.CreatedUnix.FormatLong .Version.CreatedUnix.FormatShort}}</td> </tr> {{else}} <tr> 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}} <div class="item gt-df"> <a class="gt-f1" href="{{$.PackageDescriptor.PackageWebLink}}/{{PathEscape .LowerVersion}}">{{.Version}}</a> - <span class="text small">{{template "shared/datetime/short" (dict "Datetime" (.CreatedUnix.FormatDate) "Fallback" (.CreatedUnix.FormatDate))}}</span> + <span class="text small">{{DateTime "short" (.CreatedUnix.FormatDate) (.CreatedUnix.FormatDate)}}</span> </div> {{end}} </div> 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 @@ <div role="main" aria-label="{{.Title}}" class="page-content repository commits"> {{template "repo/header" .}} <div class="ui container"> - <h2 class="ui header">{{template "shared/datetime/long" (dict "Datetime" .DateFrom "Fallback" .DateFrom)}} - {{template "shared/datetime/long" (dict "Datetime" .DateUntil "Fallback" .DateUntil)}} + <h2 class="ui header">{{DateTime "long" .DateFrom .DateFrom}} - {{DateTime "long" .DateUntil .DateUntil}} <div class="ui right"> <!-- Period --> <div class="ui floating dropdown jump filter"> diff --git a/templates/repo/issue/milestone_issues.tmpl b/templates/repo/issue/milestone_issues.tmpl index 137f2c2d9d..ccbc40586a 100644 --- a/templates/repo/issue/milestone_issues.tmpl +++ b/templates/repo/issue/milestone_issues.tmpl @@ -35,7 +35,7 @@ {{else}} {{svg "octicon-calendar"}} {{if .Milestone.DeadlineString}} - <span {{if .IsOverdue}}class="overdue"{{end}}>{{template "shared/datetime/short" (dict "Datetime" .Milestone.DeadlineString "Fallback" .Milestone.DeadlineString)}}</span> + <span {{if .IsOverdue}}class="overdue"{{end}}>{{DateTime "short" .Milestone.DeadlineString .Milestone.DeadlineString}}</span> {{else}} {{$.locale.Tr "repo.milestones.no_due_date"}} {{end}} diff --git a/templates/repo/issue/milestones.tmpl b/templates/repo/issue/milestones.tmpl index c07232c759..7abb1a6606 100644 --- a/templates/repo/issue/milestones.tmpl +++ b/templates/repo/issue/milestones.tmpl @@ -77,7 +77,7 @@ {{else}} {{svg "octicon-calendar"}} {{if .DeadlineString}} - <span {{if .IsOverdue}}class="overdue"{{end}}>{{template "shared/datetime/short" (dict "Datetime" .DeadlineString "Fallback" .DeadlineString)}}</span> + <span {{if .IsOverdue}}class="overdue"{{end}}>{{DateTime "short" .DeadlineString .DeadlineString}}</span> {{else}} {{$.locale.Tr "repo.milestones.no_due_date"}} {{end}} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 45077e91ba..142c8153f0 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -295,7 +295,7 @@ {{template "shared/user/avatarlink" dict "Context" $.Context "user" .Poster}} <span class="text grey muted-links"> {{template "shared/user/authorlink" .Poster}} - {{$.locale.Tr "repo.issues.due_date_added" .Content $createdStr | Safe}} + {{$.locale.Tr "repo.issues.due_date_added" (DateTime "long" .Content .Content) $createdStr | Safe}} </span> </div> {{else if eq .Type 17}} @@ -305,7 +305,9 @@ <span class="text grey muted-links"> {{template "shared/user/authorlink" .Poster}} {{$parsedDeadline := .Content | ParseDeadline}} - {{$.locale.Tr "repo.issues.due_date_modified" (index $parsedDeadline 0) (index $parsedDeadline 1) $createdStr | Safe}} + {{$from := DateTime "long" (index $parsedDeadline 1) (index $parsedDeadline 1)}} + {{$to := DateTime "long" (index $parsedDeadline 0) (index $parsedDeadline 0)}} + {{$.locale.Tr "repo.issues.due_date_modified" $to $from $createdStr | Safe}} </span> </div> {{else if eq .Type 18}} @@ -314,7 +316,7 @@ {{template "shared/user/avatarlink" dict "Context" $.Context "user" .Poster}} <span class="text grey muted-links"> {{template "shared/user/authorlink" .Poster}} - {{$.locale.Tr "repo.issues.due_date_remove" .Content $createdStr | Safe}} + {{$.locale.Tr "repo.issues.due_date_remove" (DateTime "long" .Content .Content) $createdStr | Safe}} </span> </div> {{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 @@ <div class="gt-df gt-sb gt-ac"> <div class="due-date {{if .Issue.IsOverdue}}text red{{end}}" {{if .Issue.IsOverdue}}data-tooltip-content="{{.locale.Tr "repo.issues.due_date_overdue"}}"{{end}}> {{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}} </div> <div> {{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}} </div> <div class="activity meta"> - <i>{{$.locale.Tr "settings.add_on"}} <span>{{template "shared/datetime/short" (dict "Datetime" .CreatedUnix.FormatLong "Fallback" .CreatedUnix.FormatShort)}}</span> — {{svg "octicon-info"}} {{if .HasUsed}}{{$.locale.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="green"{{end}}>{{template "shared/datetime/short" (dict "Datetime" .UpdatedUnix.FormatLong "Fallback" .UpdatedUnix.FormatShort)}}</span>{{else}}{{$.locale.Tr "settings.no_activity"}}{{end}} - <span>{{$.locale.Tr "settings.can_read_info"}}{{if not .IsReadOnly}} / {{$.locale.Tr "settings.can_write_info"}} {{end}}</span></i> + <i>{{$.locale.Tr "settings.add_on"}} <span>{{DateTime "short" .CreatedUnix.FormatLong .CreatedUnix.FormatShort}}</span> — {{svg "octicon-info"}} {{if .HasUsed}}{{$.locale.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="green"{{end}}>{{DateTime "short" .UpdatedUnix.FormatLong .UpdatedUnix.FormatShort}}</span>{{else}}{{$.locale.Tr "settings.no_activity"}}{{end}} - <span>{{$.locale.Tr "settings.can_read_info"}}{{if not .IsReadOnly}} / {{$.locale.Tr "settings.can_write_info"}} {{end}}</span></i> </div> </div> </div> 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 @@ <tr> <td>{{(MirrorRemoteAddress $.Context .Repository .Mirror.GetRemoteName false).Address}}</td> <td>{{$.locale.Tr "repo.settings.mirror_settings.direction.pull"}}</td> - <td>{{template "shared/datetime/full" (dict "Datetime" .Mirror.UpdatedUnix.FormatLong "Fallback" .Mirror.UpdatedUnix.AsTime)}}</td> + <td>{{DateTime "full" .Mirror.UpdatedUnix.FormatLong .Mirror.UpdatedUnix.AsTime}}</td> <td class="right aligned"> <form method="post" style="display: inline-block"> {{.CsrfTokenHtml}} @@ -167,7 +167,7 @@ {{$address := MirrorRemoteAddress $.Context $.Repository .GetRemoteName true}} <td>{{$address.Address}}</td> <td>{{$.locale.Tr "repo.settings.mirror_settings.direction.push"}}</td> - <td>{{if .LastUpdateUnix}}{{template "shared/datetime/full" (dict "Datetime" .LastUpdateUnix.FormatLong "Fallback" .LastUpdateUnix.AsTime)}}{{else}}{{$.locale.Tr "never"}}{{end}} {{if .LastError}}<div class="ui red label" data-tooltip-content="{{.LastError}}">{{$.locale.Tr "error"}}</div>{{end}}</td> + <td>{{if .LastUpdateUnix}}{{DateTime "full" .LastUpdateUnix.FormatLong .LastUpdateUnix.AsTime}}{{else}}{{$.locale.Tr "never"}}{{end}} {{if .LastError}}<div class="ui red label" data-tooltip-content="{{.LastError}}">{{$.locale.Tr "error"}}</div>{{end}}</td> <td class="right aligned"> <form method="post" style="display: inline-block"> {{$.CsrfTokenHtml}} diff --git a/templates/repo/user_cards.tmpl b/templates/repo/user_cards.tmpl index a48fd41744..5acea0b4d9 100644 --- a/templates/repo/user_cards.tmpl +++ b/templates/repo/user_cards.tmpl @@ -18,7 +18,7 @@ {{else if .Location}} {{svg "octicon-location"}} {{.Location}} {{else}} - {{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}} {{end}} </div> </li> diff --git a/templates/shared/datetime/full.tmpl b/templates/shared/datetime/full.tmpl deleted file mode 100644 index 1c55a4b53e..0000000000 --- a/templates/shared/datetime/full.tmpl +++ /dev/null @@ -1 +0,0 @@ -<relative-time format="datetime" weekday="" year="numeric" month="short" day="numeric" hour="numeric" minute="numeric" second="numeric" datetime="{{.Datetime}}">{{.Fallback}}</relative-time> diff --git a/templates/shared/datetime/long.tmpl b/templates/shared/datetime/long.tmpl deleted file mode 100644 index 4880cf3f91..0000000000 --- a/templates/shared/datetime/long.tmpl +++ /dev/null @@ -1 +0,0 @@ -<relative-time format="datetime" year="numeric" month="long" day="numeric" weekday="" datetime="{{.Datetime}}">{{.Fallback}}</relative-time> diff --git a/templates/shared/datetime/short.tmpl b/templates/shared/datetime/short.tmpl deleted file mode 100644 index e5bcef6459..0000000000 --- a/templates/shared/datetime/short.tmpl +++ /dev/null @@ -1 +0,0 @@ -<relative-time format="datetime" year="numeric" month="short" day="numeric" weekday="" datetime="{{.Datetime}}">{{.Fallback}}</relative-time> diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index 198e76f37c..d3d9729fe4 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -106,7 +106,7 @@ <span class="due-date" data-tooltip-content="{{$.locale.Tr "repo.issues.due_date"}}"> <span{{if .IsOverdue}} class="overdue"{{end}}> {{svg "octicon-calendar" 14 "gt-mr-2"}} - {{template "shared/datetime/short" (dict "Datetime" .DeadlineUnix.FormatDate "Fallback" .DeadlineUnix.FormatShort)}} + {{DateTime "short" .DeadlineUnix.FormatDate .DeadlineUnix.FormatShort}} </span> </span> {{end}} diff --git a/templates/user/dashboard/milestones.tmpl b/templates/user/dashboard/milestones.tmpl index 09519ce005..468bde0b78 100644 --- a/templates/user/dashboard/milestones.tmpl +++ b/templates/user/dashboard/milestones.tmpl @@ -97,7 +97,7 @@ {{else}} {{svg "octicon-calendar"}} {{if .DeadlineString}} - <span {{if .IsOverdue}}class="overdue"{{end}}>{{template "shared/datetime/short" (dict "Datetime" .DeadlineString "Fallback" .DeadlineString)}}</span> + <span {{if .IsOverdue}}class="overdue"{{end}}>{{DateTime "short" .DeadlineString .DeadlineString}}</span> {{else}} {{$.locale.Tr "repo.milestones.no_due_date"}} {{end}} diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 376dfacacf..2ad92612a2 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -73,7 +73,7 @@ </li> {{end}} {{end}} - <li>{{svg "octicon-clock"}} {{.locale.Tr "user.join_on"}} {{template "shared/datetime/short" (dict "Datetime" .ContextUser.CreatedUnix.FormatLong "Fallback" .ContextUser.CreatedUnix.FormatShort)}}</li> + <li>{{svg "octicon-clock"}} {{.locale.Tr "user.join_on"}} {{DateTime "short" .ContextUser.CreatedUnix.FormatLong .ContextUser.CreatedUnix.FormatShort}}</li> {{if and .Orgs .HasOrgsVisible}} <li> <ul class="user-orgs"> diff --git a/templates/user/settings/applications.tmpl b/templates/user/settings/applications.tmpl index c8789bbe82..fb1154d0c8 100644 --- a/templates/user/settings/applications.tmpl +++ b/templates/user/settings/applications.tmpl @@ -27,7 +27,7 @@ </ul> </details> <div class="activity meta"> - <i>{{$.locale.Tr "settings.add_on"}} <span>{{template "shared/datetime/short" (dict "Datetime" .CreatedUnix.FormatLong "Fallback" .CreatedUnix.FormatShort)}}</span> — {{svg "octicon-info"}} {{if .HasUsed}}{{$.locale.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="green"{{end}}>{{template "shared/datetime/short" (dict "Datetime" .UpdatedUnix.FormatLong "Fallback" .UpdatedUnix.FormatShort)}}</span>{{else}}{{$.locale.Tr "settings.no_activity"}}{{end}}</i> + <i>{{$.locale.Tr "settings.add_on"}} <span>{{DateTime "short" .CreatedUnix.FormatLong .CreatedUnix.FormatShort}}</span> — {{svg "octicon-info"}} {{if .HasUsed}}{{$.locale.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="green"{{end}}>{{DateTime "short" .UpdatedUnix.FormatLong .UpdatedUnix.FormatShort}}</span>{{else}}{{$.locale.Tr "settings.no_activity"}}{{end}}</i> </div> </div> </div> diff --git a/templates/user/settings/grants_oauth2.tmpl b/templates/user/settings/grants_oauth2.tmpl index 205b374176..3fe34a8727 100644 --- a/templates/user/settings/grants_oauth2.tmpl +++ b/templates/user/settings/grants_oauth2.tmpl @@ -20,7 +20,7 @@ <div class="content"> <strong>{{$grant.Application.Name}}</strong> <div class="activity meta"> - <i>{{$.locale.Tr "settings.add_on"}} <span>{{template "shared/datetime/short" (dict "Datetime" $grant.CreatedUnix.FormatLong "Fallback" $grant.CreatedUnix.FormatShort)}}</span></i> + <i>{{$.locale.Tr "settings.add_on"}} <span>{{DateTime "short" $grant.CreatedUnix.FormatLong $grant.CreatedUnix.FormatShort}}</span></i> </div> </div> </div> diff --git a/templates/user/settings/keys_gpg.tmpl b/templates/user/settings/keys_gpg.tmpl index 46b60aafd8..a488555404 100644 --- a/templates/user/settings/keys_gpg.tmpl +++ b/templates/user/settings/keys_gpg.tmpl @@ -68,9 +68,9 @@ <b>{{$.locale.Tr "settings.subkeys"}}:</b> {{range .SubsKey}} {{.PaddedKeyID}} {{end}} </div> <div class="activity meta"> - <i>{{$.locale.Tr "settings.add_on"}} <span>{{template "shared/datetime/short" (dict "Datetime" .AddedUnix.FormatLong "Fallback" .AddedUnix.FormatShort)}}</span></i> + <i>{{$.locale.Tr "settings.add_on"}} <span>{{DateTime "short" .AddedUnix.FormatLong .AddedUnix.FormatShort}}</span></i> - - <i>{{if not .ExpiredUnix.IsZero}}{{$.locale.Tr "settings.valid_until"}} <span>{{template "shared/datetime/short" (dict "Datetime" .ExpiredUnix.FormatLong "Fallback" .ExpiredUnix.FormatShort)}}</span>{{else}}{{$.locale.Tr "settings.valid_forever"}}{{end}}</i> + <i>{{if not .ExpiredUnix.IsZero}}{{$.locale.Tr "settings.valid_until"}} <span>{{DateTime "short" .ExpiredUnix.FormatLong .ExpiredUnix.FormatShort}}</span>{{else}}{{$.locale.Tr "settings.valid_forever"}}{{end}}</i> </div> </div> </div> diff --git a/templates/user/settings/keys_principal.tmpl b/templates/user/settings/keys_principal.tmpl index 5251e465fd..51009fdea1 100644 --- a/templates/user/settings/keys_principal.tmpl +++ b/templates/user/settings/keys_principal.tmpl @@ -25,7 +25,7 @@ <div class="content"> <strong>{{.Name}}</strong> <div class="activity meta"> - <i>{{$.locale.Tr "settings.add_on"}} <span>{{template "shared/datetime/short" (dict "Datetime" .CreatedUnix.FormatLong "Fallback" .CreatedUnix.FormatShort)}}</span> — {{svg "octicon-info" 16}} {{if .HasUsed}}{{$.locale.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="green"{{end}}>{{template "shared/datetime/short" (dict "Datetime" .UpdatedUnix.FormatLong "Fallback" .UpdatedUnix.FormatShort)}}</span>{{else}}{{$.locale.Tr "settings.no_activity"}}{{end}}</i> + <i>{{$.locale.Tr "settings.add_on"}} <span>{{DateTime "short" .CreatedUnix.FormatLong .CreatedUnix.FormatShort}}</span> — {{svg "octicon-info" 16}} {{if .HasUsed}}{{$.locale.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="green"{{end}}>{{DateTime "short" .UpdatedUnix.FormatLong .UpdatedUnix.FormatShort}}</span>{{else}}{{$.locale.Tr "settings.no_activity"}}{{end}}</i> </div> </div> </div> diff --git a/templates/user/settings/keys_ssh.tmpl b/templates/user/settings/keys_ssh.tmpl index d66b4ea528..abe0624d96 100644 --- a/templates/user/settings/keys_ssh.tmpl +++ b/templates/user/settings/keys_ssh.tmpl @@ -59,7 +59,7 @@ {{.Fingerprint}} </div> <div class="activity meta"> - <i>{{$.locale.Tr "settings.add_on"}} <span>{{template "shared/datetime/short" (dict "Datetime" .CreatedUnix.FormatLong "Fallback" .CreatedUnix.FormatShort)}}</span> — {{svg "octicon-info"}} {{if .HasUsed}}{{$.locale.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="green"{{end}}>{{template "shared/datetime/short" (dict "Datetime" .UpdatedUnix.FormatLong "Fallback" .UpdatedUnix.FormatShort)}}</span>{{else}}{{$.locale.Tr "settings.no_activity"}}{{end}}</i> + <i>{{$.locale.Tr "settings.add_on"}} <span>{{DateTime "short" .CreatedUnix.FormatLong .CreatedUnix.FormatShort}}</span> — {{svg "octicon-info"}} {{if .HasUsed}}{{$.locale.Tr "settings.last_used"}} <span {{if .HasRecentActivity}}class="green"{{end}}>{{DateTime "short" .UpdatedUnix.FormatLong .UpdatedUnix.FormatShort}}</span>{{else}}{{$.locale.Tr "settings.no_activity"}}{{end}}</i> </div> </div> </div> |