Last active
August 26, 2019 18:38
-
-
Save Pustur/9b867bb2934803b4ff2314c0d2e21c79 to your computer and use it in GitHub Desktop.
Revisions
-
Pustur revised this gist
Aug 26, 2019 . 1 changed file with 22 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,23 +1,26 @@ function timestampToString(timestamp, useMilliseconds) { const periods = { day: 86400000, hour: 3600000, minute: 60000, second: 1000, millisecond: 1, }; if (!useMilliseconds) { timestamp *= 1000; delete periods.millisecond; } return Object.entries(periods) .reduce((result, [period, value]) => { const num = Math.floor(timestamp / value); const plural = num === 1 ? '' : 's'; const str = `${num} ${period}${plural} `; timestamp -= num * value; return `${result}${num === 0 ? '' : str}`; }, '') .trim(); } -
Loris Bettazza renamed this gist
Jun 19, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Loris Bettazza revised this gist
Apr 26, 2016 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,15 +6,14 @@ function timestamp2string(timestamp, useMilliseconds) { minute: 60000, second: 1000, millisecond: 1 }; if (!useMilliseconds) { timestamp *= 1000; delete periods.millisecond; } for (var period in periods) { var number = Math.floor(timestamp / periods[period]); timestamp -= (number * periods[period]); string += (number !== 0 ? number + ' ' + period + ((number !== 1) ? 's' : '') + ' ' : ''); -
Loris Bettazza created this gist
Apr 26, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ function timestamp2string(timestamp, useMilliseconds) { var string = '', periods = { day: 86400000, hour: 3600000, minute: 60000, second: 1000, millisecond: 1 }, period; if (!useMilliseconds) { timestamp *= 1000; delete periods.millisecond; } for (period in periods) { var number = Math.floor(timestamp / periods[period]); timestamp -= (number * periods[period]); string += (number !== 0 ? number + ' ' + period + ((number !== 1) ? 's' : '') + ' ' : ''); } return string.trim(); }