|
|
@ -11,19 +11,28 @@ export const divisorSecond = 1;
|
|
|
|
export const formatTime = (
|
|
|
|
export const formatTime = (
|
|
|
|
timeInSeconds: number,
|
|
|
|
timeInSeconds: number,
|
|
|
|
formats: TimeFormat[],
|
|
|
|
formats: TimeFormat[],
|
|
|
|
): string =>
|
|
|
|
): string => {
|
|
|
|
formats.reduce(
|
|
|
|
return formats.reduce(
|
|
|
|
(formattedTime: string, { unit, divisor }: TimeFormat, index: number) => {
|
|
|
|
(
|
|
|
|
const timeValue: number =
|
|
|
|
{ formattedTime, remainingSeconds },
|
|
|
|
index === 0
|
|
|
|
{ unit, divisor }: TimeFormat,
|
|
|
|
? Math.floor(timeInSeconds / divisor)
|
|
|
|
index: number,
|
|
|
|
: Math.floor(timeInSeconds / divisor) % 60;
|
|
|
|
) => {
|
|
|
|
return (
|
|
|
|
const timeValue = Math.floor(remainingSeconds / divisor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const seconds = remainingSeconds % divisor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const time =
|
|
|
|
formattedTime +
|
|
|
|
formattedTime +
|
|
|
|
(index === 0
|
|
|
|
(index === 0
|
|
|
|
? `${timeValue}${unit} `
|
|
|
|
? `${timeValue}${unit} `
|
|
|
|
: `${timeValue.toString().padStart(2, "0")}${index < formats.length - 1 ? ":" : ""}`)
|
|
|
|
: `${timeValue.toString().padStart(2, "0")}${index < formats.length - 1 ? ":" : ""}`);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
formattedTime: time,
|
|
|
|
|
|
|
|
remainingSeconds: seconds,
|
|
|
|
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"",
|
|
|
|
{ formattedTime: "", remainingSeconds: timeInSeconds },
|
|
|
|
);
|
|
|
|
).formattedTime;
|
|
|
|
|
|
|
|
};
|
|
|
|