diff --git a/apps/upcoming_events/upcoming_events.star b/apps/upcoming_events/upcoming_events.star index 0bd34637cc..f6d226db5c 100644 --- a/apps/upcoming_events/upcoming_events.star +++ b/apps/upcoming_events/upcoming_events.star @@ -24,6 +24,7 @@ def main(config): rep = http.get(url) if rep.status_code != 200: fail("Google Calender request failed with status %d", rep.status_code) + lines = rep.body().split("\n") events = [] @@ -44,13 +45,48 @@ def main(config): if creatingEvent: if line.startswith("SUMMARY:"): - event["name"] = line.split(":")[1] + event["name"] = ":".join(line.split(":")[1:]) if line.startswith("DTSTART:"): timestamp = line.split(":")[1].replace("\x0d", "") dateFormat = "20060102T150405Z" + eventDate = time.parse_time(timestamp, dateFormat, "UTC") + + # For display, convert to local timezone timezone = config.get("timezone") or "America/New_York" + localEventDate = eventDate.in_location(timezone) + + event["date"] = eventDate # Keep as UTC for comparison + event["formattedDate"] = localEventDate.format("01/02") # Display in local timezone + + if line.startswith("DTSTART;VALUE=DATE:"): + dateString = line.split(":")[1].replace("\x0d", "") + + year = int(dateString[0:4]) + month = int(dateString[4:6]) + day = int(dateString[6:8]) + + # For all-day events, create a timestamp at noon local time to avoid timezone issues + timezone = config.get("timezone") or "America/New_York" + + # Create timestamp string manually (avoiding % formatting) + yearStr = str(year) + monthStr = str(month) + dayStr = str(day) + + # Pad with zeros if needed + if len(yearStr) < 4: + yearStr = "0" * (4 - len(yearStr)) + yearStr + if len(monthStr) < 2: + monthStr = "0" + monthStr + if len(dayStr) < 2: + dayStr = "0" + dayStr + + timestamp = yearStr + monthStr + dayStr + "T120000" + + # Parse in local timezone to avoid date shifting + dateFormat = "20060102T150405" eventDate = time.parse_time(timestamp, dateFormat, timezone) event["date"] = eventDate