Skip to content

Commit 08fd58a

Browse files
committed
Toggle status page date format between 12hr and 24hr
1 parent c4075bf commit 08fd58a

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<script setup lang="ts">
2+
import {DATE_FMT_12HR} from "../../utils/formatting";
3+
4+
const props = defineProps<{
5+
dateFmt: string;
6+
toggleDate(): void;
7+
}>();
8+
</script>
9+
10+
<template>
11+
<span>
12+
<input
13+
@click="props.toggleDate"
14+
:checked="props.dateFmt === DATE_FMT_12HR"
15+
type="checkbox"
16+
id="user-date-fmt-toggle"
17+
/>
18+
<label for="user-date-fmt-toggle">Show 12hr date format</label><br />
19+
</span>
20+
</template>

site/frontend/src/pages/status/page.vue

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import {
99
formatISODate,
1010
formatSecondsAsDuration,
1111
parseDateIsoStringOrNull,
12+
setDateFmt,
13+
getDateFmt,
14+
DATE_FMT_12HR,
15+
DATE_FMT_24HR,
1216
} from "../../utils/formatting";
1317
import {useExpandedStore} from "../../utils/expansion";
1418
import {
@@ -20,13 +24,15 @@ import {
2024
} from "./data";
2125
import Collector from "./collector.vue";
2226
import CommitSha from "./commit-sha.vue";
27+
import DateFmtPicker from "./date-format-selection.vue";
2328
2429
const loading = ref(true);
2530
2631
const data: Ref<{
2732
timeline: BenchmarkRequestRow[];
2833
queueLength: number;
2934
collectors: CollectorConfig[];
35+
dateFmt: string;
3036
} | null> = ref(null);
3137
3238
type BenchmarkRequestRow = BenchmarkRequest & {
@@ -77,6 +83,7 @@ async function loadStatusData(loading: Ref<boolean>) {
7783
timeline,
7884
collectors: resp.collectors,
7985
queueLength,
86+
dateFmt: getDateFmt(),
8087
};
8188
});
8289
}
@@ -101,6 +108,11 @@ function formatStatus(request: BenchmarkRequest): string {
101108
}
102109
}
103110
111+
function formatDate(dateString?: string): string {
112+
const fmt = data.value.dateFmt;
113+
return formatISODate(dateString, fmt);
114+
}
115+
104116
function hasErrors(request: BenchmarkRequest) {
105117
return Object.keys(request.errors).length !== 0;
106118
}
@@ -204,6 +216,17 @@ const {toggleExpanded: toggleExpandedErrors, isExpanded: hasExpandedErrors} =
204216
205217
const tableWidth = 8;
206218
219+
function toggleDate() {
220+
let dateFmt: string;
221+
if (data.value.dateFmt === DATE_FMT_24HR) {
222+
dateFmt = DATE_FMT_12HR;
223+
} else {
224+
dateFmt = DATE_FMT_24HR;
225+
}
226+
setDateFmt(dateFmt);
227+
data.value.dateFmt = dateFmt;
228+
}
229+
207230
loadStatusData(loading);
208231
</script>
209232

@@ -212,8 +235,9 @@ loadStatusData(loading);
212235
<div class="status-page-wrapper">
213236
<div class="timeline-wrapper">
214237
<h1>Timeline</h1>
215-
<span class="small-padding-bottom">
238+
<span class="local-time-message small-padding-bottom">
216239
<strong>Times are local.</strong>
240+
<DateFmtPicker :toggleDate="toggleDate" :dateFmt="data.dateFmt" />
217241
</span>
218242
<span class="small-padding-bottom">
219243
<ExpectedCurrentRequestCompletion />
@@ -256,7 +280,7 @@ loadStatusData(loading);
256280
/>
257281
</td>
258282
<td>
259-
{{ formatISODate(req.completedAt) }}
283+
{{ formatDate(req.completedAt) }}
260284
<span v-if="req.endEstimated">(est.)</span>
261285
</td>
262286
<td style="text-align: right">
@@ -421,4 +445,11 @@ loadStatusData(loading);
421445
.small-padding-bottom {
422446
padding-bottom: 8px;
423447
}
448+
449+
.local-time-message {
450+
display: flex;
451+
flex-direction: column;
452+
align-items: center;
453+
padding-bottom: 12px;
454+
}
424455
</style>

site/frontend/src/utils/formatting.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,23 @@ export function formatSecondsAsDuration(time: number): string {
2020
return s;
2121
}
2222

23+
export const DATE_FMT_KEY = "__rustc-perf-user-date-fmt-preference__";
24+
export const DATE_FMT_24HR = "yyyy-MM-dd HH:mm:ss";
25+
export const DATE_FMT_12HR = "yyyy-MM-dd pp";
26+
27+
export function setDateFmt(dateFmt: string) {
28+
window.localStorage.setItem(DATE_FMT_KEY, dateFmt);
29+
}
30+
31+
export function getDateFmt() {
32+
return window.localStorage.getItem(DATE_FMT_KEY) ?? DATE_FMT_24HR;
33+
}
34+
2335
// Takes a date like `2025-09-10T08:22:47.161348Z` -> `"2025-09-10 08:22:47"`
24-
export function formatISODate(dateString?: string): string {
36+
export function formatISODate(dateString?: string, fmt?: string): string {
2537
if (dateString) {
26-
return format(parseISO(dateString), "yyyy-MM-dd HH:mm:ss");
38+
const dateFmt = fmt ?? getDateFmt();
39+
return format(parseISO(dateString), dateFmt);
2740
}
2841
return "";
2942
}

0 commit comments

Comments
 (0)