Index: main/waeup.kofa/trunk/src/waeup/kofa/widgets/datetimewidget.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/widgets/datetimewidget.py	(revision 8198)
+++ main/waeup.kofa/trunk/src/waeup/kofa/widgets/datetimewidget.py	(revision 8198)
@@ -0,0 +1,54 @@
+## $Id$
+##
+## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+"""Datetimewidgets that are compatible with pytz.
+"""
+import datetime
+import pytz
+from zope.formlib.textwidgets import DatetimeWidget
+
+class PytzDatetimeWidget(DatetimeWidget):
+    """pytz-conform, non-ambigous UTC datetimes.
+
+    While the standard formlib datetime widget makes use of
+    zope.datetime and creates also not too reliable (or ambigous)
+    datetimes based on local servertime, this widget provides
+    non-ambigous UTC datetimes with a pytz timezone (pytz.utc).
+
+    Using this widget for datetime data we always get clean UTC
+    datetimes compatible with other Python packages (as pytz is more
+    wide-spread than zope.datetime).
+
+    For datetimes in other timezones we compute the correct UTC value
+    and store this. A way to help making sure, only UTC-based values
+    go into the DB.
+
+    From zope.datetime, however, we save the parser abilities to
+    interpret even bizarre entered data as some datetime.
+    """
+    def _toFieldValue(self, string):
+        """Turn string into a UTC-based datetime.
+
+        The TZ data is guaranteed to be pytz.utc.
+
+        """
+        value = super(PytzDatetimeWidget, self)._toFieldValue(string)
+        if not isinstance(value, datetime.datetime):
+            return value
+        if value.tzinfo is None:
+            return pytz.utc.localize(value)
+        return value.astimezone(pytz.utc)
Index: main/waeup.kofa/trunk/src/waeup/kofa/widgets/tests/test_datetimewidget.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/widgets/tests/test_datetimewidget.py	(revision 8198)
+++ main/waeup.kofa/trunk/src/waeup/kofa/widgets/tests/test_datetimewidget.py	(revision 8198)
@@ -0,0 +1,53 @@
+# Tests for datetimewidgets
+import datetime
+import pytz
+from zope import schema
+from zope.formlib import form
+from zope.formlib.interfaces import IInputWidget, IDisplayWidget
+from zope.formlib.tests.test_functional_textwidget import(
+    FunctionalWidgetTestCase,)
+from zope.formlib.textwidgets import TextWidget
+from zope.interface import Interface, implements
+from zope.interface.verify import verifyClass, verifyObject
+from zope.publisher.browser import TestRequest
+from waeup.kofa.widgets.datetimewidget import PytzDatetimeWidget
+
+class IContent(Interface):
+    my_dt = schema.Datetime(
+        title = u'A datetime.',
+        )
+
+class Content(object):
+    implements(IContent)
+    my_dt = None
+
+class SampleForm(form.EditForm):
+    form_fields = form.fields(IContent)
+    form_fields['my_dt'].custom_widget = PytzDatetimeWidget
+
+class PytzDatetimeWidgetTests(FunctionalWidgetTestCase):
+
+    widgets = [
+        (schema.interfaces.IDatetime, TextWidget),
+        ]
+
+    def test_iface(self):
+        # make sure we fullfill interface contracts
+        obj = PytzDatetimeWidget(IContent['my_dt'], TestRequest())
+        verifyClass(IInputWidget, PytzDatetimeWidget)
+        verifyObject(IInputWidget, obj)
+        return
+
+    def test_to_value(self):
+        # we get always UTC-based values
+        content = Content()
+        request = TestRequest()
+
+        request.form['form.my_dt'] = u'2012-01-02 12:10:19 GMT+1'
+        request.form['form.actions.apply'] = u''
+        SampleForm(content, request)()
+
+        self.assertEqual( content.my_dt, datetime.datetime(
+            2012, 1, 2, 11, 10, 19, tzinfo=pytz.utc))
+        self.assertTrue(content.my_dt.tzinfo is pytz.utc)
+        return
