Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion apps/upcoming_events/upcoming_events.star
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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
Expand Down