[Zope3-checkins] CVS: Zope3/src/zope/publisher - browser.py:1.7

Tres Seaver tseaver@zope.com
Thu, 13 Feb 2003 00:06:57 -0500


Update of /cvs-repository/Zope3/src/zope/publisher
In directory cvs.zope.org:/tmp/cvs-serv20260/src/zope/publisher

Modified Files:
	browser.py 
Log Message:


  - Make 'field2date' marshaller return a new-style datetime (naive until
    we have infrastructure for looking up 'tzinfo' objects by name);  added
    module for testing marshalling.


=== Zope3/src/zope/publisher/browser.py 1.6 => 1.7 ===
--- Zope3/src/zope/publisher/browser.py:1.6	Tue Feb 11 11:00:08 2003
+++ Zope3/src/zope/publisher/browser.py	Thu Feb 13 00:06:24 2003
@@ -19,7 +19,9 @@
 import re
 from types import ListType, TupleType, StringType, StringTypes
 from cgi import FieldStorage, escape
+from datetime import datetime
 
+from zope.app.datetimeutils import parse as parseDateTime
 from zope.i18n.interfaces import IUserPreferredLanguages
 from zope.i18n.interfaces import IUserPreferredCharsets
 from zope.publisher.interfaces.browser import IBrowserPresentation
@@ -144,10 +146,30 @@
     return field2text(v).split('\n')
 
 def field2date(v):
-    from DateTime import DateTime
-    if hasattr(v,'read'): v=v.read()
-    else: v=str(v)
-    return DateTime(v)
+    if hasattr(v,'read'):
+        v = v.read()
+    else:
+        v = str(v)
+
+    # *Don't* force a timezone if not passed explicitly;  leave it as
+    # "naive" datetime.
+    year, month, day, hour, minute, second, tzname = parseDateTime(v, local=0)
+
+    # TODO:  look up a real tzinfo object using 'tzname'
+    #
+    # Option 1:  Use 'timezones' module as global registry::
+    #
+    #   from zope.app.timezones import getTimezoneInfo
+    #   tzinfo = getTimezoneInfo(tzname)
+    #
+    # Option 2:  Use a utility.
+    #
+    #   tz_lookup = getUtility(None, ITimezoneLookup)
+    #   tzinfo = tz_lookup(tzname)
+    #
+    return datetime(year, month, day, hour, minute, second,
+                  # tzinfo=tzinfo
+                   )
 
 def field2boolean(v):
     return v