[Zope] DateTime, Zope DateTime and PostGres

Stephan Richter SRichter@ixl.com
Sun, 8 Aug 1999 20:47:48 -0500


If some of you had problems converting date results from a PostGres DB, then I
hope the following lines will help you out:

Problem
1. Since the PyGreSQL Adapter is derived from the standard PyGres Module, it
will return Dates as Strings. Thats annoying, but the developer of the pygres
module is working at the problem.
2. The DateTime module that comes with Zope is not complete. It does not
contain the very important Parser.

Solution:
1. You can download and compile the full mxDateTime module. You will have an
entire directory called DateTime. Rename it (to avoid conflicts with Zope's
DateTime) to something like DateTimeNew. Now copy the directory into
ZopeDir/lib/python/. You will be now able to call DateTimeNew from the modules
you write for External Methods.

2. Create a module in ZopeDir/Extensions. For example: mymodule.py
There you can put code like:

import DateTimeNew

def format_date_string(date_string, format):
      date = DateTimeNew.Parser.DateTimeFromString(date_string)
      return date.strftime(format)

3. Let's say the external method in Zope has the same name as the module
function. You can then use it like that, assuming you have a Z SQL method
called qry_get_date_of_data that gets all values from column 'created':

<dtml-in qry_get_date_of_data>
  <dtml-var "format_date_string(created, '%a %b %d, %Y %H:%M:%S')"><br>
</dtml-in>

I hope that helps. I agree, it is a hack, but better then nothing.

stephan
 --
Stephan Richter
iXL - Software Designer and Engineer