Skip to content
Snippets Groups Projects
Commit 23d81356 authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

AKModel: Improve AK Slot time helper methods

Use more pythonic way to calculate times and construct strings
parent f8bc6d8e
No related branches found
No related tags found
No related merge requests found
...@@ -341,9 +341,8 @@ class AKSlot(models.Model): ...@@ -341,9 +341,8 @@ class AKSlot(models.Model):
""" """
Display duration of slot in format hours:minutes, e.g. 1.5 -> "1:30" Display duration of slot in format hours:minutes, e.g. 1.5 -> "1:30"
""" """
hours = int(self.duration) hours, minutes = divmod(self.duration * 60, 60)
minutes = (self.duration * 60) % 60 return f"{hours}:{minutes:2.0f}"
return '%d:%02d' % (hours, minutes)
@property @property
def start_simplified(self): def start_simplified(self):
...@@ -361,13 +360,11 @@ class AKSlot(models.Model): ...@@ -361,13 +360,11 @@ class AKSlot(models.Model):
""" """
if self.start is None: if self.start is None:
return _("Not scheduled yet") return _("Not scheduled yet")
result = self.start.astimezone(self.event.timezone).strftime('%a %H:%M')
result += ' - ' start = self.start.astimezone(self.event.timezone)
if self.start.astimezone(self.event.timezone).day == self.end.astimezone(self.event.timezone).day: end = self.end.astimezone(self.event.timezone)
result += self.end.astimezone(self.event.timezone).strftime('%H:%M')
else: return f"{start.strftime('%a %H:%M')} - {end.strftime('%H:%M') if start.day == end.day else end.strftime('%a %H:%M')}"
result += self.end.astimezone(self.event.timezone).strftime('%a %H:%M')
return result
@property @property
def end(self): def end(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment