Changed the timesync display to show seconds
This commit is contained in:
parent
66c40ef604
commit
8e157cc3ad
@ -1,9 +1,15 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useTimeSkew } from "../hooks/useTimeSkew";
|
import { useTimeSkew } from "../hooks/useTimeSkew";
|
||||||
|
|
||||||
function formatMs(ms: number) {
|
function formatDelay(ms: number, withSign = true) {
|
||||||
const sign = ms > 0 ? "+" : "";
|
const sign = withSign ? (ms > 0 ? "+" : ms < 0 ? "−" : "") : "";
|
||||||
return `${sign}${ms}ms`;
|
const abs = Math.abs(ms);
|
||||||
|
if (abs >= 1000) {
|
||||||
|
const s = Math.floor(abs / 1000);
|
||||||
|
const rem = abs % 1000;
|
||||||
|
return `${sign}${s}s${rem ? ` ${rem}ms` : ""}`;
|
||||||
|
}
|
||||||
|
return `${sign}${abs}ms`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TimeSyncNotice({
|
export default function TimeSyncNotice({
|
||||||
@ -33,11 +39,11 @@ export default function TimeSyncNotice({
|
|||||||
|
|
||||||
const ahead = skewMs > 0;
|
const ahead = skewMs > 0;
|
||||||
const msgJa = ahead
|
const msgJa = ahead
|
||||||
? `端末の時計が正確な時刻より ${formatMs(skewMs)} 進んでいます(往復遅延 ${rttMs ?? "-"}ms)`
|
? `端末の時計が正確な時刻より ${formatDelay(skewMs)} 進んでいます(通信往復遅延 ${rttMs ?? "-"}ms)`
|
||||||
: `端末の時計が正確な時刻より ${formatMs(-skewMs)} 遅れています(往復遅延 ${rttMs ?? "-"}ms)`;
|
: `端末の時計が正確な時刻より ${formatDelay(-skewMs)} 遅れています(通信往復遅延 ${rttMs ?? "-"}ms)`;
|
||||||
const msgEn = ahead
|
const msgEn = ahead
|
||||||
? `Your device clock is ${formatMs(skewMs)} ahead of the correct time (RTT ${rttMs ?? "-"}ms).`
|
? `Your device clock is ${formatDelay(skewMs)} ahead of the correct time (RTT ${rttMs ?? "-"}ms).`
|
||||||
: `Your device clock is ${formatMs(-skewMs)} behind the correct time (RTT ${rttMs ?? "-"}ms).`;
|
: `Your device clock is ${formatDelay(-skewMs)} behind the correct time (RTT ${rttMs ?? "-"}ms).`;
|
||||||
|
|
||||||
const onClose = () => {
|
const onClose = () => {
|
||||||
setDismissed(true);
|
setDismissed(true);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user