Last active
March 23, 2022 02:55
-
-
Save renatoassis01/6b1fdf15583a4f42ad9b149987571616 to your computer and use it in GitHub Desktop.
seconds to time total moment
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
export function SecondsToTimeTotal(seconds: number): string { | |
const NINE_HOURS_IN_SECONDS = 32400; | |
const ms = seconds * 1000; | |
if (seconds < 3600) return moment.utc(ms).format('HH:mm'); | |
const hours = Math.floor(moment.duration(ms).asHours()); | |
if (seconds <= NINE_HOURS_IN_SECONDS) | |
return `0${hours}:${moment.utc(ms).format('mm')}`; | |
return `${hours}:${moment.utc(ms).format('mm')}`; | |
} | |
describe('Suite tests SecondsToTime', () => { | |
it('CASE 0', () => { | |
expect(SecondsToTimeTotal(0)).toBe('00:00'); | |
}); | |
it('CASE 1', () => { | |
expect(SecondsToTimeTotal(28800)).toBe('08:00'); | |
}); | |
it('CASE 2', () => { | |
expect(SecondsToTimeTotal(775800)).toBe('215:30'); | |
}); | |
it('CASE 3', () => { | |
expect(SecondsToTimeTotal(775600)).toBe('215:26'); | |
}); | |
it('CASE 4', () => { | |
expect(SecondsToTimeTotal(89400)).toBe('24:50'); | |
}); | |
it('CASE 5', () => { | |
expect(SecondsToTimeTotal(89460)).toBe('24:51'); | |
}); | |
it('CASE 6', () => { | |
expect(SecondsToTimeTotal(2880780)).toBe('800:13'); | |
}); | |
it('CASE 7', () => { | |
expect(SecondsToTimeTotal(18960)).toBe('05:16'); | |
}); | |
it('CASE 8', () => { | |
expect(SecondsToTimeTotal(3600)).toBe('01:00'); | |
}); | |
it('CASE 9', () => { | |
expect(SecondsToTimeTotal(1440)).toBe('00:24'); | |
}); | |
it('CASE 10', () => { | |
expect(SecondsToTimeTotal(3540)).toBe('00:59'); | |
}); | |
it('CASE 11', () => { | |
expect(SecondsToTimeTotal(300)).toBe('00:05'); | |
}); | |
it('CASE 12', () => { | |
expect(SecondsToTimeTotal(3720)).toBe('01:02'); | |
}); | |
it('CASE 13', () => { | |
expect(SecondsToTimeTotal(47580)).toBe('13:13'); | |
}); | |
it('CASE 14', () => { | |
expect(SecondsToTimeTotal(60)).toBe('00:01'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment