Files
doctate/server/templates/partials/time_format.js
T
Brummel e795bdf6a5 feat: Display most recent recording time
Add `recorded_at_iso` and `time_hms_utc` to `CasePageTemplate` to
display the timestamp of the most recent recording.
Introduce a new partial `partials/time_format.js` for consistent date
and time formatting in the browser.
Update templates to use the new partial for rendering timestamps and
group headings.
2026-04-20 10:51:01 +02:00

28 lines
1.1 KiB
JavaScript

// Inline helper module for timezone- and locale-aware date/time labels.
// Included verbatim by templates; exposes `window.TimeFmt`.
//
// Heute/Gestern is decided in UTC (same as server-side grouping) to keep
// client and server in lockstep. Locale date format follows the browser.
(() => {
const utcDayISO = (d) => d.toISOString().slice(0, 10);
const todayISO = () => utcDayISO(new Date());
const yesterdayISO = () => {
const y = new Date();
y.setUTCDate(y.getUTCDate() - 1);
return utcDayISO(y);
};
const dateLabelFromISO = (iso) => {
if (iso === todayISO()) return 'Heute';
if (iso === yesterdayISO()) return 'Gestern';
const parts = iso.split('-');
if (parts.length !== 3) return iso;
return new Date(Date.UTC(+parts[0], +parts[1] - 1, +parts[2]))
.toLocaleDateString();
};
const dateLabel = (d) => dateLabelFromISO(utcDayISO(d));
const timeLabel = (d) => d.toLocaleTimeString(undefined, {
hour: '2-digit', minute: '2-digit', hour12: false,
});
window.TimeFmt = { dateLabelFromISO, dateLabel, timeLabel };
})();