[Python-Dev] proposal: add basic time type to the standard library

M.-A. Lemburg mal@lemburg.com
Sat, 09 Feb 2002 12:57:05 +0100


Fredrik Lundh wrote:
> 
> mal wrote:
> 
> > In order to make mxDateTime subtypes of this new type we'd need to
> > make sure that the datetime type uses a true struct subset of what
> > I have in DateTime objects now:
> >
> > typedef struct {
> >     PyObject_HEAD
> >
> >     /* Representation used to do calculations */
> >     long absdate;               /* number of days since 31.12. in the year 1 BC
> >                                    calculated in the Gregorian calendar. */
> >     double abstime;             /* seconds since 0:00:00.00 (midnight)
> >                                    on the day pointed to by absdate */
> >
> >  ...lots of broken down values needed to assure roundtrip safety...
> >
> > }
> 
> as Tim has pointed out, what I have in mind is:
> 
>     typedef struct {
>         PyObject_HEAD
>         /* nothing here: subtypes should implement timetuple
>            and, if possible, utctimetuple */
>     } basetimeObject;
> 
>     /* maybe: */
> 
>     PyObject*
>     basetime_timetuple(PyObject* self, PyObject* args)
>     {
>         PyErr_SetString(PyExc_NotImplementedError, "must override");
>         return NULL;
>     }
> 
> (to adapt mxDateTime, all you should have to do is to inherit from
> baseObject, and add an alias for your "tuple" method)

Ok.

Sounds like you are inventing something like a set of abstract 
types here.

I'm very much +1 on that idea, provided the interfaces we define
for these types are simple enough (I think the DB SIG has shown
that simple interface can go a looong way).

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Company & Consulting:                           http://www.egenix.com/
Python Software:                   http://www.egenix.com/files/python/