[Jppy-commit] [SCM] jppy - Python bindings and API for jpilot databases and a GTK2 GUI branch, devel-calendar, updated. releases/0.0.48-75-g0f9b2cf
Jon Schewe
jpschewe@mtu.net
Sun Nov 2 18:07:51 GMT 2008
The following commit has been merged in the devel-calendar branch:
commit 3cc6b2f4cceb03e29bd10865ac34f88e47d8cd23
Author: Jon Schewe <jpschewe@mtu.net>
Date: Sun Nov 2 11:45:07 2008 -0600
Convert exceptions to appropriate timezones.
diff --git a/jppy/calendarEvent.py b/jppy/calendarEvent.py
index 73df4e0..1b4ee1e 100644
--- a/jppy/calendarEvent.py
+++ b/jppy/calendarEvent.py
@@ -27,14 +27,19 @@ class calendarEvent(object):
raise NotImplemented("Unable to get %s yet." % key)
elif "begin" == key:
begin = self.internalEvent["begin"]
- if isinstance(begin, datetime.datetime):
- begin = self.convertDatetimeFromPalm(begin)
+ begin = self.convertDatetimeFromPalm(begin)
return begin
elif "end" == key:
end = self.internalEvent["end"]
- if isinstance(end, datetime.datetime):
- end = self.convertDatetimeFromPalm(end)
+ end = self.convertDatetimeFromPalm(end)
return end
+ elif "exceptions" == key:
+ palmExceptions = self.internalEvent["exceptions"]
+ tzExceptions = []
+ for palmException in palmExceptions:
+ tzExceptions.append(self.convertDatetimeFromPalm(palmException))
+ return tzExceptions
+
# @todo need to handle all dates
elif "timezone" == key:
return self.gettimezone()
@@ -50,13 +55,17 @@ class calendarEvent(object):
else:
if "begin" == item or "end" == item:
- if isinstance(value, datetime.datetime):
- value = convertDatetimeToPalm(value)
+ value = convertDatetimeToPalm(value)
+ elif "exceptions" == item:
+ palmExceptions = []
+ for exception in value:
+ palmExceptions.append(self.convertDatetimeToPalm(exception))
+ value = palmExceptions
elif "timezone" == item:
# @todo if the timzone is being set, then change the times in
# the palm object
- # dates to set: begin, end
+ # dates to set: begin, end, exceptions
pass
@@ -69,7 +78,10 @@ class calendarEvent(object):
If this calendar event has a timezone, then apply that timezone to
dt, if not, assume the local timezone.
'''
- return dt.replace(tzinfo=self.gettimezone())
+ if isinstance(dt, datetime.datetime):
+ return dt.replace(tzinfo=self.gettimezone())
+ else:
+ return dt
def convertDatetimeToPalm(self, dt):
'''
@@ -79,11 +91,14 @@ class calendarEvent(object):
calendar event. If this calendar event has no timezone, the local
timezone is assumed.
'''
- if not dt.tzinfo:
- dt.replace(tzinfo=tzlocal())
-
- tz = self.gettimezone()
- return dt.astimezone(tz)
+ if isinstance(dt, datetime.datetime):
+ if not dt.tzinfo:
+ dt.replace(tzinfo=tzlocal())
+
+ tz = self.gettimezone()
+ return dt.astimezone(tz)
+ else:
+ return dt
def gettimezone(self):
'''
diff --git a/python_module_src/pytype_events.c b/python_module_src/pytype_events.c
index 8365405..0493742 100644
--- a/python_module_src/pytype_events.c
+++ b/python_module_src/pytype_events.c
@@ -168,7 +168,6 @@ static void PyPiEvent_Dealloc(PyPiEvent* self) {
static int PyPiEvent_Compare(PyPiEvent* self,PyPiEvent *other) {
time_t s, o;
- /* @todo Need to pay attention to timezones here */
s = mktime(&(self->a.begin));
o = mktime(&(other->a.begin));
@@ -582,8 +581,6 @@ PyObject *PyPiEvent_GetItem(PyPiEvent* self, PyObject* key) {
Py_INCREF(Py_None);
return Py_None;
} else {
- /* FIX need to create palm_timezone class so that conversions to tzinfo can be done in python */
-
/* This creats an extra copy of a.tz in memory, but I don't know a
* better way around it for now */
return PyPiTimezone_Wrap(self->a.tz);
--
jppy - Python bindings and API for jpilot databases and a GTK2 GUI
More information about the Jppy-commit
mailing list