[Python-ideas] Need way to check if a `datetime.timedelta` is positive
Arnaud Delobelle
arnodel at gmail.com
Sat Nov 5 15:22:29 CET 2011
On 5 November 2011 14:07, Ram Rachum <ram.rachum at gmail.com> wrote:
> (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.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
>
(That's more of a question for c.l.py)
Simpler:
my_timedelta.days >= 0
--
Arnaud
More information about the Python-ideas
mailing list