[Python-Dev] Interop between datetime and mxDateTime (original) (raw)

M.-A. Lemburg mal@lemburg.com
Tue, 14 Jan 2003 17:30:37 +0100


Guido van Rossum wrote:

Certainly, such a subclass would help me enormously, and would probably make it quite simple for this to allow any datetime object to be passed to COM/Windows functions. If we can do the same for MAL (ie, a Python datetime magically works anywhere an mxDateTime did before), then this would be a real bonus :)

OK, we can do this. (If someone can cook up a patch that would be great.) Mark, what APIs would you use on a time object? And don't you need an API to create time objects? Still waiting for an answer from Marc-Andre...

An abstract baseclass would only help all the way if I can make mxDateTime objects new style classes. That's not going to happen for a few months because I don't have any requirement for it.

Now for interop, I'm basically interested in adding support for most of the binary operations ...

mxD = mx.DateTime.DateTime mxDD = mx.DateTime.DateTimeDelta dt = datetime t = timedelta d = date

(and reverse order)

... and contructors

etc.

In order to get the binary ops to work, I'll have to enable new style number support in mxDateTime and drop the 1.5.2 support :-(

Now the problem I see is when an API expects a datetime object and gets an mxDateTime object instead.

For mxDateTime I have solved this by simply letting float(mxD) return a Unix ticks value and float(mxDD) return the value in seconds since midnight -- this makes mxDateTime object compatible to all APIs which have previously only accepted Unix ticks.

mxDateTime also does mixed type operations using Unix ticks if it doesn't know the other type.

So perhaps we need something like this:

-- Marc-Andre Lemburg CEO eGenix.com Software GmbH


eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,... Python Consulting: http://www.egenix.com/ Python Software: http://www.egenix.com/files/python/