[icalendar-dev] util.py/tools.py uid patches
Max M
maxm at mxm.dk
Fri Dec 30 12:27:02 CET 2005
Alan Milligan wrote:
>Similarly, the vDatetime stuff could also support these __add__ and
>__sub__ features to behave as full first-class citizens (a __len__
>function would also help in this regard). Any thoughts on getting these
>into the next release??
>
I tried that approach at first, but it wasn't practical. datetime
arithmetic returns subclasses of the same type as itself.
So to be able to do datetime arithmetic in vDateTime, vDate, vDuration
etc. they would need to subclass their corresponding datetime classes,
and overwrite all the arithmetic methods, just to do the arithemtic. And
then they would still need to be converted to datetime in most cases.
And if you need to do arithmetic with objects of a third type you cannot
do that either. So for each kind of datetime subclass you will need to
do those conversions. Which makes it a squared problem to the number of
different datetime types.
so I decided that it would be smarter to simply return datetime objects
and then do the arithmetic in those.
I think that the simplest and most pratical approach would be to make a
small library of functions, or perhapse better, an adapter for doing
arithmetics and conversions for objects supporting the datetime
interfaces. That library should then allways return straight datetime
types. Pseudocode::
>>> dt1 = DTWrapper(vDateTime())
>>> dt2 = DTWrapper(SomeOtherSubclass())
>>> dt1 + dt2
datetime.datetime()
--
hilsen/regards Max M, Denmark
http://www.mxm.dk/
IT's Mad Science
More information about the icalendar-dev
mailing list