Przeglądaj źródła

fix: floating point time value format

Fela Maslen 5 lat temu
rodzic
commit
7a31718067
2 zmienionych plików z 2 dodań i 1 usunięć
  1. 1 0
      gmus-web/src/utils/time.spec.ts
  2. 1 1
      gmus-web/src/utils/time.ts

+ 1 - 0
gmus-web/src/utils/time.spec.ts

@@ -12,6 +12,7 @@ describe(formatTime.name, () => {
     ${'more than one hour'}    | ${3615}   | ${'1:00:15'}
     ${'more than one hour'}    | ${3615}   | ${'1:00:15'}
     ${'more than one day'}     | ${86465}  | ${'1 day, 01:05'}
     ${'more than one day'}     | ${86465}  | ${'1 day, 01:05'}
     ${'negative values'}       | ${-86465} | ${'-1 day, 01:05'}
     ${'negative values'}       | ${-86465} | ${'-1 day, 01:05'}
+    ${'floating point values'} | ${119.99} | ${'02:00'}
   `('should handle case: $case', ({ input, output }) => {
   `('should handle case: $case', ({ input, output }) => {
     expect.assertions(1);
     expect.assertions(1);
     expect(formatTime(input)).toBe(output);
     expect(formatTime(input)).toBe(output);

+ 1 - 1
gmus-web/src/utils/time.ts

@@ -5,7 +5,7 @@ export function formatTime(seconds: number | null): string {
     return '';
     return '';
   }
   }
 
 
-  const totalSecondsAbsolute = Math.abs(seconds);
+  const totalSecondsAbsolute = Math.abs(Math.round(seconds));
   const sign = seconds < 0 ? '-' : '';
   const sign = seconds < 0 ? '-' : '';
 
 
   const hours = Math.floor(totalSecondsAbsolute / 3600);
   const hours = Math.floor(totalSecondsAbsolute / 3600);