[Python-ideas] datetime: Support infinity
Chris Barker
chris.barker at noaa.gov
Thu Jan 29 20:35:01 CET 2015
On Thu, Jan 29, 2015 at 11:19 AM, Yawar Amin <yawar.amin at gmail.com> wrote:
> My test implementation works for me on Python 2.7, see http://repl.it/9Wz
>
cool site!
And yes, it does appear to work.
However the subclassing approach is really weird, as the infinite datetimes
have a year, month, day, etc -- that strikes me as ripe for error. That's
why I didn't subclass, but just had them e independent.
Another option would be to override just about everything...
-Chris
> Notice especially the last few assertions, where normal datetime objects
> are on the LHS.
>
> Regards,
>
> Yawar
>
> On 2015-01-29, at 2:04, Chris Barker <chris.barker at noaa.gov> wrote:
>
> On Wed, Jan 28, 2015 at 6:55 PM, Yawar Amin <yawar.amin at gmail.com> wrote:
>
>> Cool, the comparison operator logic looks very similar to mine:
>>
>> https://groups.google.com/d/msg/python-ideas/G3jeWoa6h14/ELpDLFu28QcJ
>>
>>
> Did you get it to work both ways? i.e.
>
> datetime.neg_inf < datetime.now()
>
> and
>
> datetime.now() > datetime.neg_inf
>
> I had trouble with that, because the regular datetime doesn't know how to
> compare itself to a neg_inf object.
>
>
>> I believe the ideal design is the following type hierarchy:
>>
>> datetime_base
>> datetime_neg_inf
>> datetime_pos_inf
>> datetime
>>
>> But in the interests of pragmatism, I think this one can be made to
>> work:
>>
>> datetime
>> datetime_neg_inf
>> datetime_pos_inf
>>
>
> yup -- should work.
>
> and you could add class methods to the datetime object, so you could do:
>
> datetime.neg_inf()
> and
> datetime.pos_inf()
>
>
>> The
>>
> advantage to this is that we don't have to switch everything over to
>> using a new derived type--just use the normal datetime for the majority
>> of cases where we don't need inifinity dates.
>>
>
> And it could be a third part package, too. -- particularly good for
> backward compatibility.
>
> -Chris
>
>
> --
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R (206) 526-6959 voice
> 7600 Sand Point Way NE (206) 526-6329 fax
> Seattle, WA 98115 (206) 526-6317 main reception
>
> Chris.Barker at noaa.gov
>
>
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150129/7e1796e7/attachment-0001.html>
More information about the Python-ideas
mailing list