[Checkins] SVN: zope.webdav/trunk/src/zope/webdav/ Use utility
methods from zope.datetime and datetime itself in order to
Michael Kerrin
michael.kerrin at openapp.biz
Tue Feb 13 14:44:05 EST 2007
Log message for revision 72547:
Use utility methods from zope.datetime and datetime itself in order to
avoid handling dates incorrectly.
Changed:
U zope.webdav/trunk/src/zope/webdav/configure.zcml
U zope.webdav/trunk/src/zope/webdav/tests/test_widgets.py
U zope.webdav/trunk/src/zope/webdav/widgets.py
-=-
Modified: zope.webdav/trunk/src/zope/webdav/configure.zcml
===================================================================
--- zope.webdav/trunk/src/zope/webdav/configure.zcml 2007-02-13 19:43:59 UTC (rev 72546)
+++ zope.webdav/trunk/src/zope/webdav/configure.zcml 2007-02-13 19:44:05 UTC (rev 72547)
@@ -93,7 +93,7 @@
<adapter
for="zope.schema.interfaces.IDate
.interfaces.IWebDAVRequest"
- factory=".widgets.DatetimeDAVWidget"
+ factory=".widgets.DateDAVWidget"
/>
<adapter
Modified: zope.webdav/trunk/src/zope/webdav/tests/test_widgets.py
===================================================================
--- zope.webdav/trunk/src/zope/webdav/tests/test_widgets.py 2007-02-13 19:43:59 UTC (rev 72546)
+++ zope.webdav/trunk/src/zope/webdav/tests/test_widgets.py 2007-02-13 19:44:05 UTC (rev 72547)
@@ -187,7 +187,7 @@
_FieldFactory = schema.Datetime
_WidgetFactory = widgets.DatetimeDAVWidget
- rendered_content = u"Wed, 24 May 2006 00:00:58 +0100"
+ rendered_content = u"Tue, 23 May 2006 23:00:58 GMT"
field_content = datetime.datetime(2006, 5, 24, 0, 0, 58,
tzinfo = tzinfo(60))
@@ -196,30 +196,52 @@
self.setUpContent()
-class DateWebDAVWidgetTest(DatetimeWebDAVWidgetTest):
+class DatetimeWebDAVWidgetNoTZInfoTest(WebDAVWidgetTest):
- _FieldFactory = schema.Date
+ _FieldFactory = schema.Datetime
_WidgetFactory = widgets.DatetimeDAVWidget
- field_content = datetime.date(2006, 5, 24)
- rendered_content = u"Wed, 24 May 2006 00:00:00"
+ rendered_content = u"Wed, 24 May 2006 00:00:58 GMT"
+ field_content = datetime.datetime(2006, 5, 24, 0, 0, 58)
+ def setUp(self):
+ super(DatetimeWebDAVWidgetNoTZInfoTest, self).setUp()
+ self.setUpContent()
+
class ISO8601DatetimeWebDAVWidgetTest(DatetimeWebDAVWidgetTest):
- _FieldFactory = schema.Datetime
_WidgetFactory = widgets.ISO8601DatetimeDAVWidget
+ rendered_content = u"2006-05-24T00:00:58+01:00"
+
+
+class ISO8601DatetimeWebDAVWidgetNoTZInfoTest(DatetimeWebDAVWidgetNoTZInfoTest):
+
+ _WidgetFactory = widgets.ISO8601DatetimeDAVWidget
+
rendered_content = u"2006-05-24T00:00:58Z"
-class ISO8601DateWebDAVWidgetTest(DatetimeWebDAVWidgetTest):
+class DateWebDAVWidgetTest(WebDAVWidgetTest):
_FieldFactory = schema.Date
+ _WidgetFactory = widgets.DateDAVWidget
+
+ field_content = datetime.date(2006, 5, 23)
+ rendered_content = u"Tue, 23 May 2006 00:00:00 GMT"
+
+ def setUp(self):
+ super(DateWebDAVWidgetTest, self).setUp()
+ self.setUpContent()
+
+
+class ISO8601DateWebDAVWidgetTest(DateWebDAVWidgetTest):
+
_WidgetFactory = widgets.ISO8601DatetimeDAVWidget
- field_content = datetime.date(2006, 5, 24)
- rendered_content = u"2006-05-24T00:00:00Z"
+ field_content = datetime.date(2006, 5, 23)
+ rendered_content = u"2006-05-23"
class ListWebDAVWidgetTest(WebDAVWidgetTest):
@@ -327,8 +349,10 @@
unittest.makeSuite(IntWebDAVWidgetTest),
unittest.makeSuite(FloatWebDAVWidgetTest),
unittest.makeSuite(DatetimeWebDAVWidgetTest),
+ unittest.makeSuite(DatetimeWebDAVWidgetNoTZInfoTest),
unittest.makeSuite(DateWebDAVWidgetTest),
unittest.makeSuite(ISO8601DatetimeWebDAVWidgetTest),
+ unittest.makeSuite(ISO8601DatetimeWebDAVWidgetNoTZInfoTest),
unittest.makeSuite(ISO8601DateWebDAVWidgetTest),
unittest.makeSuite(ListWebDAVWidgetTest),
unittest.makeSuite(ListTextWebDAVWidgetTest),
Modified: zope.webdav/trunk/src/zope/webdav/widgets.py
===================================================================
--- zope.webdav/trunk/src/zope/webdav/widgets.py 2007-02-13 19:43:59 UTC (rev 72546)
+++ zope.webdav/trunk/src/zope/webdav/widgets.py 2007-02-13 19:44:05 UTC (rev 72547)
@@ -15,6 +15,9 @@
"""
__docformat__ = 'restructuredtext'
+import datetime
+import calendar
+
from zope import component
from zope import interface
from zope.schema import getFieldsInOrder
@@ -92,9 +95,21 @@
if value is None:
return None
- return value.strftime("%a, %d %b %Y %H:%M:%S %z").strip()
+ return zope.datetime.rfc1123_date(calendar.timegm(value.utctimetuple()))
+class DateDAVWidget(DAVWidget):
+ """Same widget can be used for a date field also."""
+ interface.classProvides(interfaces.IIDAVWidget)
+
+ def toDAVValue(self, value):
+ # datetime object
+ if value is None:
+ return None
+
+ return zope.datetime.rfc1123_date(calendar.timegm(value.timetuple()))
+
+
class ISO8601DatetimeDAVWidget(DAVWidget):
"""Same widget can be used for a date field also."""
interface.classProvides(interfaces.IIDAVWidget)
@@ -103,7 +118,9 @@
if value is None:
return None
- return value.strftime('%Y-%m-%dT%TZ')
+ if isinstance(value, datetime.datetime) and value.utcoffset() is None:
+ return value.isoformat() + "Z"
+ return value.isoformat()
class ObjectDAVWidget(DAVWidget):
More information about the Checkins
mailing list