improve shumantime + use it everywhere

This commit is contained in:
ed 2022-07-27 15:07:04 +02:00
parent e24ffebfc8
commit 77f624b01e
3 changed files with 13 additions and 10 deletions

View file

@ -231,7 +231,9 @@ class Up2k(object):
"hashq": self.n_hashq,
"tagq": self.n_tagq,
"mtpq": mtpq,
"dbwt": min(1000 * 24 * 60 * 60 - 1, int(time.time() - self.db_act)),
"dbwt": "{:.2f}".format(
min(1000 * 24 * 60 * 60 - 1, time.time() - self.db_act)
),
}
return json.dumps(ret, indent=4)

View file

@ -679,8 +679,8 @@ function Donut(uc, st) {
}
if (++r.tc >= 10) {
wintitle("{0}%, {1}s, #{2}, ".format(
f2f(v * 100 / t, 1), r.eta, st.files.length - st.nfile.upload), true);
wintitle("{0}%, {1}, #{2}, ".format(
f2f(v * 100 / t, 1), shumantime(r.eta), st.files.length - st.nfile.upload), true);
r.tc = 0;
}

View file

@ -642,7 +642,7 @@ function humansize(b, terse) {
function humantime(v) {
if (v >= 60 * 60 * 24)
return v;
return shumantime(v);
try {
return /.*(..:..:..).*/.exec(new Date(v * 1000).toUTCString())[1];
@ -660,17 +660,18 @@ function shumantime(v) {
return f2f(v, 1) + 's';
v = parseInt(v);
var st = [[60 * 60 * 24, 'd'], [60 * 60, 'h'], [60, 'm']];
var st = [[60 * 60 * 24, 60 * 60, 'd'], [60 * 60, 60, 'h'], [60, 1, 'm']];
for (var a = 0; a < st.length; a++) {
var mod = st[a][0],
ch = st[a][1];
var m1 = st[a][0],
m2 = st[a][1],
ch = st[a][2];
if (v < mod)
if (v < m1)
continue;
var v1 = parseInt(v / mod),
v2 = ('0' + parseInt(v % mod)).slice(-2);
var v1 = parseInt(v / m1),
v2 = ('0' + parseInt((v % m1) / m2)).slice(-2);
return v1 + ch + (v1 >= 10 ? '' : v2);
}