]> source.dussan.org Git - gitea.git/commitdiff
Allow using localized absolute date times within phrases with place holders and local...
authorYarden Shoham <git@yardenshoham.com>
Sun, 23 Apr 2023 19:12:33 +0000 (22:12 +0300)
committerGitHub <noreply@github.com>
Sun, 23 Apr 2023 19:12:33 +0000 (15:12 -0400)
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:
modules/templates/helper.go
modules/timeutil/datetime.go [new file with mode: 0644]
templates/admin/auth/list.tmpl
templates/admin/cron.tmpl
templates/admin/notice.tmpl
templates/admin/org/list.tmpl
templates/admin/packages/list.tmpl
templates/admin/queue.tmpl
templates/admin/repo/list.tmpl
templates/admin/user/list.tmpl
templates/explore/organizations.tmpl
templates/explore/users.tmpl
templates/package/shared/cleanup_rules/preview.tmpl
templates/package/view.tmpl
templates/repo/activity.tmpl
templates/repo/issue/milestone_issues.tmpl
templates/repo/issue/milestones.tmpl
templates/repo/issue/view_content/comments.tmpl
templates/repo/issue/view_content/sidebar.tmpl
templates/repo/settings/deploy_keys.tmpl
templates/repo/settings/options.tmpl
templates/repo/user_cards.tmpl
templates/shared/datetime/full.tmpl [deleted file]
templates/shared/datetime/long.tmpl [deleted file]
templates/shared/datetime/short.tmpl [deleted file]
templates/shared/issuelist.tmpl
templates/user/dashboard/milestones.tmpl
templates/user/profile.tmpl
templates/user/settings/applications.tmpl
templates/user/settings/grants_oauth2.tmpl
templates/user/settings/keys_gpg.tmpl
templates/user/settings/keys_principal.tmpl
templates/user/settings/keys_ssh.tmpl

index c82f88a42f2a09654cd535f71be4f71dea133a48..b7bef205603f33b5dd5cb85095c77357f1dac782 100644 (file)
@@ -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 (file)
index 0000000..02275bc
--- /dev/null
@@ -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")
+}
index 5350672026cbce90b87fc87f653aa51d3e24db3f..f8e15eddef65342dc84d02842286887483e7ed00 100644 (file)
@@ -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}}
index 51685112baff09949bc32413cb21547525ffb5e4..5dd63149445a0fbd97590fe9a5222f31863186ab 100644 (file)
@@ -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>
index 82acb142472a254c4aeb13957f7ac03d6c2151b4..51b0c6850a1e749bb5f0aeb5558c9cb662824413 100644 (file)
@@ -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}}
index 2e8a6359858a7c293cf19da928b93b553ce9a983..73435fdd379d8a4ec0704b0d8118ab9038bcdbcc 100644 (file)
@@ -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}}
index af98e76175438f875c11f54783c683dbc3fe90d4..48046f4296e4e404b77b7318dcc2f1f49b980f47 100644 (file)
@@ -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}}
index b6ca0de117184f0ca6a3b927b2ed36e2d0815e61..79b20dc1a47b36a2a3d0b43059b970ab28f49b17 100644 (file)
                                        {{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>
index 59aa36d19dea4c99d8a539e74024177f4da42bef..06c801774fbfe8ebb01efdc6947d94c801e2342c 100644 (file)
@@ -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}}
index c7644b3b4ee143c60e7646a4e6755ecd0918fa9b..fef7c7b27f9f0ffb661cee2a4128b8e9a16e0149 100644 (file)
@@ -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}}
index fe9359251b7f11b9e842c5e442b92b95a24eb766..e61a72b6edba5e3e281efffda9a0d4bad48a3a8a 100644 (file)
@@ -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>
index 5dbc4ef6e7463aba73ec8bc9ccc5b727285a6c02..4cab94ee86ca8de52b5846b8a5f9ecd7fa9a3da6 100644 (file)
@@ -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>
index f9c9bc71f0843167a5577707290d9fb1165f6493..ae1ce1b1d515b72c020b0f42cbde3bd2e2dc44df 100644 (file)
@@ -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>
index 7c622a91b3eb734626322125467e8c704edba360..36b0e8a8b3a05e487047d92ef23c2e7562e72e12 100644 (file)
@@ -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>
index aa71fe838b710dff3973e8d542f782c1a871a8c2..26734e304aeb7ea4afc53168f019ece163b67c18 100644 (file)
@@ -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">
index 137f2c2d9dda79649234ebe9e16defd2f6493e8e..ccbc40586a8ff507cd2082a0fbbf71b100bb2648 100644 (file)
@@ -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}}
index c07232c759584465b16cd2bd7e236a7d186d5c5e..7abb1a660699c099db4eac6d8d6c010bf388f6f4 100644 (file)
@@ -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}}
index 45077e91ba12ef7f8828cfc6a2f7821a85a0eee4..142c8153f0e2087a65a6b3f92fb2970ed883c8d3 100644 (file)
                                {{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}}
                                <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}}
                                {{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}}
index bab9ff19366594a90bca36657fa0d3d4af879e35..a8ca0331c756fc537a2c025ddd4f664e7f236e3b 100644 (file)
                                        <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)}}
index e577fcc5fa9764a1a8d6a7406b574dce7bb06f58..584a6ee1a6c16e0cf0d21f7627b1d9fc3678321c 100644 (file)
@@ -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>
index 9440f265fc4937671e37d927bc5a0be94db2ab46..0f69dac53c1583e53b8eb4c1723adac5a98a54d0 100644 (file)
@@ -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}}
                                                        {{$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}}
index a48fd41744c8e791a0cf06721a8f191536952ad8..5acea0b4d91bddf9287d37ddb4eca4c6c470ebdf 100644 (file)
@@ -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 (file)
index 1c55a4b..0000000
+++ /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 (file)
index 4880cf3..0000000
+++ /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 (file)
index e5bcef6..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<relative-time format="datetime" year="numeric" month="short" day="numeric" weekday="" datetime="{{.Datetime}}">{{.Fallback}}</relative-time>
index 198e76f37cbbeb4a1cbe8641ba7952b81ecc8e19..d3d9729fe40e45d29b9c10701c9feadc4b9172ca 100644 (file)
                                                <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}}
index 09519ce005cfc1a2dec7e4808956576b97b38dc1..468bde0b78da8050ad4355988bbc448064701c9f 100644 (file)
@@ -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}}
index 376dfacacf78ea7cb5610086054c69650934b9e5..2ad92612a2b6d500e5e9d98c6ae14b862031af29 100644 (file)
@@ -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">
index c8789bbe827b54aa3abe5d5b5eaf335ad44a574d..fb1154d0c8bfe88d64e89f4ff0ffc697de314b97 100644 (file)
@@ -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>
index 205b374176bc46d1daf1df27a5c1a50cdc075692..3fe34a87270ad72d05a79f7fab291506b659fb63 100644 (file)
@@ -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>
index 46b60aafd861d4eec3b180f1c82f9a8968e1cc3e..a4885554044e8204c2be35ffde9c3a861097e1fd 100644 (file)
@@ -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>
index 5251e465fd9641a7245d6152012f7684beca7b3e..51009fdea144490dcb1423b8f75658b27991ae49 100644 (file)
@@ -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>
index d66b4ea528c41c455f4623bd21ec74e4ac073c11..abe0624d968d8e163d511f57c5b3587fc0de1b0c 100644 (file)
@@ -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>