blob: a31c6b27814ad7120cc30953c7d8bd078bacd10a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
type Props = {
sec: number;
};
export default function LeftTime({ sec }: Props) {
const s = sec % 60;
const m = Math.floor(sec / 60) % 60;
const h = Math.floor(sec / 3600) % 24;
const d = Math.floor(sec / 86400);
let leftTime = "";
if (d > 0 || h > 0) {
// 1d 2h 3m 4s
leftTime = [
d > 0 ? `${d}d` : "",
h > 0 ? `${h}h` : "",
m > 0 ? `${m}m` : "",
`${s}s`,
].join(" ");
} else {
// 03:04
leftTime = `${m.toString().padStart(2, "0")}:${s.toString().padStart(2, "0")}`;
}
return <div className="text-3xl">{leftTime}</div>;
}
|