Skip to content

Instantly share code, notes, and snippets.

@domenkozar
Created October 23, 2012 12:37
Show Gist options
  • Save domenkozar/3938518 to your computer and use it in GitHub Desktop.
Save domenkozar/3938518 to your computer and use it in GitHub Desktop.
Timezone test
import datetime
import icalendar
import pytz
tz = pytz.timezone('Europe/Ljubljana')
dt = datetime.datetime(2012, 10, 23, 14, 0, 0)
print "datetime without timezone information: ", dt
dt_localized = tz.localize(dt)
print "localized into DST Europe/Ljubljana: ", dt_localized
print "Europe/Ljubljana to UTC time: ", dt_localized.astimezone(pytz.utc)
event = icalendar.Event()
event.add('dtstart', dt_localized)
print "icalendat vevent dtstart with localized to Europe/Ljubljana: ", event.to_ical()
@domenkozar
Copy link
Author

Output:

datetime without timezone information: 2012-10-23 14:00:00
localized into DST Europe/Ljubljana: 2012-10-23 14:00:00+02:00
Europe/Ljubljana to UTC time: 2012-10-23 12:00:00+00:00
icalendat vevent dtstart with localized to Europe/Ljubljana: BEGIN:VEVENT
DTSTART;TZID=Europe/Ljubljana;VALUE=DATE-TIME:20121023T140000
END:VEVENT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment