Skip to content

Commit

Permalink
Fix duration bug on tracks longer than an hour.
Browse files Browse the repository at this point in the history
Previously a duration longer than an hour would result in the minutes
being represented incorrectly e.g 3602 seconds as 1:60:02.
  • Loading branch information
Dan Brook committed Jun 7, 2010
1 parent 0451b41 commit 6479733
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Background Music",
"version": "1.2",
"description": "Listen to some audio in the background.",
"description": "Listen to .mp3s from the web while your browse.",
"browser_action": {
"default_icon": "icons/icon_48.png",
"default_title": "Background Music",
Expand Down
11 changes: 7 additions & 4 deletions popup.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
function durationToString(duration) {
if(!duration)
return '0:00';
return '00:00';

var hr = Math.floor(Number(duration / 3600)).toFixed(0),
min = Math.floor(Number(duration / 60)).toFixed(0),
var hr = Math.floor(Number(duration / 3600)).toFixed(0);
if(duration > 3600)
duration %= 3600;
var min = Math.floor(Number(duration / 60)).toFixed(0),
sec = Math.floor(Number(duration % 60)).toFixed(0);

var hrStr = ( hr >= 1 ? hr + ':' : '' ),
minStr = ( min >= 1 ? (min < 10 ? '0'+min : min) + ':' : '0:' ),
minStr = ( min >= 1 ? (min < 10 ? '0'+min : min) + ':' : '00:' ),
secStr = ( sec >= 1 ? (sec < 10 ? '0'+sec : sec) : '00' );

return hrStr + minStr + secStr;
Expand Down

0 comments on commit 6479733

Please sign in to comment.