mirror of https://github.com/morpheus65535/bazarr
Fixed uptime calculation overflowing hours
This commit is contained in:
parent
668ec386fc
commit
34089b0fd7
|
@ -30,7 +30,7 @@ describe("formatTime", () => {
|
|||
{ unit: "s", divisor: divisorSecond },
|
||||
]);
|
||||
|
||||
expect(formattedTime).toBe("581d 25:27:41");
|
||||
expect(formattedTime).toBe("581d 01:27:41");
|
||||
});
|
||||
|
||||
it("should format time day hour minute", () => {
|
||||
|
|
|
@ -11,19 +11,28 @@ export const divisorSecond = 1;
|
|||
export const formatTime = (
|
||||
timeInSeconds: number,
|
||||
formats: TimeFormat[],
|
||||
): string =>
|
||||
formats.reduce(
|
||||
(formattedTime: string, { unit, divisor }: TimeFormat, index: number) => {
|
||||
const timeValue: number =
|
||||
index === 0
|
||||
? Math.floor(timeInSeconds / divisor)
|
||||
: Math.floor(timeInSeconds / divisor) % 60;
|
||||
return (
|
||||
): string => {
|
||||
return formats.reduce(
|
||||
(
|
||||
{ formattedTime, remainingSeconds },
|
||||
{ unit, divisor }: TimeFormat,
|
||||
index: number,
|
||||
) => {
|
||||
const timeValue = Math.floor(remainingSeconds / divisor);
|
||||
|
||||
const seconds = remainingSeconds % divisor;
|
||||
|
||||
const time =
|
||||
formattedTime +
|
||||
(index === 0
|
||||
? `${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;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue