Improve duration display
This commit is contained in:
parent
dd59c809e1
commit
3ec7f5c18a
|
@ -268,6 +268,26 @@ class Event:
|
||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def display_duration(self) -> str | None:
|
||||||
|
"""Duration for display."""
|
||||||
|
if self.end_as_date != self.as_date or not self.has_time:
|
||||||
|
return None
|
||||||
|
|
||||||
|
assert isinstance(self.date, datetime.datetime)
|
||||||
|
assert isinstance(self.end_date, datetime.datetime)
|
||||||
|
|
||||||
|
secs: int = int((self.end_date - self.date).total_seconds())
|
||||||
|
|
||||||
|
hours: int = secs // 3600
|
||||||
|
mins: int = (secs % 3600) // 60
|
||||||
|
|
||||||
|
if mins == 0:
|
||||||
|
return f"{hours:d}h"
|
||||||
|
if hours == 0:
|
||||||
|
return f"{mins:d} mins"
|
||||||
|
|
||||||
|
return f"{hours:d}h {mins:02d} mins"
|
||||||
|
|
||||||
def delta_days(self, today: datetime.date) -> str:
|
def delta_days(self, today: datetime.date) -> str:
|
||||||
"""Return number of days from today as a string."""
|
"""Return number of days from today as a string."""
|
||||||
delta = (self.as_date - today).days
|
delta = (self.as_date - today).days
|
||||||
|
|
|
@ -174,9 +174,10 @@
|
||||||
|
|
||||||
<div class="col-md-2{{ cell_bg }}">
|
<div class="col-md-2{{ cell_bg }}">
|
||||||
{% if event.end_date %}
|
{% if event.end_date %}
|
||||||
{% if event.end_as_date == event.as_date and event.has_time %}
|
{% set duration = event.display_duration() %}
|
||||||
|
{% if duration %}
|
||||||
end: {{event.end_date.strftime("%H:%M") }}
|
end: {{event.end_date.strftime("%H:%M") }}
|
||||||
(duration: {{event.end_date - event.date}})
|
(duration: {{duration}})
|
||||||
{% elif event.end_date != event.date %}
|
{% elif event.end_date != event.date %}
|
||||||
{{event.end_date}}
|
{{event.end_date}}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue