[Zope3-dev] Dates and times

Jim Fulton jim@zope.com
Thu, 14 Nov 2002 14:24:18 -0500


Marius Gedminas wrote:
> 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? 

Do you know how other Python database APIs handle this? What does
Psycopg do with these.

 > 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?)? 

You are right, this would be wrong.

 > Leave all zeroes for the year/month/day part
> (currently datetime doesn't allow this)? 

Wrong too.

 > Maybe the datetime module needs a 'time' class?

Maybe.


> 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,

Yes

 > 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). 

No. No. No. No math on times. :)

 > 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),

Yes.

 > but is it useful enough to
> warrant the addition of new classes?

I don't know. I don't think it would be all that useful.

> (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?

I think it would be nice to have a time type for completeness and to better
interoperate with databases. I would keep it as simple as possible. I'd keep it
a basic container for the time data that would otherwise appear in datetime and
datetimetz objects. There shouldn't be math support. There should be special
constructors for combining a date or datetime(tz) and a time(tz).

Wanna propose an interface? :)

It should be posted somewhere at:
http://www.zope.org/Members/fdrake/DateTimeWiki/FrontPage

Thanks.

Jim

-- 
Jim Fulton           mailto:jim@zope.com       Python Powered!
CTO                  (888) 344-4332            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org