upcomingEvents: Use cleaner datetime format
This commit is contained in:
parent
8b845bab05
commit
79678a8920
@ -7,6 +7,22 @@ import pyclip
|
|||||||
|
|
||||||
from .config import Config
|
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):
|
def format_event(event_details, truncate: bool):
|
||||||
try:
|
try:
|
||||||
@ -22,7 +38,7 @@ def format_event(event_details, truncate: bool):
|
|||||||
out = f"""<h2 style="text-align: center;">
|
out = f"""<h2 style="text-align: center;">
|
||||||
<a href="{url}">{img}{event_details['ttl']}</a>
|
<a href="{url}">{img}{event_details['ttl']}</a>
|
||||||
</h2>
|
</h2>
|
||||||
<div><i>{event_details['szp']} — {event_details['ezp']}</i></div>
|
<div><i>{format_datetime_range(event_details['sdp'], event_details['edp'])}</i></div>
|
||||||
"""
|
"""
|
||||||
if not truncate:
|
if not truncate:
|
||||||
out += f"""
|
out += f"""
|
||||||
|
Reference in New Issue
Block a user