Refactor timeUntil for negative values.

This commit is contained in:
Michael Friedrich 2014-03-09 22:14:55 +01:00
parent 88859cb838
commit ef73bb13d3
1 changed files with 25 additions and 19 deletions

View File

@ -266,25 +266,31 @@
if (m !== null) { if (m !== null) {
var nm = parseInt(m[1]); var nm = parseInt(m[1]);
var ns = parseInt(m[2]); var ns = parseInt(m[2]);
if (nm > 0) { var signed = '';
if (ns > 0) { var sec = 0;
ns--;
} else if (ns == 0) { if (nm < 0) {
ns = 59; signed = '-';
nm--; nm = nm * -1;
} else { //negative means recalculate against 1m sec = nm * 60 + ns;
ns = (60 - ns - 1); sec++;
nm--; } else if (nm == 0 && ns == 0) {
} signed = '-';
} else if (nm <= 0) { sec = 1;
if (ns == -59) { } else if (nm == 0) {
ns = 0; signed = '-';
nm--; sec = ns;
sec++;
} else { } else {
ns--; signed = '';
sec = nm * 60 + ns;
sec--;
} }
}
$(el).html(nm + 'm ' + ns + 's'); nm = Math.floor(sec/60);
ns = sec - nm * 60;
$(el).html(signed + nm + 'm ' + ns + 's');
} }
}); });
}, },