DateTime('2009/06/16') != DateTime('2009-06-16')
Be careful when parsing dates with the Zope DateTime
module.
Recently I have been bitten by a small difference in the way the DateTime
module parses differently formatted date strings. Naively, you would think there
is no difference between the following two DateTime
objects:
>>> from DateTime import DateTime
>>> DateTime('2009/06/16')
DateTime('2009/06/16')
>>> DateTime('2009-06-16')
DateTime('2009/06/16')
So far, so good. But:
>>> DateTime('2009/06/16') == DateTime('2009-06-16')
False
Wait… What?!?
>>> DateTime('2009/06/16').rfc822()
'Tue, 16 Jun 2009 00:00:00 +0200'
>>> DateTime('2009-06-16').rfc822()
'Tue, 16 Jun 2009 00:00:00 +0000'
As you can see, the way you format the date before feeding it to
DateTime
matters: it may take the timezone into account. And this
can really mess up catalog queries if you use slashes when storing
your content and dashes for the query (or the other way around). I’m
sure this is documented somewhere, but why search for documentation if
you ‘know’ how it works. :)