[Python-ideas] Please reconsider the Boolean evaluation of midnight
Alexander Belopolsky
alexander.belopolsky at gmail.com
Thu Mar 6 07:47:12 CET 2014
On Thu, Mar 6, 2014 at 12:16 AM, Bruce Leban <bruce at leapyear.org> wrote:
> Well, it's not surprising that you don't find it's helpful. In fact, it's
> wrong, which to me indicates how confusing this. Which of the following are
> falsey?
>
> 00:00:00+01:00
> 01:00:00+01:00
> 01:00:00-01:00
> 07:00:00+07:00
> 23:00:00-01:00
>
>
> I find it particularly surprising that the bug that the OP described
> finding would occur in the Russia and China, but not in the US. Obviously,
> not an accident. :-)
>
"Aware" time objects are problematic even before you consider their bool
behavior. Fortunately, you don't encounter them too often because
dt.time() returns naive time even if dt is an aware datetime instance.
Again, the use case that I find compelling is to test dt.time() for
falsehood to detect datetime objects that fall on midnight.
I don't understand why people are denying that midnights are special
points. All real numbers are equal, but integers are more equal than
others. When you plot say hourly timeseries it is not uncommon to mark
midnight ticks on the time axis with dt.date() and other ticks with
dt.hour. Whenever you need to do something special when you start a new
date in a simulation of a physical process it is convenient to have a
simple test for midnight.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140306/deeb546e/attachment.html>
More information about the Python-ideas
mailing list