fix Ox.parseDuration for cases where duration includes days

This commit is contained in:
rlx 2013-08-01 08:55:14 +00:00
parent 687158c3fa
commit df1bb73364

View file

@ -110,8 +110,8 @@ Ox.pad = function(string, position, length, padding) {
/*@ /*@
Ox.parseDuration <f> Takes a formatted duration, returns seconds Ox.parseDuration <f> Takes a formatted duration, returns seconds
> Ox.parseDuration('01:02:03.04') > Ox.parseDuration('1:02:03:04.05')
3723.04 93784.05
> Ox.parseDuration('3') > Ox.parseDuration('3')
3 3
> Ox.parseDuration('2:') > Ox.parseDuration('2:')
@ -120,8 +120,8 @@ Ox.parseDuration <f> Takes a formatted duration, returns seconds
3600 3600
@*/ @*/
Ox.parseDuration = function(string) { Ox.parseDuration = function(string) {
return string.split(':').reverse().slice(0, 3).reduce(function(p, c, i) { return string.split(':').reverse().slice(0, 4).reduce(function(p, c, i) {
return p + (parseFloat(c) || 0) * Math.pow(60, i); return p + (parseFloat(c) || 0) * (i == 3 ? 86400 : Math.pow(60, i));
}, 0); }, 0);
}; };