[Python-ideas] Need way to check if a `datetime.timedelta` is positive

Ram Rachum ram.rachum at gmail.com
Sat Nov 5 15:07:22 CET 2011


(Sorry for possible double-post, Google Groups was doing weird things.)

Hey,

I'm currently writing code that's manipulating `datetime.timedelta` 
objects. I get one and I need to check whether it's positive or negative.

I can't really think of an elegant way to do this.

Here's one:

    my_timedelta >= datetime.timedelta(0)

Another one:

    my_timedelta.total_seconds() >= 0


Perhaps we should allow a more elegant way? Possibly `my_timedelta >= 0` 
for 0 only?


Thanks,
Ram.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20111105/308dcb70/attachment.html>


More information about the Python-ideas mailing list