I've added validation to the calendar.ics file parsing, as well as
rewritten the add_time() function to work correctly with months of
different length and leap years fixing this time validation bug.
-Kacper
diff -Nur gdeskcal-0.57.1/code/planner/cal/Date.py gdeskcal-0.57.2-kw/code/planner/cal/Date.py
--- gdeskcal-0.57.1/code/planner/cal/Date.py 2004-03-15 23:46:05.000000000 +0100
+++ gdeskcal-0.57.2-kw/code/planner/cal/Date.py 2006-05-09 01:13:39.913505056 +0200
@@ -1,5 +1,6 @@
import time
import calendar
+from datetime import datetime,timedelta
@@ -23,6 +24,13 @@
if (is_utc): self.__utc_to_localtime()
+ # Validate the time
+ try:
+ sttime = self._to_time()
+ except ValueError:
+ print "********* Date.__init__() ERROR: This date does not exist: %s %s %s %s:%s:%s" % (year, month, day, hours, mins, secs)
+
+
def __cmp__(self, other):
@@ -98,52 +106,22 @@
#
def add_time(self, dyear, dmonth, dday, dhour = 0, dmin = 0, dsec = 0):
- current_time = self._to_time()
- year = current_time[0]
- month = current_time[1]
- day = current_time[2]
- julian_day = current_time[7]
-
- if (calendar.isleap(year)): ndays = 366
- else: ndays = 365
-
-
- julian_day += dday
- while (julian_day > ndays):
- julian_day -= ndays
- year += 1
- while (julian_day < 1):
- julian_day += ndays
- year -= 1
-
- month += dmonth
- while (month > 12):
- month -= 12
- year += 1
- while (month < 1):
- month += 12
- year -= 1
-
- year += dyear
-
-
- if (dday):
- t = time.strptime("%(year)d %(julian_day)d" % vars(),
- "%Y %j")
- elif (dyear):
- t = time.strptime("%(year)d %(month)d %(day)d" % vars(),
- "%Y %m %d")
-
- else:
- t = time.strptime("%(year)d %(month)d %(day)d" % vars(),
- "%Y %m %d")
- #t = time.strptime("%(year)d %(month)d %(julian_day)d" % vars(),
- # "%Y %m %j")
+ old_time = self._to_time()
+ dt_current_time = datetime.fromtimestamp(time.mktime(old_time))
+ delta = timedelta(dday, 0, 0, 0, 0, 0, dmonth * 4 + dyear * 52 )
- self.__year = t[0]
+ dt_current_time = dt_current_time + delta
+
+ t = dt_current_time.timetuple()
+
+ self.__year = t[0]
self.__month = t[1]
- self.__day = t[2]
+ self.__day = t[2]
+ self.__hours = t[3]
+ self.__mins = t[4]
+ self.__secs = t[5]
+ # add any hours, minutes or seconds separately. Why? -KW
if (dhour or dmin or dsec): self.__add_daytime(dhour, dmin, dsec)
@@ -180,8 +158,6 @@
self.__mins = cm
self.__secs = cs
-
-
#
# Returns the time interval to another date in seconds.
#
diff -Nur gdeskcal-0.57.1/code/planner/iCalLoader.py gdeskcal-0.57.2-kw/code/planner/iCalLoader.py
--- gdeskcal-0.57.1/code/planner/iCalLoader.py 2004-03-15 23:46:05.000000000 +0100
+++ gdeskcal-0.57.2-kw/code/planner/iCalLoader.py 2006-05-03 20:42:44.513923200 +0200
@@ -216,8 +216,8 @@
self.__objects[-1].add_event(event)
self.__objects.append(event)
- rrule = event.get_recurrences()
- event.set_recurrences(rrule)
+ rrule = event.get_recurrences()
+ # event.set_recurrences(rrule)
while (1):
l = lines.pop()