SVN: CMF/trunk/CODINGSTYLE.txt - added note about offset-naive and offset-aware datetime and DateTime

Yvo Schubbe <[email protected]> Mon, 21 Feb 2011 04:32:32 -0500 (EST)
Newsgroups gmane.comp.web.zope.cmf.cvs
Message-ID <20110221093232.06B03941C7__36124.2450461306$1298280758$gmane$org@cvs.zope.org>
Log message for revision 120487:
  - added note about offset-naive and offset-aware datetime and DateTime

Changed:
  U   CMF/trunk/CODINGSTYLE.txt

-=-
Modified: CMF/trunk/CODINGSTYLE.txt
===================================================================
--- CMF/trunk/CODINGSTYLE.txt	2011-02-21 09:28:24 UTC (rev 120486)
+++ CMF/trunk/CODINGSTYLE.txt	2011-02-21 09:32:31 UTC (rev 120487)
@@ -43,6 +43,25 @@
 the ``datetime`` objects usually used in Python. But converting them is
 possible.
 
+Try to use always offset-naive datetime and DateTime values. Using mixed
+values sometimes causes trouble. This is how you can test and normalize them:
+
+    >>> from DateTime.DateTime import DateTime
+    >>> local_tz = DateTime().timezone()
+    >>> aware_DT = DateTime('2002/02/02 02:02:02 ' + local_tz)
+    >>> aware_DT.timezoneNaive()
+    False
+    >>> aware_dt = aware_DT.asdatetime()
+    >>> aware_dt.tzinfo is None
+    False
+
+    >>> naive_DT = DateTime(str(aware_DT)[:19])
+    >>> naive_DT.timezoneNaive()
+    True
+    >>> naive_dt = aware_dt.replace(tzinfo=None)
+    >>> naive_dt.tzinfo is None
+    True
+
 CMF will be migrated to datetime step by step. Formlib based forms already
 require datetime objects. The same schema adapters used for adapting encoded
 strings should also be used for adapting DateTime values. Don't use any