-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from vishalmishraa/only_acs
FIX : only active contest submission
- Loading branch information
Showing
3 changed files
with
88 additions
and
37 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"use client" | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
import { useEffect, useState } from "react"; | ||
|
||
export function useContestTime({ startTime, endTime }: { startTime: Date; endTime: Date }) { | ||
const [currentTime, setCurrentTime] = useState(Date.now()); | ||
const [isStarted, setIsStarted] = useState(false); | ||
|
||
console.log({ startTime, endTime }); | ||
|
||
useEffect(() => { | ||
const interval = setInterval(() => { | ||
const now = Date.now(); | ||
setCurrentTime(now); | ||
setIsStarted(now >= startTime.getTime()); | ||
}, 1000); | ||
|
||
return () => clearInterval(interval); | ||
}, [startTime]); | ||
|
||
const timeLeft = isStarted | ||
? Math.max(0, endTime.getTime() - currentTime) | ||
: Math.max(0, startTime.getTime() - currentTime); | ||
|
||
const formatTime = (time: number) => { | ||
const hours = Math.floor(time / 3600000); | ||
const minutes = Math.floor((time % 3600000) / 60000); | ||
const seconds = Math.floor((time % 60000) / 1000); | ||
return { hours, minutes, seconds }; | ||
}; | ||
|
||
const { hours, minutes, seconds } = formatTime(timeLeft); | ||
|
||
return { | ||
hours, | ||
minutes, | ||
seconds, | ||
timeLeft, | ||
currentTime, | ||
isStarted | ||
} | ||
} |
This should be more consistent. I mean i can implement this in more efficient way and less no. 9g line of code