Skip to content

Commit 6d69fd7

Browse files
🩹 fix(menu.recoll): Fix date display and drop arrow.
1 parent 6fd6ae8 commit 6d69fd7

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

.bin/human.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import datetime as dt
2+
from typing import Optional
13

24
def bytes(size):
35

@@ -15,3 +17,52 @@ def bytes(size):
1517
size /= HUMANRADIX
1618

1719
return HUMANFMT.format(size, UNITS[-1])
20+
21+
def _seconds(s: float):
22+
seconds = int(s)
23+
yield 'seconds', seconds
24+
25+
minutes = seconds // 60
26+
yield 'minutes', minutes
27+
28+
hours = minutes // 60
29+
yield 'hours', hours
30+
31+
days = hours // 24
32+
yield 'days', days
33+
34+
weeks = days // 7
35+
yield 'weeks', weeks
36+
37+
months = days // 30
38+
yield 'months', months
39+
40+
years = days // 365
41+
yield 'years', years
42+
43+
44+
def _duration(unit: str, count: int):
45+
return '{count} {unit}'.format(
46+
count=count,
47+
unit=unit if abs(count) > 1 else unit[:-1]
48+
)
49+
50+
def seconds(value: float):
51+
for unit, count in list(_seconds(value))[::-1]:
52+
if count == 0: continue
53+
return _duration(unit, count)
54+
55+
return 'now'
56+
57+
def timedelta(delta: dt.timedelta):
58+
return seconds(delta.total_seconds())
59+
60+
def datetime(x: dt.datetime, relative_to: Optional[dt.datetime]=None):
61+
if relative_to is None:
62+
relative_to = dt.datetime.now(x.tzinfo)
63+
64+
delta = x - relative_to
65+
s = delta.total_seconds()
66+
67+
suffix = '' if s == 0 else ' ago' if s < 0 else ' from now'
68+
return seconds(abs(s)) + suffix

.bin/librecoll.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import arrow
2-
import human
3-
humanbytes = human.bytes
1+
from datetime import datetime
2+
from human import bytes as humanbytes, datetime as humandatetime
43

54
def formatdoc(doc):
65

@@ -32,9 +31,9 @@ def formatkeys(doc):
3231
hint = '/'.join(map(lambda x : x[:2], path.split('/')[3:-1]))
3332

3433
try:
35-
timestamp = arrow.get(doc.mtime)
36-
htime = timestamp.humanize()
37-
hdate = timestamp.format('YYYY-MM-DDTHH:mm:ssZZ')
34+
timestamp = datetime.fromtimestamp(int(doc.mtime))
35+
htime = humandatetime(timestamp)
36+
hdate = timestamp.isoformat()
3837
except Exception:
3938
htime = 'unknown'
4039
hdate = 'unknown'

0 commit comments

Comments
 (0)