[Zope-dev] Collector issue #30: Empty dates

Lennart Regebro lennart@torped.se
Mon, 18 Mar 2002 19:57:38 +0100


http://collector.zope.org/Zope/30

What are people take on empty dates? Today I can find no way to enter empty
dates (I think "None" worked before, but it doesn't work in 2.5.1b1 anyway).

This is a problem, because we need to be able to have empty dates. Also,
enetering something magick (like None, or 1980/0/0 isn't usable. We fix this
with this simple patch, which so far has caused us no problems:

from ZPublisher import Converters

def fixedfield2date(v):
    from DateTime import DateTime
    if hasattr(v,'read'): v=v.read()
    else: v=str(v)
    if v=='':
       return v
    return DateTime(v)

Converters.field2date = fixedfield2date
Converters.type_converters['date'] = fixedfield2date

It's the "if v=='': return v" part that does it. This makes it possible to
enter empty strings as dates. We then handle these as unset dates. Seems to
work fine as far as we can see.

I was told that this had some type of compatibility issue. If thats the
case, how do you suggest we fix it?

Best Regards

Lennart Regebro
Torped Strategi och Kommunikation AB