2014-11-08 16:13:00 +01:00
|
|
|
/*
|
|
|
|
* JS counterpart of the function in src/misc.cpp
|
|
|
|
*/
|
|
|
|
function friendlyUnit(value, isSpeed) {
|
2014-11-30 14:14:09 +01:00
|
|
|
units = [
|
2014-12-17 14:58:32 +03:00
|
|
|
"QBT_TR(B)QBT_TR",
|
|
|
|
"QBT_TR(KiB)QBT_TR",
|
|
|
|
"QBT_TR(MiB)QBT_TR",
|
|
|
|
"QBT_TR(GiB)QBT_TR",
|
|
|
|
"QBT_TR(TiB)QBT_TR",
|
2014-11-30 14:14:09 +01:00
|
|
|
];
|
2014-11-08 16:13:00 +01:00
|
|
|
|
2014-11-30 14:14:09 +01:00
|
|
|
if (value < 0)
|
2014-12-17 14:58:32 +03:00
|
|
|
return "QBT_TR(Unknown)QBT_TR";
|
2014-11-30 14:14:09 +01:00
|
|
|
var i = 0;
|
|
|
|
while (value >= 1024. && i++ < 6)
|
|
|
|
value /= 1024.;
|
|
|
|
var ret;
|
|
|
|
ret = value.toFixed(1) + " " + units[i];
|
|
|
|
if (isSpeed)
|
2014-12-17 14:58:32 +03:00
|
|
|
ret += "QBT_TR(/s)QBT_TR";
|
2014-11-30 14:14:09 +01:00
|
|
|
return ret;
|
2014-11-08 16:13:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* JS counterpart of the function in src/misc.cpp
|
|
|
|
*/
|
|
|
|
function friendlyDuration(seconds) {
|
2014-11-30 14:14:09 +01:00
|
|
|
var MAX_ETA = 8640000;
|
|
|
|
if (seconds < 0 || seconds >= MAX_ETA)
|
|
|
|
return "∞";
|
|
|
|
if (seconds == 0)
|
|
|
|
return "0";
|
|
|
|
if (seconds < 60)
|
2014-12-17 15:12:11 +03:00
|
|
|
return "QBT_TR(< 1m)QBT_TR";
|
2014-11-30 14:14:09 +01:00
|
|
|
var minutes = seconds / 60;
|
|
|
|
if (minutes < 60)
|
2014-12-17 14:58:32 +03:00
|
|
|
return "QBT_TR(%1m)QBT_TR".replace("%1", parseInt(minutes));
|
2014-11-30 14:14:09 +01:00
|
|
|
var hours = minutes / 60;
|
|
|
|
minutes = minutes - hours * 60;
|
|
|
|
if (hours < 24)
|
2014-12-17 14:58:32 +03:00
|
|
|
return "QBT_TR(%1h %2m)QBT_TR".replace("%1", parseInt(hours)).replace("%2", parseInt(minutes))
|
2014-11-30 14:14:09 +01:00
|
|
|
var days = hours / 24;
|
|
|
|
hours = hours - days * 24;
|
|
|
|
if (days < 100)
|
2014-12-17 14:58:32 +03:00
|
|
|
return "QBT_TR(%1d %2h)QBT_TR".replace("%1", parseInt(days)).replace("%2", parseInt(hours))
|
2014-11-08 16:13:00 +01:00
|
|
|
return "∞";
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* From: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
|
|
|
|
*/
|
|
|
|
if (!Date.prototype.toISOString) {
|
2014-11-30 14:14:09 +01:00
|
|
|
(function() {
|
2014-11-08 16:13:00 +01:00
|
|
|
|
2014-11-30 14:14:09 +01:00
|
|
|
function pad(number) {
|
|
|
|
if (number < 10) {
|
|
|
|
return '0' + number;
|
|
|
|
}
|
|
|
|
return number;
|
|
|
|
}
|
2014-11-08 16:13:00 +01:00
|
|
|
|
2014-11-30 14:14:09 +01:00
|
|
|
Date.prototype.toISOString = function() {
|
|
|
|
return this.getUTCFullYear() +
|
|
|
|
'-' + pad(this.getUTCMonth() + 1) +
|
|
|
|
'-' + pad(this.getUTCDate()) +
|
|
|
|
'T' + pad(this.getUTCHours()) +
|
|
|
|
':' + pad(this.getUTCMinutes()) +
|
|
|
|
':' + pad(this.getUTCSeconds()) +
|
|
|
|
'.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) +
|
|
|
|
'Z';
|
|
|
|
};
|
2014-11-08 16:13:00 +01:00
|
|
|
|
2014-11-30 14:14:09 +01:00
|
|
|
}());
|
2014-12-17 15:12:11 +03:00
|
|
|
}
|