When you pass Python datetime objects to ics.py, it preserves the timezone information.
- Naïve datetimes: If you pass a datetime with
tzinfo=None, the event is considered "floating" (interpreted as local time). - Aware datetimes: If you pass a datetime with a timezone (e.g., from
dateutil.tz or pytz), ics.py embeds a full VTIMEZONE specification in the serialized .ics file. This ensures the timezone can be reconstructed exactly on any system, even without an IANA database. - DTSTAMP: Every event includes a
dtstamp field representing when the ics representation was created. ics.py ensures this is always an UTC timestamp per RFC standards.
To check if a datetime is in UTC, use the is_utc() function instead of direct equality comparison, as it correctly handles various library implementations (like datetime, dateutil, and pytz).
from datetime import datetime as dt
from ics import Event
from ics.timezone import is_utc
t = dt(2020, 4, 1, 18, 0)
e = Event(begin=t, uid="test", dtstamp=t)
# Checking for UTC
print(is_utc(e.dtstamp))