Add humanize_remaining formatter
* Add humanize_remaining formatter
Allows for formating the time remaning to next event in _human readable
format_. Work only if `humanize` module is available.
@@ -8,6 +8,11 @@ from i3pystatus import IntervalModule, formatp, SettingsBase
from i3pystatus.core.color import ColorRangeModule
from i3pystatus.core.desktop import DesktopNotification
+try:
+ import humanize
+except ImportError:
+ pass
+
def strip_microseconds(delta):
return delta - timedelta(microseconds=delta.microseconds)
@@ -50,7 +55,8 @@ class CalendarEvent:
"""
event_dict = dict(
title=self.title,
- remaining=self.time_remaining
+ remaining=self.time_remaining,
+ humanize_remaining=self.humanize_time_remaining,
)
def is_formatter(x):
@@ -64,6 +70,13 @@ class CalendarEvent:
def time_remaining(self):
return strip_microseconds(self.start - datetime.now(tz=self.start.tzinfo))
+ @property
+ def humanize_time_remaining(self):
+ try:
+ return humanize.naturaltime(datetime.now(tz=self.start.tzinfo) - self.start)
+ except NameError:
+ raise ImportError('Missing humanize module')
+
def __str__(self):
return "{}(title='{}', start={}, end={}, recurring={})" \
.format(type(self).__name__,
@@ -112,8 +125,11 @@ class Calendar(IntervalModule, ColorRangeModule):
* {title} - the title or summary of the event
* {remaining_time} - how long until this event is due
+ * {humanize_remaining} - how long until this event is due in human readable format
Additional formatters may be provided by the backend, consult their documentation for details.
+
+ .. note:: Optionally requires `humanize` to display time in human readable format.
"""
settings = (
