updated calendar widget to show "today" and "tomorrow"
This commit is contained in:
@@ -936,6 +936,20 @@ data:
|
||||
# Calendar configuration - loaded from environment
|
||||
CALENDAR_ICAL_URLS = os.getenv("CALENDAR_ICAL_URLS", "") # JSON: {"name": "url", ...}
|
||||
|
||||
def _format_relative_date(dt: datetime, tz) -> str:
|
||||
"""Format date as 'Today', 'Tomorrow', or 'Mon 24' style."""
|
||||
now = datetime.now(tz)
|
||||
today = now.date()
|
||||
tomorrow = today + timedelta(days=1)
|
||||
event_date = dt.date()
|
||||
|
||||
if event_date == today:
|
||||
return "Today"
|
||||
elif event_date == tomorrow:
|
||||
return "Tomorrow"
|
||||
else:
|
||||
return dt.strftime("%b %d")
|
||||
|
||||
def _parse_ical_urls() -> dict[str, str]:
|
||||
"""Parse CALENDAR_ICAL_URLS environment variable."""
|
||||
if not CALENDAR_ICAL_URLS:
|
||||
@@ -1047,6 +1061,7 @@ data:
|
||||
"start": occ.isoformat(),
|
||||
"start_unix": int(occ.timestamp()),
|
||||
"start_date": occ.strftime("%b %d"),
|
||||
"start_date_relative": _format_relative_date(occ, tz),
|
||||
"start_time": occ.strftime("%H:%M"),
|
||||
"start_weekday": occ.strftime("%a"),
|
||||
"end": occ_end.isoformat() if occ_end else None,
|
||||
@@ -1066,6 +1081,7 @@ data:
|
||||
"start": dtstart_val.isoformat(),
|
||||
"start_unix": int(dtstart_val.timestamp()),
|
||||
"start_date": dtstart_val.strftime("%b %d"),
|
||||
"start_date_relative": _format_relative_date(dtstart_val, tz),
|
||||
"start_time": dtstart_val.strftime("%H:%M"),
|
||||
"start_weekday": dtstart_val.strftime("%a"),
|
||||
"end": dtend_val.isoformat() if dtend_val else None,
|
||||
@@ -1084,6 +1100,7 @@ data:
|
||||
"start": dtstart_val.isoformat(),
|
||||
"start_unix": int(dtstart_val.timestamp()),
|
||||
"start_date": dtstart_val.strftime("%b %d"),
|
||||
"start_date_relative": _format_relative_date(dtstart_val, tz),
|
||||
"start_time": dtstart_val.strftime("%H:%M"),
|
||||
"start_weekday": dtstart_val.strftime("%a"),
|
||||
"end": dtend_val.isoformat() if dtend_val else None,
|
||||
|
||||
Reference in New Issue
Block a user