diff options
author | Yarden Shoham <git@yardenshoham.com> | 2023-04-15 14:01:54 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-15 13:01:54 +0200 |
commit | b4e952545b95953056f2645b38aa17d15bcd58ab (patch) | |
tree | d5e84c516c743a15bc39a548ca1a7caf1cf81569 /modules | |
parent | 35e562d7bd5e984a5cb97f74f5753d2a9998c1d3 (diff) | |
download | gitea-b4e952545b95953056f2645b38aa17d15bcd58ab.tar.gz gitea-b4e952545b95953056f2645b38aa17d15bcd58ab.zip |
Remove untranslatable `on_date` key (#24106)
- Follows #23988
- Fixes: #24074 by removing this key
GitHub's `relative-time` elements allow us to force their rendering to
`auto`, `past`, or `future` tense. We will never show an absolute date
`on ...` in `TimeSince`
## Before
![image](https://user-images.githubusercontent.com/20454870/231735872-048c7bf3-6aa1-4113-929d-75a985c9922c.png)
## After
![image](https://user-images.githubusercontent.com/20454870/231736116-6ad47b63-77f4-4d3f-82a2-ee9a46ba2bd1.png)
---------
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/timeutil/since.go | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/modules/timeutil/since.go b/modules/timeutil/since.go index bdde54c617..e6a2519d21 100644 --- a/modules/timeutil/since.go +++ b/modules/timeutil/since.go @@ -114,11 +114,25 @@ func timeSincePro(then, now time.Time, lang translation.Locale) string { return strings.TrimPrefix(timeStr, ", ") } +func timeSinceUnix(then, now time.Time, lang translation.Locale) template.HTML { + friendlyText := then.Format("2006-01-02 15:04:05 +07:00") + + // document: https://github.com/github/relative-time-element + attrs := `tense="past"` + isFuture := now.Before(then) + if isFuture { + attrs = `tense="future"` + } + + // declare data-tooltip-content attribute to switch from "title" tooltip to "tippy" tooltip + htm := fmt.Sprintf(`<relative-time class="time-since" prefix="" %s datetime="%s" data-tooltip-content data-tooltip-interactive="true">%s</relative-time>`, + attrs, then.Format(time.RFC3339), friendlyText) + return template.HTML(htm) +} + // TimeSince renders relative time HTML given a time.Time func TimeSince(then time.Time, lang translation.Locale) template.HTML { - timestamp := then.UTC().Format(time.RFC3339) - // declare data-tooltip-content attribute to switch from "title" tooltip to "tippy" tooltip - 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)) + return timeSinceUnix(then, time.Now(), lang) } // TimeSinceUnix renders relative time HTML given a TimeStamp |