Skip to content

Commit d8e73a5

Browse files
committed
fix lint
1 parent 5bf5d41 commit d8e73a5

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

modules/timeutil/since.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func timeSincePro(then, now time.Time, lang translation.Locale) string {
114114
return strings.TrimPrefix(timeStr, ", ")
115115
}
116116

117-
func timeSinceUnix(then, now time.Time, lang translation.Locale) template.HTML {
117+
func timeSinceUnix(then, now time.Time, lang translation.Locale, attrsMap ...map[string]any) template.HTML {
118118
friendlyText := then.Format("2006-01-02 15:04:05 +07:00")
119119

120120
// document: https://github.com/github/relative-time-element
@@ -124,18 +124,30 @@ func timeSinceUnix(then, now time.Time, lang translation.Locale) template.HTML {
124124
attrs = `tense="future"`
125125
}
126126

127+
transOnDate := ""
128+
if len(attrsMap) == 1 {
129+
m := attrsMap[0]
130+
if m["tense"] == "auto" {
131+
attrs = `tense="auto"` // "relative-time" doesn't support i18n of "prefix", so we use our translation
132+
transOnDate = lang.Tr("tool.on_date")
133+
}
134+
}
135+
127136
// declare data-tooltip-content attribute to switch from "title" tooltip to "tippy" tooltip
128137
htm := fmt.Sprintf(`<relative-time class="time-since" prefix="" %s datetime="%s" data-tooltip-content data-tooltip-interactive="true">%s</relative-time>`,
129138
attrs, then.Format(time.RFC3339), friendlyText)
139+
if transOnDate != "" {
140+
htm = fmt.Sprintf(transOnDate, htm)
141+
}
130142
return template.HTML(htm)
131143
}
132144

133145
// TimeSince renders relative time HTML given a time.Time
134-
func TimeSince(then time.Time, lang translation.Locale) template.HTML {
135-
return timeSinceUnix(then, time.Now(), lang)
146+
func TimeSince(then time.Time, lang translation.Locale, attrs ...map[string]any) template.HTML {
147+
return timeSinceUnix(then, time.Now(), lang, attrs...)
136148
}
137149

138150
// TimeSinceUnix renders relative time HTML given a TimeStamp
139-
func TimeSinceUnix(then TimeStamp, lang translation.Locale) template.HTML {
140-
return TimeSince(then.AsLocalTime(), lang)
151+
func TimeSinceUnix(then TimeStamp, lang translation.Locale, extra ...map[string]any) template.HTML {
152+
return TimeSince(then.AsLocalTime(), lang, extra...)
141153
}

options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -3127,6 +3127,7 @@ starred_repo = starred <a href="%[1]s">%[2]s</a>
31273127
watched_repo = started watching <a href="%[1]s">%[2]s</a>
31283128
31293129
[tool]
3130+
on_date = on %s
31303131
now = now
31313132
future = future
31323133
1s = 1 second

templates/devtest/gitea-ui.tmpl

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
<div>2m future: {{TimeSince .TimeFuture2m $.locale}}</div>
3434
<div>1y past: {{TimeSince .TimePast1y $.locale}}</div>
3535
<div>1y future: {{TimeSince .TimeFuture1y $.locale}}</div>
36+
<div>1y past (tense=auto): {{TimeSince .TimePast1y $.locale (dict "tense" "auto")}}</div>
37+
<div>1y future (tense=auto): {{TimeSince .TimeFuture1y $.locale (dict "tense" "auto")}}</div>
3638
</div>
3739

3840
<div>

0 commit comments

Comments
 (0)