Respect user's 12/24 hour preference consistently (#29237)

* Respect user's 12/24 hour preference consistently

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update test

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

---------

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski
2025-02-11 14:16:59 +00:00
committed by GitHub
parent f2fae82e32
commit 6fa8032caa
3 changed files with 11 additions and 4 deletions

View File

@@ -7,6 +7,9 @@ Please see LICENSE files in the repository root for full details.
import { useEffect, useState } from "react";
import { type MatrixClient, MatrixError } from "matrix-js-sdk/src/matrix";
import { getTwelveHourOptions } from "../DateUtils.ts";
import { useSettingValue } from "./useSettings.ts";
/**
* Fetch a user's delclared timezone through their profile, and return
* a friendly string of the current time for that user. This will keep
@@ -23,6 +26,7 @@ export const useUserTimezone = (cli: MatrixClient, userId: string): { timezone:
const [updateInterval, setUpdateInterval] = useState<ReturnType<typeof setTimeout>>();
const [friendly, setFriendly] = useState<string>();
const [supported, setSupported] = useState<boolean>();
const showTwelveHour = useSettingValue("showTwelveHourTimestamps");
useEffect(() => {
if (!cli || supported !== undefined) {
@@ -62,8 +66,8 @@ export const useUserTimezone = (cli: MatrixClient, userId: string): { timezone:
const updateTime = (): void => {
const currentTime = new Date();
const friendly = currentTime.toLocaleString(undefined, {
...getTwelveHourOptions(showTwelveHour),
timeZone: tz,
hour12: true,
hour: "2-digit",
minute: "2-digit",
timeZoneName: "shortOffset",
@@ -84,7 +88,7 @@ export const useUserTimezone = (cli: MatrixClient, userId: string): { timezone:
console.error("Could not render current timezone for user", ex);
}
})();
}, [supported, userId, cli]);
}, [supported, userId, cli, showTwelveHour]);
if (!timezone || !friendly) {
return null;