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

cool-RR ram.rachum at gmail.com
Sat Nov 5 15:26:00 CET 2011


On Sat, Nov 5, 2011 at 4:22 PM, Arnaud Delobelle <arnodel at gmail.com> wrote:

> 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
>

Shorter, yeah, but still weird. I'm making a calculation involving
microseconds and suddenly I deal with days? Pretty weird.


-- 
Sincerely,
Ram Rachum
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20111105/813b04df/attachment.html>


More information about the Python-ideas mailing list