[Python-ideas] Please reconsider the Boolean evaluation of midnight
Donald Stufft
donald at stufft.io
Thu Mar 6 08:30:39 CET 2014
On Mar 6, 2014, at 2:20 AM, Alexander Belopolsky <alexander.belopolsky at gmail.com> wrote:
>
>
>
> 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.
So check for it falling on midnight. It’s not reasonable to expect that midnight will evaluate
to false, especially when it doesn’t if you happen to have a tzinfo on the time (sometimes!).
That makes the behavior even more surprising and more footgun-ey.
>
> I claim that "if dt.time()" is a perfectly good shorthand for "if dt.time() != datetime.time(0)”.
And I claim that you’re reaching to justify stupid behavior.
>
> I am not trying to argue that "if not dt.timetz()" test is equally useful
And yet you can’t control what people do with it. Consistency is a virtue and how objects
act with a tzinfo and how they act without a tzinfo should be as close as possible.
> .
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-----------------
Donald Stufft
PGP: 0x6E3CBCE93372DCFA // 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140306/cb0038f5/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140306/cb0038f5/attachment.sig>
More information about the Python-ideas
mailing list