[Zope3-dev] Dates and times

Marius Gedminas mgedmin@codeworks.lt
Thu, 14 Nov 2002 12:30:23 +0200


Hi,

We've now working on PsycopgDA type conversion for date/time fields.
Some of PostgreSQL types (DATE, TIMESTAMP, TIMESTAMPTZ) nicely map to
new Python datetime types (date, datetime, datetimetz).  The question is
what should we do with TIME and TIMETZ?  Map them to datetime/datetimetz
by supplying perhaps today's year/month/day, but that feels wrong (e.g.
why should str(dbresults.mytimefield) include today's date which is not
in the database?)?  Leave all zeroes for the year/month/day part
(currently datetime doesn't allow this)?  Maybe the datetime module
needs a 'time' class?

I've been thinking about possible uses of that, and the only operations
with times I can think of are combining a date object and a time object
to get a datetime object, subtracting two times to get an interval
(which perhaps should always be positive, i.e. some sort of modular
arithmetic (modulo 24 hours)), and adding an interval to a time (also
mod 24 hours).  It could be useful for working on periodic schedules
(e.g., combine a time object retrieved from a database with a manually
constructed 'next Wednesday' date object), but is it useful enough to
warrant the addition of new classes?

(Everything that applies to the potential datetime.time could be also
applied to a hyphotetical datetime.timetz, which combines with date to
produce a datetimetz etc.)

Comments?

Marius Gedminas
-- 
Q:      Why do mountain climbers rope themselves together?
A:      To prevent the sensible ones from going home.