diff options
author | Anderson Shindy Oki <[email protected]> | 2024-06-25 21:49:52 +0900 |
---|---|---|
committer | GitHub <[email protected]> | 2024-06-25 08:49:52 -0400 |
commit | 34089b0fd7915f61d7b0bdfd41a65c3d938bb380 (patch) | |
tree | 626343d5fa7506b61d9f5631ff0e7cf04a2cb751 | |
parent | 668ec386fc6eb2da53a68b3aaf8744ae364aaa97 (diff) | |
download | bazarr-34089b0fd7915f61d7b0bdfd41a65c3d938bb380.tar.gz bazarr-34089b0fd7915f61d7b0bdfd41a65c3d938bb380.zip |
Fixed uptime calculation overflowing hoursv1.4.4-beta.12
-rw-r--r-- | frontend/src/utilities/time.test.ts | 2 | ||||
-rw-r--r-- | frontend/src/utilities/time.ts | 33 |
2 files changed, 22 insertions, 13 deletions
diff --git a/frontend/src/utilities/time.test.ts b/frontend/src/utilities/time.test.ts index a0e936a25..25cc9d72e 100644 --- a/frontend/src/utilities/time.test.ts +++ b/frontend/src/utilities/time.test.ts @@ -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", () => { diff --git a/frontend/src/utilities/time.ts b/frontend/src/utilities/time.ts index 54f93289f..6e1519b62 100644 --- a/frontend/src/utilities/time.ts +++ b/frontend/src/utilities/time.ts @@ -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; +}; |