Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip(web/actionModal): finished info tab + smaller sttuff
- Loading branch information
Showing
3 changed files
with
118 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { tsToLocaleDate, tsToLocaleDateTime } from "@/lib/utils"; | ||
import { txToast } from "./TxToaster"; | ||
|
||
const clockSkewTolerance = 5 * 60; //5 minutes | ||
|
||
type Props = { | ||
tsFetch: number; | ||
tsObject: number; | ||
serverTime: number; | ||
className?: string; | ||
isDateOnly?: boolean; | ||
}; | ||
|
||
export default function DateTimeCorrected({ tsFetch, tsObject, serverTime, className, isDateOnly }: Props) { | ||
const serverClockDrift = serverTime - tsFetch; //be positive if server is ahead | ||
const howFarInThePast = serverTime - tsObject; | ||
const localTime = tsFetch - howFarInThePast; | ||
|
||
const clockDriftBtnHandler = () => { | ||
txToast.warning(`This means that the server clock is ${Math.abs(serverClockDrift)} seconds ${serverClockDrift > 0 ? 'ahead' : 'behind'} your computer time. Make sure both your computer and the server have their clocks synchronized.`); | ||
} | ||
const displayTime = isDateOnly | ||
? tsToLocaleDate(localTime, 'short') | ||
: tsToLocaleDateTime(localTime, 'medium', 'short') | ||
return <span | ||
className={className} | ||
title={tsToLocaleDateTime(localTime, 'long', 'long')} | ||
> | ||
{displayTime} | ||
{Math.abs(serverClockDrift) > clockSkewTolerance && ( | ||
<button | ||
className="ml-1 text-warning-inline" | ||
onClick={clockDriftBtnHandler} | ||
>(clock drift)</button> | ||
)} | ||
</span> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters