Re: psycopg2: parsing timestamps with odd time zones

Daniele Varrazzo <[email protected]> Wed, 19 May 2010 15:41:53 +0100
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
On Wed, May 19, 2010 at 2:36 PM, Karsten Hilbert
<[email protected]> wrote:
> Hello all,
>
> apparently, the exception thrown by Python when failing to
> parse time zones with seconds in them has changed. It used
> to be
>
>        "DataError: unable to parse time"
>
> but now is the more specific:
>
>        "ValueError: time zone offset XXXX is not a whole number of minutes"

I don't know much about this type caster: please accept a few
questions to better understand its purpose and our limitations.

Is this really the best we can do? I feel depending on the exception
message a little bit brittle. Couldn't we partially pre-parse 's' and
pass DATETIME something stripped of the part it makes it fail, just to
put the things back before returning?

I don't know exactly the type of strings TSTZ_W_SECS expects (and the
object it returns): it would be nice to have a few of them in the test
suite, both for testing and documentation.

What stops us to have a default typecaster doing the right thing in
first place? Is it because TSTZ_W_SECS truncates what can't be done
(instead of raising an exception)? I think it could be accomplished by
not relying on the python parser for the timezone part. It also seem
that the current constructor implementation of tz.FixedOffsetTimezone
should be changed to allow for seconds, which can be probably done
without breaking compatibility. Apart from that, I see no reason to be
unable to deal with seconds in the timezone (I assume pytz can deal
with them)... am I overlooking anything?

Thank you very much, cheers!

-- Daniele