summaryrefslogtreecommitdiffstats
path: root/engagements/utils.py
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-10-07 15:40:13 +0100
committerMatthew Lemon <y@yulqen.org>2024-10-14 14:35:17 +0100
commit46e5ae3428a15980f4721074aef8a499e64c0dcf (patch)
treeeddb5ecc6723c541eae6348e0ce1380670d7f566 /engagements/utils.py
parentf7fd378a421a18026f55f566d2119ba05e41becb (diff)
Nice engagement duration text for summary box on detail page
Diffstat (limited to 'engagements/utils.py')
-rw-r--r--engagements/utils.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/engagements/utils.py b/engagements/utils.py
index 3b414e9..b80e74d 100644
--- a/engagements/utils.py
+++ b/engagements/utils.py
@@ -18,6 +18,20 @@ from instruments.models import Instrument, SubInstrument
from myuser.models import Team, TeamUser
+def duration_formatter(d1: datetime.date, d2: datetime.date) -> str:
+ trip_delta = d2 - d1
+ if trip_delta.days == 0:
+ # this is a single day event
+ return f"{d1.strftime("%d %B %Y")} (1 day)"
+ else:
+ # if months are different...
+ if d1.month != d2.month:
+ # we need to format this differently
+ return f"{d1.strftime("%d %B")} - {d2.strftime("%d %B %Y")} ({trip_delta.days +1} days)"
+ else:
+ return f"{d1.strftime("%d")}-{d2.strftime("%d %B %Y")} ({trip_delta.days + 1} days)"
+
+
def populate_database():
out = defaultdict(list)
fake = Faker(locale="en_GB")