Penguin

Differences between version 2 and previous revision of PythonNotes.

Other diffs: Previous Major Revision, Previous Author, or view the Annotated Edit History

Newer page: version 2 Last edited on Monday, October 18, 2004 2:59:12 am by AristotlePagaltzis Revert
Older page: version 1 Last edited on Tuesday, October 12, 2004 10:14:06 am by MattBrown Revert
@@ -1,16 +1,18 @@
-Progamming Notes to help with [Python] 
+!!! Timezones and [Python] < 2.3  
  
-----  
-!! Timezones and Python < 2.3 
+[Python] 2.3 has made some impressive leaps forward in its support of timezones and the classes that it makes available to handle them. If you are doing anything that uses timezones even remotely you will save yourself a __lot__ of hassle by not using a version of [ Python] older than 2.3! If for some reason you're stuck with [Python] < 2.3 (like you run a pathetically old distro like [Woody]) then watch out for the following.  
  
-Python 2.3 has made some impressive leaps forward in its support of timezones and the classes that it makes available to handle them. If you are doing anything that uses timezones even remotely you will save yourself a __lot__ of hassle by not using a version of Python older than 2.3 ! If for some reason you're stuck with Python < 2.3 (like you run a pathetically old distro like Woody) then watch out for the following
+!! strptime  
  
-! strptime  
- In Python < 2.3 strptime can cause problems if your format string does not specify a timezone as there is no data for Python to set the DST flag in the returned tuple from, so it is left undefined and is filled with a platform specific value. This causes problems if you then try and convert the parsed date into a timestamp and then an ascii time. Usually you end up with a time that is 1 hour out from what it should be! To fix this problem, you can do two things  
-# Modify your format string so that it reads a timezone  
-# Set the DST field to -1 (unknown) explicitly, this is what Python 2.3 does. Setting the DST field to -1 causes other time related functions to handle the date correctly using the current timezone of the machine. You can accomplish this with the little code snippet below.  
+In [ Python] < 2.3 strptime can cause problems if your format string does not specify a timezone as there is no data for [ Python] to set the DST flag in the returned tuple from, so it is left undefined and is filled with a platform specific value. This causes problems if you then try and convert the parsed date into a timestamp and then an ascii time. Usually you end up with a time that is 1 hour out from what it should be! To fix this problem, you can do two things:  
  
- ptime = time.strptime("2004-10-06 10:00:00", "%Y-%m-%d %H:%M:%S")[ [:8] + (-1,) 
+* Modify your format string so that it reads a timezone  
+  
+* Set the DST field to -1 (unknown) explicitly, which causes other time related functions to handle the date correctly using the current timezone of the machine.  
+ <verbatim>  
+ ptime = time.strptime("2004-10-06 10:00:00", "%Y-%m-%d %H:%M:%S")[:8] + (-1,)  
+ </verbatim>  
+ This is what [Python] 2.3 does, implicitly.  
  
 ---- 
 CategoryProgramming, CategoryNotes