diff --git a/memberPlumbing/upcomingEvents.py b/memberPlumbing/upcomingEvents.py index 4ab03ee..0614d23 100644 --- a/memberPlumbing/upcomingEvents.py +++ b/memberPlumbing/upcomingEvents.py @@ -7,6 +7,22 @@ import pyclip from .config import Config +TIME_FMT = "%l:%M%P" +DATETIME_FMT = "%a %b %e %Y, " + TIME_FMT + + +def format_datetime_range(start_ts: int, end_ts: int): + start = datetime.fromtimestamp(start_ts) + end = datetime.fromtimestamp(end_ts) + start_str = start.strftime(DATETIME_FMT) + if start.date() == end.date(): + end_str = end.strftime(TIME_FMT) + else: + # TODO: this probably implies multiple instances. Should read + # RRULE or similar from the event notes + end_str = end.strftime(DATETIME_FMT) + return f"{start_str} — {end_str}" + def format_event(event_details, truncate: bool): try: @@ -22,7 +38,7 @@ def format_event(event_details, truncate: bool): out = f"""

{img}{event_details['ttl']}

-
{event_details['szp']} — {event_details['ezp']}
+
{format_datetime_range(event_details['sdp'], event_details['edp'])}
""" if not truncate: out += f"""