fix up userOnlineFor function

This commit is contained in:
Natsumi
2020-12-18 06:42:57 +13:00
committed by pypy
parent 74fa583b99
commit 8cd81221ad
2 changed files with 7 additions and 34 deletions

View File

@@ -7600,42 +7600,13 @@ import gameLogService from './service/gamelog.js'
});
};
$app.methods.onlineFor = function (ctx) {
var timeToText = function (sec) {
var n = Number(sec);
if (isNaN(n)) {
return escapeTag(sec);
}
n = Math.floor(n / 1000);
var arr = [];
if (n < 0) {
n = -n;
}
if (n >= 86400) {
arr.push(`${Math.floor(n / 86400)}d`);
n %= 86400;
}
if (n >= 3600) {
arr.push(`${Math.floor(n / 3600)}h`);
n %= 3600;
}
if (n >= 60) {
arr.push(`${Math.floor(n / 60)}m`);
n %= 60;
}
if (n ||
arr.length === 0) {
arr.push(`${n}s`);
}
return arr.join(' ');
};
$app.methods.userOnlineFor = function (ctx) {
if (ctx.ref.state === 'online') {
return timeToText(Date.now() - ctx.ref.$online_for)
return ctx.ref.$online_for;
} else if (ctx.ref.$offline_for) {
return timeToText(Date.now() - ctx.ref.$offline_for)
return ctx.ref.$offline_for;
} else {
return '-';
return false;
}
};