Add ETA and ratio to format util

This commit is contained in:
John Furrow
2015-11-21 23:19:45 -08:00
parent 345825c02c
commit c693370078

View File

@@ -1,7 +1,75 @@
import React from 'react';
const format = {
data: function(bytes, extraUnits, precision) {
eta: function(eta) {
if (eta === 'Infinity') {
return '∞';
} else if (eta.years > 0) {
return (
<span>
<span className="torrent__details--segment">
{eta.years}<em className="unit">yr</em>
</span>
<span className="torrent__details--segment">
{eta.weeks}<em className="unit">wk</em>
</span>
</span>
);
} else if (eta.weeks > 0) {
return (
<span>
<span className="torrent__details--segment">
{eta.weeks}<em className="unit">wk</em>
</span>
<span className="torrent__details--segment">
{eta.days}<em className="unit">d</em>
</span>
</span>
);
} else if (eta.days > 0) {
return (
<span>
<span className="torrent__details--segment">
{eta.days}<em className="unit">d</em>
</span>
<span className="torrent__details--segment">
{eta.hours}<em className="unit">hr</em>
</span>
</span>
);
} else if (eta.hours > 0) {
return (
<span>
<span className="torrent__details--segment">
{eta.hours}<em className="unit">hr</em>
</span>
<span className="torrent__details--segment">
{eta.minutes}<em className="unit">m</em>
</span>
</span>
);
} else if (eta.minutes > 0) {
return (
<span>
<span className="torrent__details--segment">
{eta.minutes}<em className="unit">m</em>
</span>
<span className="torrent__details--segment">
{eta.seconds}<em className="unit">s</em>
</span>
</span>
);
} else {
return (
<span>
{eta.seconds}<em className="unit">s</em>
</span>
);
}
},
data: function(bytes, extraUnits, precision) {
precision = precision || 2;
let kilobyte = 1024,
@@ -36,10 +104,22 @@ const format = {
}
return {
'value': value,
'unit': unit
value,
unit
};
},
ratio: function(ratio) {
ratio = ratio / 1000;
let precision = 1;
if (ratio < 10) {
precision = 2;
} else if (ratio < 100) {
precision = 0;
}
return ratio.toFixed(precision);
}
};