[CalendarServer-changes] [6279] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Sep 10 19:06:06 PDT 2010


Revision: 6279
          http://trac.macosforge.org/projects/calendarserver/changeset/6279
Author:   cdaboo at apple.com
Date:     2010-09-10 19:06:05 -0700 (Fri, 10 Sep 2010)
Log Message:
-----------
Fix created/modified value conversions read from sql.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/dateops.py
    CalendarServer/trunk/txdav/caldav/datastore/sql.py
    CalendarServer/trunk/txdav/common/datastore/sql.py

Modified: CalendarServer/trunk/twistedcaldav/dateops.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/dateops.py	2010-09-10 22:49:37 UTC (rev 6278)
+++ CalendarServer/trunk/twistedcaldav/dateops.py	2010-09-11 02:06:05 UTC (rev 6279)
@@ -29,6 +29,7 @@
     "clipPeriod"
 ]
 
+import calendar
 import datetime
 from vobject.icalendar import utc
 
@@ -223,3 +224,11 @@
         else:
             return (start, end)
  
+def datetimeMktime(dt):
+
+    assert isinstance(dt, datetime.date)
+    
+    if dt.tzinfo is None:
+        dt.replace(tzinfo=utc)
+    return calendar.timegm(dt.utctimetuple())
+    
\ No newline at end of file

Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/sql.py	2010-09-10 22:49:37 UTC (rev 6278)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py	2010-09-11 02:06:05 UTC (rev 6279)
@@ -32,7 +32,7 @@
 
 from twistedcaldav import caldavxml, customxml
 from twistedcaldav.caldavxml import ScheduleCalendarTransp, Opaque
-from twistedcaldav.dateops import normalizeForIndex
+from twistedcaldav.dateops import normalizeForIndex, datetimeMktime
 from twistedcaldav.index import IndexedSearchException
 from twistedcaldav.instance import InvalidOverriddenInstanceError
 
@@ -575,15 +575,15 @@
         """
         rows = self._txn.execSQL(
             """
-            select CONTENT_TYPE, SIZE, MD5, extract(EPOCH from CREATED), extract(EPOCH from MODIFIED) from ATTACHMENT where PATH = %s
+            select CONTENT_TYPE, SIZE, MD5, CREATED, MODIFIED from ATTACHMENT where PATH = %s
             """, [self._pathValue()])
         if not rows:
             return False
         self._contentType = MimeType.fromString(rows[0][0])
         self._size = rows[0][1]
         self._md5 = rows[0][2]
-        self._created = int(rows[0][3])
-        self._modified = int(rows[0][4])
+        self._created = datetimeMktime(datetime.datetime.strptime(rows[0][3], "%Y-%m-%d %H:%M:%S.%f"))
+        self._modified = datetimeMktime(datetime.datetime.strptime(rows[0][4], "%Y-%m-%d %H:%M:%S.%f"))
         return True
 
 

Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py	2010-09-10 22:49:37 UTC (rev 6278)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py	2010-09-11 02:06:05 UTC (rev 6279)
@@ -35,6 +35,7 @@
 from twisted.python.util import FancyEqMixin
 
 from twistedcaldav.customxml import NotificationType
+from twistedcaldav.dateops import datetimeMktime
 
 from txdav.common.datastore.sql_legacy import PostgresLegacyNotificationsEmulator
 from txdav.caldav.icalendarstore import ICalendarTransaction, ICalendarStore
@@ -58,6 +59,8 @@
 
 from zope.interface.declarations import implements, directlyProvides
 
+import datetime
+
 v1_schema = getModule(__name__).filePath.sibling(
     "sql_schema_v1.sql").getContent()
 
@@ -799,19 +802,21 @@
 
     def created(self):
         created = self._txn.execSQL(
-            "select extract(EPOCH from %(column_CREATED)s) from %(name)s "
+            "select %(column_CREATED)s from %(name)s "
             "where %(column_RESOURCE_ID)s = %%s" % self._homeChildTable,
             [self._resourceID]
         )[0][0]
-        return int(created)
+        utc = datetime.datetime.strptime(created, "%Y-%m-%d %H:%M:%S.%f")
+        return datetimeMktime(utc)
 
     def modified(self):
         modified = self._txn.execSQL(
-            "select extract(EPOCH from %(column_MODIFIED)s) from %(name)s "
+            "select %(column_MODIFIED)s from %(name)s "
             "where %(column_RESOURCE_ID)s = %%s" % self._homeChildTable,
             [self._resourceID]
         )[0][0]
-        return int(modified)
+        utc = datetime.datetime.strptime(modified, "%Y-%m-%d %H:%M:%S.%f")
+        return datetimeMktime(utc)
 
     def notifierID(self, label="default"):
         if self._notifier:
@@ -903,19 +908,21 @@
 
     def created(self):
         created = self._txn.execSQL(
-            "select extract(EPOCH from %(column_CREATED)s) from %(name)s "
+            "select %(column_CREATED)s from %(name)s "
             "where %(column_RESOURCE_ID)s = %%s" % self._objectTable,
             [self._resourceID]
         )[0][0]
-        return int(created)
+        utc = datetime.datetime.strptime(created, "%Y-%m-%d %H:%M:%S.%f")
+        return datetimeMktime(utc)
 
     def modified(self):
         modified = self._txn.execSQL(
-            "select extract(EPOCH from %(column_MODIFIED)s) from %(name)s "
+            "select %(column_MODIFIED)s from %(name)s "
             "where %(column_RESOURCE_ID)s = %%s" % self._objectTable,
             [self._resourceID]
         )[0][0]
-        return int(modified)
+        utc = datetime.datetime.strptime(modified, "%Y-%m-%d %H:%M:%S.%f")
+        return datetimeMktime(utc)
 
 class NotificationCollection(LoggingMixIn, FancyEqMixin):
 
@@ -1133,16 +1140,18 @@
 
 
     def created(self):
-        modified = self._txn.execSQL(
-            "select extract(EPOCH from CREATED) from NOTIFICATION "
+        created = self._txn.execSQL(
+            "select CREATED from NOTIFICATION "
             "where RESOURCE_ID = %s",
             [self._resourceID]
         )[0][0]
-        return int(modified)
+        utc = datetime.datetime.strptime(created, "%Y-%m-%d %H:%M:%S.%f")
+        return datetimeMktime(utc)
 
     def modified(self):
         modified = self._txn.execSQL(
-            "select extract(EPOCH from MODIFIED) from NOTIFICATION "
+            "select MODIFIED from NOTIFICATION "
             "where RESOURCE_ID = %s", [self._resourceID]
         )[0][0]
-        return int(modified)
+        utc = datetime.datetime.strptime(modified, "%Y-%m-%d %H:%M:%S.%f")
+        return datetimeMktime(utc)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100910/e83c45e6/attachment.html>


More information about the calendarserver-changes mailing list