Make the wall display and Proxmox dates follow the date and time settings
The wall clock, date line and 'Updated' footer used the browser locale, and the Proxmox backup tasks and PBS page used toLocaleString. They now use the display settings via new formatDate/formatTime helpers. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bff0c2169e
commit
3945c60681
4 files changed
+23
-21
No files matched your search
+15
-16
@@ -30,37 +30,36 @@ function pad(n: number): string {
|
||||
return String(n).padStart(2, "0");
|
||||
}
|
||||
|
||||
/** Formats a date using the app-wide date/time display settings (defaults to "YYYY-MM-DD HH:mm:ss" on a 24-hour clock). */
|
||||
export function formatDateTime(date: Date): string {
|
||||
/** The date part alone, in the chosen date format ("2026-10-16", "16/10/2026" or "10/16/2026"). */
|
||||
export function formatDate(date: Date): string {
|
||||
const year = date.getFullYear();
|
||||
const month = pad(date.getMonth() + 1);
|
||||
const day = pad(date.getDate());
|
||||
|
||||
let datePart: string;
|
||||
switch (current.dateFormat) {
|
||||
case "dmy":
|
||||
datePart = `${day}/${month}/${year}`;
|
||||
break;
|
||||
return `${day}/${month}/${year}`;
|
||||
case "mdy":
|
||||
datePart = `${month}/${day}/${year}`;
|
||||
break;
|
||||
return `${month}/${day}/${year}`;
|
||||
case "ymd":
|
||||
default:
|
||||
datePart = `${year}-${month}-${day}`;
|
||||
break;
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
}
|
||||
|
||||
/** The time part alone, on the chosen 12- or 24-hour clock; seconds are left out when `withSeconds` is false (a wall clock, say). */
|
||||
export function formatTime(date: Date, withSeconds = true): string {
|
||||
const minutes = pad(date.getMinutes());
|
||||
const seconds = pad(date.getSeconds());
|
||||
let timePart: string;
|
||||
const seconds = withSeconds ? `:${pad(date.getSeconds())}` : "";
|
||||
if (current.timeFormat === "12h") {
|
||||
const hour24 = date.getHours();
|
||||
const period = hour24 >= 12 ? "PM" : "AM";
|
||||
const hour12 = hour24 % 12 || 12;
|
||||
timePart = `${hour12}:${minutes}:${seconds} ${period}`;
|
||||
} else {
|
||||
timePart = `${pad(date.getHours())}:${minutes}:${seconds}`;
|
||||
return `${hour24 % 12 || 12}:${minutes}${seconds} ${period}`;
|
||||
}
|
||||
return `${pad(date.getHours())}:${minutes}${seconds}`;
|
||||
}
|
||||
|
||||
return `${datePart} ${timePart}`;
|
||||
/** Formats a date using the app-wide date/time display settings (defaults to "YYYY-MM-DD HH:mm:ss" on a 24-hour clock). */
|
||||
export function formatDateTime(date: Date): string {
|
||||
return `${formatDate(date)} ${formatTime(date)}`;
|
||||
}
|
||||
Reference in new issue
Block a user