Skip to content

Commit

Permalink
support hour in time string, @micooz and @Oukanina
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Feb 3, 2018
1 parent d8de7e5 commit 2eca9ad
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ const isMobile = /mobile/i.test(window.navigator.userAgent);
const utils = {

/**
* Parse second to 00:00 format
* Parse second to time string
*
* @param {Number} second
* @return {String} 00:00 format
* @return {String} 00:00 or 00:00:00
*/
secondToTime: (second) => {
const add0 = (num) => num < 10 ? '0' + num : '' + num;
const min = parseInt(second / 60);
const sec = parseInt(second - min * 60);
return add0(min) + ':' + add0(sec);
const hour = Math.floor(second / 3600);
const min = Math.floor((second - hour * 3600) / 60);
const sec = Math.floor(second - hour * 3600 - min * 60);
return (hour > 0 ? [hour, min, sec] : [min, sec]).map(add0).join(':');
},

/**
Expand Down

0 comments on commit 2eca9ad

Please sign in to comment.