Skip to content

Commit 4785128

Browse files
committed
Add ability to tune the relative-time elements in TimeSince functions
1 parent 29194a9 commit 4785128

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

modules/timeutil/since.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ func timeSincePro(then, now time.Time, lang translation.Locale) string {
115115
}
116116

117117
// TimeSince renders relative time HTML given a time.Time
118-
func TimeSince(then time.Time, lang translation.Locale) template.HTML {
118+
func TimeSince(then time.Time, lang translation.Locale, relativeTimeOptions ...string) template.HTML {
119119
timestamp := then.UTC().Format(time.RFC3339)
120120
// declare data-tooltip-content attribute to switch from "title" tooltip to "tippy" tooltip
121-
return template.HTML(fmt.Sprintf(`<relative-time class="time-since" prefix="%s" datetime="%s" data-tooltip-content data-tooltip-interactive="true">%s</relative-time>`, lang.Tr("on_date"), timestamp, timestamp))
121+
return template.HTML(fmt.Sprintf(`<relative-time class="time-since" %s prefix="%s" datetime="%s" data-tooltip-content data-tooltip-interactive="true">%s</relative-time>`, strings.Join(relativeTimeOptions, " "), lang.Tr("on_date"), timestamp, timestamp))
122122
}
123123

124124
// TimeSinceUnix renders relative time HTML given a TimeStamp
125-
func TimeSinceUnix(then TimeStamp, lang translation.Locale) template.HTML {
126-
return TimeSince(then.AsLocalTime(), lang)
125+
func TimeSinceUnix(then TimeStamp, lang translation.Locale, relativeTimeOptions ...string) template.HTML {
126+
return TimeSince(then.AsLocalTime(), lang, relativeTimeOptions...)
127127
}

templates/repo/view_list.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</span>
3535
{{end}}
3636
</th>
37-
<th class="text grey right age">{{if .LatestCommit}}{{if .LatestCommit.Committer}}{{TimeSince .LatestCommit.Committer.When $.locale}}{{end}}{{end}}</th>
37+
<th class="text grey right age">{{if .LatestCommit}}{{if .LatestCommit.Committer}}{{TimeSince .LatestCommit.Committer.When $.locale "tense=\"past\""}}{{end}}{{end}}</th>
3838
</tr>
3939
</thead>
4040
<tbody>
@@ -87,7 +87,7 @@
8787
{{end}}
8888
</span>
8989
</td>
90-
<td class="text right age three wide">{{if $commit}}{{TimeSince $commit.Committer.When $.locale}}{{end}}</td>
90+
<td class="text right age three wide">{{if $commit}}{{TimeSince $commit.Committer.When $.locale "tense=\"past\""}}{{end}}</td>
9191
</tr>
9292
{{end}}
9393
</tbody>

0 commit comments

Comments
 (0)