-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add helper function to convert seconds to timeunits (#28)
* feat: add helper function to convert seconds to timeunits * chore: add spec * chore: refactor * chore: improve spec coverage * chore: Publish v0.0.22 --------- Co-authored-by: Muhsin Keloth <[email protected]>
- Loading branch information
1 parent
1203c4d
commit d2aa147
Showing
3 changed files
with
71 additions
and
1 deletion.
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
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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { convertSecondsToTimeUnit } from '../src/helpers'; | ||
|
||
describe('#convertSecondsToTimeUnit', () => { | ||
it("it should return { time: 1, unit: 'm' } if 60 seconds passed", () => { | ||
expect( | ||
convertSecondsToTimeUnit(60, { minute: 'm', hour: 'h', day: 'd' }) | ||
).toEqual({ time: 1, unit: 'm' }); | ||
}); | ||
it("it should return { time: 1, unit: 'Minutes' } if 60 seconds passed", () => { | ||
expect( | ||
convertSecondsToTimeUnit(60, { | ||
minute: 'Minutes', | ||
hour: 'Hours', | ||
day: 'Days', | ||
}) | ||
).toEqual({ time: 1, unit: 'Minutes' }); | ||
}); | ||
it("it should return { time: 1, unit: 'h' } if 3600 seconds passed", () => { | ||
expect( | ||
convertSecondsToTimeUnit(3600, { minute: 'm', hour: 'h', day: 'd' }) | ||
).toEqual({ time: 1, unit: 'h' }); | ||
}); | ||
it("it should return { time: 1, unit: 'Hours' } if 3600 seconds passed", () => { | ||
expect( | ||
convertSecondsToTimeUnit(3600, { | ||
minute: 'Minutes', | ||
hour: 'Hours', | ||
day: 'Days', | ||
}) | ||
).toEqual({ time: 1, unit: 'Hours' }); | ||
}); | ||
it("it should return { time: 1, unit: 'd' } if 86400 seconds passed", () => { | ||
expect( | ||
convertSecondsToTimeUnit(86400, { minute: 'm', hour: 'h', day: 'd' }) | ||
).toEqual({ time: 1, unit: 'd' }); | ||
}); | ||
it("it should return { time: 1, unit: 'Days' } if 86400 seconds passed", () => { | ||
expect( | ||
convertSecondsToTimeUnit(86400, { | ||
minute: 'Minutes', | ||
hour: 'Hours', | ||
day: 'Days', | ||
}) | ||
).toEqual({ time: 1, unit: 'Days' }); | ||
}); | ||
}); |