mirror of
https://codeberg.org/demostf/frontend.git
synced 2026-06-03 18:24:12 +02:00
edit wip
This commit is contained in:
parent
0ab24ead47
commit
189788a1b6
14 changed files with 599 additions and 6 deletions
30
script/components/Duration.tsx
Normal file
30
script/components/Duration.tsx
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
export function formatDuration(input) {
|
||||
if (!input) {
|
||||
return '0:00';
|
||||
}
|
||||
const hours = Math.floor(input / 3600);
|
||||
const minutes = Math.floor((input - (hours * 3600)) / 60);
|
||||
const seconds = Math.floor(input - (hours * 3600) - (minutes * 60));
|
||||
|
||||
const hourString = (hours < 10) ? "0" + hours : "" + hours;
|
||||
const minuteString = (minutes < 10) ? "0" + minutes : "" + minutes;
|
||||
const secondString = (seconds < 10) ? "0" + seconds : "" + seconds;
|
||||
|
||||
if (hourString !== '00') {
|
||||
return hourString + ':' + minuteString + ':' + secondString;
|
||||
} else {
|
||||
return minuteString + ':' + secondString;
|
||||
}
|
||||
}
|
||||
|
||||
export interface DurationProps {
|
||||
duration: number;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function Duration(props: DurationProps) {
|
||||
const duration = formatDuration(props.duration);
|
||||
return (
|
||||
<span className={props.className||''}>{duration}</span>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue