Add localized formatting for multi-day event durations

This commit introduces a feature to format the names of multi-day events using Arrow's localization. Event titles now include the event duration in days.
This commit is contained in:
mygrexit 2023-11-10 13:39:08 +01:00 committed by GitHub
parent 2b2eca2271
commit d79c65cdd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -355,7 +355,13 @@ class Calendar(inkycal_module):
cursor = 0
for event in upcoming_events:
if cursor < len(event_lines):
the_name = event['title']
event_duration = (event['end'] - event['begin']).days
if event_duration > 1:
# Format the duration using Arrow's localization
days_translation = arrow.get().shift(days=event_duration).humanize(only_distance=True, locale=lang)
the_name = f"{event['title']} ({days_translation})"
else:
the_name = event['title']
the_date = event['begin'].format(self.date_format, locale=lang)
the_time = event['begin'].format(self.time_format, locale=lang)
# logger.debug(f"name:{the_name} date:{the_date} time:{the_time}")