summaryrefslogtreecommitdiff
blob: 7f06b4f68c9e151fdfca5e8aae88affa077f5635 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
From http://codespeak.net/pipermail/icalendar-dev/2009-July/000139.html:

SUMMARY: The encoding mechanism of vDatetime handles tzinfo fields
incorrectly (specifically with respect to daylight savings time).
Attached is a simple patch that makes it work.

DETAILS: Currently vDatetime.ical() tries to compute the utcoffset of
the tzinfo, and then subtract that offset.  This approach is valid,
but the computation of the utcoffset is wrong, because it's done relative
to datetime.now() instead of the actual datetime object (self.dt)
to be converted.  This is an issue for timezones whose utcoffset varies
throughout the year, e.g., from daylight savings time.
Replacing datetime.now() with self.dt would fix the code,
but I opted to use the builtin 'asttimezone' method
because it's slightly simpler.

Submitted by Erik Demaine.
===================================================================
--- src/icalendar/prop.py.orig	2009-12-14 08:43:50.000000000 -0500
+++ src/icalendar/prop.py	2009-12-20 12:41:28.000000000 -0500
@@ -309,8 +309,7 @@
 
     def ical(self):
         if self.dt.tzinfo:
-            utc_time = self.dt - self.dt.tzinfo.utcoffset(datetime.now())
-            return utc_time.strftime("%Y%m%dT%H%M%SZ")
+            return self.dt.astimezone (UTC).strftime("%Y%m%dT%H%M%SZ")
         return self.dt.strftime("%Y%m%dT%H%M%S")
 
     def from_ical(ical):