-
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.
feat: Added timer functionality (start/stop/reset)
- Loading branch information
Showing
6 changed files
with
107 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import dayjs from "dayjs" | ||
|
||
/** | ||
* @param timestamp1 ISO string | ||
* @param timestamp2 ISO string | ||
* @returns Difference in milliseconds | ||
*/ | ||
export const diffBetweenTimestamps = ( | ||
timestamp1: string, | ||
timestamp2: string | ||
): number => { | ||
// Of course this isn't exactly a complicated function. It's put into this file just to demonstrate | ||
// the use of library functions that may be reused across the application. | ||
const date1 = dayjs(timestamp1) | ||
const date2 = dayjs(timestamp2) | ||
|
||
return date1.diff(date2) | ||
} |
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 |
---|---|---|
@@ -1,7 +1,25 @@ | ||
import { useState } from "react" | ||
import dayjs from "dayjs" | ||
import { useMemo } from "react" | ||
|
||
export const TimerDisplay = () => { | ||
const [time] = useState(0) | ||
interface ITimerDisplayProps { | ||
elapsedTime: number | ||
} | ||
|
||
export const TimerDisplay = (props: ITimerDisplayProps) => { | ||
const { elapsedTime } = props | ||
|
||
const formattedTime = useMemo(() => { | ||
const duration = dayjs.duration(elapsedTime) | ||
|
||
if (duration.hours()) { | ||
//TODO Check requirements for hour display | ||
// This depends on the requirements. The `MM:ss` format has been defined, | ||
// but not what should happen with the edge case of reaching an hour or more | ||
return duration.format("HH:MM:ss") | ||
} | ||
|
||
return duration.format("MM:ss") | ||
}, [elapsedTime]) | ||
|
||
return <div className="flex justify-center text-9xl m-6">{time}</div> | ||
return <div className="flex justify-center text-9xl m-6">{formattedTime}</div> | ||
} |
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