[Python-Dev] Interop between datetime and mxDateTime
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
* mxD - d (assuming 0:00 as time part), mxD - dt
* mxD -/+ t
* mxDD + d (assuming 0:00 as time part), mxDD + dt
* mxDD -/+ t
* mxD < d
* mxDD < t
(and reverse order)
... and contructors
* DateTimeFrom(dt), DateTimeFrom(d)
* DateTimeDeltaFrom(t)
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:
* a basedate class which is accessible at C level
* compatibility to Unix ticks floats (nb_float)
--
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/