-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1510 from Ekep-Obasi/fix/video-player-timestamp-f…
…ormat Format Video Player Timestamp for Accurate Display
- Loading branch information
Showing
2 changed files
with
25 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,31 @@ | ||
import { secondsToMediaTime } from '..' | ||
|
||
describe('secondsToMediaTime', () => { | ||
it('converts 0 seconds to "00:00"', () => { | ||
expect(secondsToMediaTime(0)).toEqual('00:00') | ||
it('converts 0 seconds to "0:00"', () => { | ||
expect(secondsToMediaTime(0)).toEqual('0:00') | ||
}) | ||
|
||
it('converts 65 seconds to "01:05"', () => { | ||
expect(secondsToMediaTime(65)).toEqual('01:05') | ||
it('converts 65 seconds to "1:05"', () => { | ||
expect(secondsToMediaTime(65)).toEqual('1:05') | ||
}) | ||
|
||
it('converts 3600 seconds to "60:00"', () => { | ||
expect(secondsToMediaTime(3600)).toEqual('60:00') | ||
it('converts 3600 seconds to "1:00:00"', () => { | ||
expect(secondsToMediaTime(3600)).toEqual('1:00:00') | ||
}) | ||
|
||
it('converts 3665 seconds to "61:05"', () => { | ||
expect(secondsToMediaTime(3665)).toEqual('61:05') | ||
it('converts 3665 seconds to "1:01:05"', () => { | ||
expect(secondsToMediaTime(3665)).toEqual('1:01:05') | ||
}) | ||
|
||
it('converts 5025 seconds to "1:23:45"', () => { | ||
expect(secondsToMediaTime(5025)).toEqual('1:23:45') | ||
}) | ||
|
||
it('converts 7261 seconds to "2:01:01"', () => { | ||
expect(secondsToMediaTime(7261)).toEqual('2:01:01') | ||
}) | ||
|
||
it('handles large values correctly', () => { | ||
expect(secondsToMediaTime(123456)).toEqual('34:17:36') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
export const secondsToMediaTime = (seconds: number): string => { | ||
const minutes = Math.floor(seconds / 60) | ||
const hours = Math.floor(seconds / 3600) | ||
const minutes = Math.floor((seconds % 3600) / 60) | ||
const remainingSeconds = Math.floor(seconds % 60) | ||
|
||
const formattedMinutes = minutes.toString().padStart(2, '0') | ||
const formattedHours = hours > 0 ? `${hours}:` : '' | ||
const formattedMinutes = hours > 0 ? minutes.toString().padStart(2, '0') : minutes.toString() | ||
const formattedSeconds = remainingSeconds.toString().padStart(2, '0') | ||
|
||
return `${formattedMinutes}:${formattedSeconds}` | ||
return `${formattedHours}${formattedMinutes}:${formattedSeconds}` | ||
} |