File tree Expand file tree Collapse file tree 3 files changed +6
-80
lines changed
Expand file tree Collapse file tree 3 files changed +6
-80
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/env python3
22
33from datetime import datetime , timedelta
4+ import human
45import re
56
67FMT = '%Y-%m-%d %H:%M:%S'
@@ -13,7 +14,6 @@ from events import _range
1314from events import _cache_load_url
1415from events import calendars
1516from events import FRESH
16- from events import _duration
1717
1818def _icon (event ):
1919
@@ -175,7 +175,7 @@ for title, events in sections:
175175 hbegin = begin .humanize (),
176176 range = _range ( now , begin , end ) ,
177177 hend = end .humanize ( ) ,
178- hduration = 'lasts ' + _duration ( begin , end ) ,
178+ hduration = 'lasts ' + human . timedelta ( end - begin ) ,
179179 name = name ,
180180 location = location ,
181181 urls = urls
Original file line number Diff line number Diff line change @@ -201,79 +201,3 @@ def event_to_i3_status_object ( now: datetime , event: ics.Event ) :
201201 "full_text" :" {}" .format (full_text ),
202202 "short_text" :" {}" .format (short_text )
203203 }
204-
205-
206- # FORMAT TIME
207-
208- def _humanize (time , ref ):
209-
210- x = time .humanize (ref )
211-
212- if x == "in seconds" :
213-
214- return "in {} seconds" .format ((time - ref ).seconds )
215-
216- if x == "just now" :
217-
218- return "now"
219-
220- return x
221-
222-
223- def _duration (A , B ):
224-
225- x = _humanize (B , A )
226-
227- if x == 'now' :
228-
229- return '{} seconds' .format ((B - A ).seconds )
230-
231- if x == 'in a minute' :
232-
233- return '1 minute'
234-
235- return x [3 :]
236-
237-
238- def _shortduration (A , B ):
239-
240- return _shorten (_duration (A , B ))
241-
242-
243- def _shorthumanize (time , ref ):
244-
245- return _shorten (_humanize (time , ref ))
246-
247- def _tinyduration (A , B ):
248-
249- return _tinier (_duration (A , B ))
250-
251-
252- def _tinyhumanize (time , ref ):
253-
254- return _tinier (_humanize (time , ref ))
255-
256-
257- def _shorten (x ):
258-
259- if 'minutes' in x or 'seconds' in x :
260-
261- return x [:- 4 ]
262-
263- if 'minute' in x :
264-
265- return x [:- 3 ]
266-
267- return x
268-
269- def _tinier (x ):
270-
271- if 'minutes' in x or 'seconds' in x :
272-
273- return x [:- 6 ]
274-
275- if 'minute' in x :
276-
277- return x [:- 5 ]
278-
279- return x
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ def seconds(value: float):
5252 if count == 0 : continue
5353 return _duration (unit , count )
5454
55- return 'now '
55+ return 'instant '
5656
5757def timedelta (delta : dt .timedelta ):
5858 return seconds (delta .total_seconds ())
@@ -64,5 +64,7 @@ def datetime(x: dt.datetime, relative_to: Optional[dt.datetime]=None):
6464 delta = x - relative_to
6565 s = delta .total_seconds ()
6666
67- fmt = '{}' if s == 0 else '{} ago' if s < 0 else 'in {}'
67+ if s == 0 : return 'now'
68+
69+ fmt = '{} ago' if s < 0 else 'in {}'
6870 return fmt .format (seconds (abs (s )))
You can’t perform that action at this time.
0 commit comments