[Python-ideas] Please reconsider the Boolean evaluation of midnight

Alexander Belopolsky alexander.belopolsky at gmail.com
Thu Mar 6 08:20:30 CET 2014


On Thu, Mar 6, 2014 at 2:02 AM, Bruce Leban <bruce at leapyear.org> wrote:

>
> On Wed, Mar 5, 2014 at 10:47 PM, Alexander Belopolsky <
> alexander.belopolsky at gmail.com> wrote:
>
>> it is convenient to have a simple test for midnight.
>>
>
> Except this isn't it. That's only works for naive times. For aware times:
>
> 00:00:00+00:00 = midnight England = midnight UTC => False
> 00:00:00+01:00 = midnight France = 2300 UTC      => True
> 01:00:00+01:00 = 1 am France = midnight UTC      => False
> 19:00:00-05:00 = 1 am Boston = midnight UTC      => True
>
> Code that relies that bool(time) is False for midnight is broken IMHO.
>
>
You keep fighting your own straw-man.  My use case is not using an
arbitrary time
object that someone decided to imbue with a timezone info.  What I want is
given
a *datetime* instance dt to check whether it falls on midnight in whatever
timezone
dt.tzinfo represent or naively if dt.tzinfo is None.

I claim that "if dt.time()" is a perfectly good shorthand for "if dt.time()
!= datetime.time(0)".

I am not trying to argue that "if not dt.timetz()" test is equally useful.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140306/5c6e8f81/attachment.html>


More information about the Python-ideas mailing list