@@ -114,7 +114,7 @@ func timeSincePro(then, now time.Time, lang translation.Locale) string {
114
114
return strings .TrimPrefix (timeStr , ", " )
115
115
}
116
116
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 {
118
118
friendlyText := then .Format ("2006-01-02 15:04:05 +07:00" )
119
119
120
120
// document: https://github.com/github/relative-time-element
@@ -124,18 +124,30 @@ func timeSinceUnix(then, now time.Time, lang translation.Locale) template.HTML {
124
124
attrs = `tense="future"`
125
125
}
126
126
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
+
127
136
// declare data-tooltip-content attribute to switch from "title" tooltip to "tippy" tooltip
128
137
htm := fmt .Sprintf (`<relative-time class="time-since" prefix="" %s datetime="%s" data-tooltip-content data-tooltip-interactive="true">%s</relative-time>` ,
129
138
attrs , then .Format (time .RFC3339 ), friendlyText )
139
+ if transOnDate != "" {
140
+ htm = fmt .Sprintf (transOnDate , htm )
141
+ }
130
142
return template .HTML (htm )
131
143
}
132
144
133
145
// 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 ... )
136
148
}
137
149
138
150
// 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 ... )
141
153
}
0 commit comments