Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set user's 24h preference from their current OS locale #29651

Merged
merged 21 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/timeutil/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func DateTime(format string, datetime any, extraAttrs ...string) template.HTML {

attrs := make([]string, 0, 10+len(extraAttrs))
attrs = append(attrs, extraAttrs...)
attrs = append(attrs, `data-tooltip-content`, `data-tooltip-interactive="true"`)
attrs = append(attrs, `data-tooltip-content`, `data-tooltip-interactive="true"`, `lang="unknown"`)
attrs = append(attrs, `format="datetime"`, `weekday=""`, `year="numeric"`)

switch format {
Expand Down
10 changes: 5 additions & 5 deletions modules/timeutil/datetime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ func TestDateTime(t *testing.T) {
assert.EqualValues(t, "-", DateTime("short", TimeStamp(0)))

actual := DateTime("short", "invalid")
assert.EqualValues(t, `<relative-time data-tooltip-content data-tooltip-interactive="true" format="datetime" weekday="" year="numeric" month="short" day="numeric" datetime="invalid">invalid</relative-time>`, actual)
assert.EqualValues(t, `<relative-time data-tooltip-content data-tooltip-interactive="true" lang="unknown"format="datetime" weekday="" year="numeric" month="short" day="numeric" datetime="invalid">invalid</relative-time>`, actual)

actual = DateTime("short", refTimeStr)
assert.EqualValues(t, `<relative-time data-tooltip-content data-tooltip-interactive="true" format="datetime" weekday="" year="numeric" month="short" day="numeric" datetime="2018-01-01T00:00:00Z">2018-01-01T00:00:00Z</relative-time>`, actual)
assert.EqualValues(t, `<relative-time data-tooltip-content data-tooltip-interactive="true" lang="unknown"format="datetime" weekday="" year="numeric" month="short" day="numeric" datetime="2018-01-01T00:00:00Z">2018-01-01T00:00:00Z</relative-time>`, actual)

actual = DateTime("short", refTime)
assert.EqualValues(t, `<relative-time data-tooltip-content data-tooltip-interactive="true" format="datetime" weekday="" year="numeric" month="short" day="numeric" datetime="2018-01-01T00:00:00Z">2018-01-01</relative-time>`, actual)
assert.EqualValues(t, `<relative-time data-tooltip-content data-tooltip-interactive="true" lang="unknown"format="datetime" weekday="" year="numeric" month="short" day="numeric" datetime="2018-01-01T00:00:00Z">2018-01-01</relative-time>`, actual)

actual = DateTime("short", refTimeStamp)
assert.EqualValues(t, `<relative-time data-tooltip-content data-tooltip-interactive="true" format="datetime" weekday="" year="numeric" month="short" day="numeric" datetime="2017-12-31T19:00:00-05:00">2017-12-31</relative-time>`, actual)
assert.EqualValues(t, `<relative-time data-tooltip-content data-tooltip-interactive="true" lang="unknown"format="datetime" weekday="" year="numeric" month="short" day="numeric" datetime="2017-12-31T19:00:00-05:00">2017-12-31</relative-time>`, actual)

actual = DateTime("full", refTimeStamp)
assert.EqualValues(t, `<relative-time data-tooltip-content data-tooltip-interactive="true" format="datetime" weekday="" year="numeric" month="short" day="numeric" hour="numeric" minute="numeric" second="numeric" datetime="2017-12-31T19:00:00-05:00">2017-12-31 19:00:00 -05:00</relative-time>`, actual)
assert.EqualValues(t, `<relative-time data-tooltip-content data-tooltip-interactive="true" lang="unknown"format="datetime" weekday="" year="numeric" month="short" day="numeric" hour="numeric" minute="numeric" second="numeric" datetime="2017-12-31T19:00:00-05:00">2017-12-31 19:00:00 -05:00</relative-time>`, actual)
}
2 changes: 1 addition & 1 deletion modules/timeutil/since.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func timeSinceUnix(then, now time.Time, _ translation.Locale) template.HTML {
}

// 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>`,
htm := fmt.Sprintf(`<relative-time class="time-since" prefix="" %s datetime="%s" data-tooltip-content data-tooltip-interactive="true" lang="unknown">%s</relative-time>`,
attrs, then.Format(time.RFC3339), friendlyText)
return template.HTML(htm)
}
Expand Down
4 changes: 2 additions & 2 deletions templates/admin/system_status.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dl class="admin-dl-horizontal">
<dt>{{ctx.Locale.Tr "admin.dashboard.server_uptime"}}</dt>
<dd><relative-time format="duration" datetime="{{.SysStatus.StartTime}}">{{.SysStatus.StartTime}}</relative-time></dd>
<dd><relative-time format="duration" lang="unknown" datetime="{{.SysStatus.StartTime}}">{{.SysStatus.StartTime}}</relative-time></dd>
<dt>{{ctx.Locale.Tr "admin.dashboard.current_goroutine"}}</dt>
<dd>{{.SysStatus.NumGoroutine}}</dd>
<div class="divider"></div>
Expand Down Expand Up @@ -52,7 +52,7 @@
<dt>{{ctx.Locale.Tr "admin.dashboard.next_gc_recycle"}}</dt>
<dd>{{.SysStatus.NextGC}}</dd>
<dt>{{ctx.Locale.Tr "admin.dashboard.last_gc_time"}}</dt>
<dd><relative-time format="duration" datetime="{{.SysStatus.LastGCTime}}">{{.SysStatus.LastGCTime}}</relative-time></dd>
<dd><relative-time format="duration" lang="unknown" datetime="{{.SysStatus.LastGCTime}}">{{.SysStatus.LastGCTime}}</relative-time></dd>
<dt>{{ctx.Locale.Tr "admin.dashboard.total_gc_pause"}}</dt>
<dd>{{.SysStatus.PauseTotalNs}}</dd>
<dt>{{ctx.Locale.Tr "admin.dashboard.last_gc_pause"}}</dt>
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/components/DiffCommitSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export default {
{{ commit.committer_or_author_name }}
<span class="text right">
<!-- TODO: make this respect the PreferredTimestampTense setting -->
<relative-time class="time-since" prefix="" :datetime="commit.time" data-tooltip-content data-tooltip-interactive="true">{{ commit.time }}</relative-time>
<relative-time class="time-since" prefix="" lang="unknown" :datetime="commit.time" data-tooltip-content data-tooltip-interactive="true">{{ commit.time }}</relative-time>
</span>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/components/RepoContributors.vue
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ export default {
month="short"
day="numeric"
weekday=""
lang="unknown"
:datetime="new Date(xAxisMin)"
>
{{ new Date(xAxisMin) }}
Expand All @@ -324,6 +325,7 @@ export default {
month="short"
day="numeric"
weekday=""
lang="unknown"
:datetime="new Date(xAxisMax)"
>
{{ new Date(xAxisMax) }}
Expand Down
Loading