[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2014-03-05 Thread Chris Rebert

Changes by Chris Rebert :


--
nosy: +cvrebert

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2014-03-04 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

> Please reopen.

Please bring your case to python-ideas.  All developers who commented on this 
issue agree that it is invalid.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2014-03-04 Thread Andreas Pelme

Andreas Pelme added the comment:

I agree with Danilo and Shai -- this behavior very surprising. I deal with 
datetimes a lot, and this bug has bitten me a number of times.

I cannot really think of a single case where "if timeobj:" is useful with the 
current behavior. It results in a check for "is timeobj midnight or false?"

Would that ever be useful in practice? If you are indeed checking for midnight, 
surely "if timeobj == time(0, 0):" would be the most explicit and obvious way 
to do it?

--
nosy: +Andreas.Pelme

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2014-03-04 Thread Shai Berger

Shai Berger added the comment:

Just got bit by this.

Tim Peters said: """
It is odd, but really no odder than "zero values" of other types evaluating to 
false in Boolean contexts.
"""

I disagree. Midnight is not a "zero value", it is just a value. It does not 
have any special qualities analogous to those of 0, "", or the empty set. Time 
values cannot be added or multiplied. Midnight evaluting to false makes as much 
sense as date(1,1,1) -- the minimal valid date value -- evaluating to false 
(and it doesn't).

It makes perfect sense for timedelta(0) to evaluate to false, and it does. time 
is different.

Also, while I appreciate this will never be fixed for Python2, the same 
behavior exists in Python3, where there may still be room for improvement.

I second Danilo Bergen's request. Please reopen.

--
nosy: +shai

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2012-11-27 Thread Danilo Bargen

Danilo Bargen added the comment:

I disagree, I think this bug should be reopened and fixed.

A use case that I just ran into: I'm using a Django form with time fields that 
aren't required, but that are only valid in combination (if there's a open time 
there has to be a close time).

if not (self.closed or (self.open_time and self.close_time )):  

raise ValidationError("Invalid times")

This leads to a Validation Error when using the times 12:00 and 00:00.

Of course, this case is debatable and can be worked around by using `self.open 
is not None and self.close is not None`, but there are even more problems when 
using the times inside the template.

I'm using the following widespread pattern inside my templates:

Close time: {{ close_time|default:"-" }}

The "default" filter used in this case displays the string "-" if the value on 
the left side of the | symbol evaluates to False. That makes sense in almost 
all of the cases.

In the case of the `datetime.time(0, 0)` object, the default value is 
displayed, even though `datetime.time(0, 0).__str__()` results in a valid 
string (in this case '00:00:00').

(By the way, through these experiments I also found a bug in Django's date 
formatting template function caused by this inconsistency, which I will report 
separately.)

I agree that casting time objects to a boolean value doesn't make much sense. 
But especially because of that, inconsistencies in the resulting boolean value 
should NOT exist. Yet another argument for this is that in many regions 
midnight isn't considered 00:00, but 24:00, which would obviously not evaluate 
to False.

Please fix this. Otherwise it will lead to a whole lot of weird bugs in 
software using the datetime library.

--
nosy: +gwrtheyrn

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2012-05-07 Thread Éric Araujo

Changes by Éric Araujo :


--
nosy: +eric.araujo

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2012-02-03 Thread Lakin Wecker

Lakin Wecker  added the comment:

Yeah - good point, and I agree.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2012-02-03 Thread Tim Peters

Tim Peters  added the comment:

It is odd, but really no odder than "zero values" of other types evaluating to 
false in Boolean contexts ;-)  Closing as "invalid".

--
resolution:  -> invalid
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2012-02-03 Thread Lakin Wecker

Lakin Wecker  added the comment:

Although I find it odd, you are all correct.

It is documented.  (I don't know how I missed that when I read those docs 
looking for that exact documentation).

It is consistent with the rest of python.

Do I close this? Do you guys? I'm fine with closing it.  Thanks and sorry for 
the noise.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2012-02-03 Thread Tim Peters

Tim Peters  added the comment:

>From the docs, at:

http://docs.python.org/library/datetime.html#time-objects

"""
in Boolean contexts, a time object is considered to be true if and only if, 
after converting it to minutes and subtracting utcoffset() (or 0 if that’s 
None), the result is non-zero.
"""

--
nosy: +tim_one

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2012-02-03 Thread Alexander Belopolsky

Alexander Belopolsky  added the comment:

This is by design.  I don't have a reference, but I do remember this being 
discussed.  Suggestions for improving the documentation are welcome.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2012-02-03 Thread Georg Brandl

Georg Brandl  added the comment:

BTW, "being a valid time" is not a good argument: 0, "" or False are all valid 
instances of their types.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2012-02-03 Thread Georg Brandl

Georg Brandl  added the comment:

It must be by design -- someone has implemented a __bool__ (formerly 
__nonzero__) method; otherwise all objects would be true.

--
nosy: +georg.brandl, lemburg

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2012-02-03 Thread Lakin Wecker

Lakin Wecker  added the comment:

Right. I've updated my code to be more correct:

instead of:

if not start_time:
start_time = default_time

it now reads:

if start_time is None:
start_time = default_time

which operates correctly and works fine for my case, I just thought it was odd 
that one time out of all of them evaluates to False.  I too wonder if it's by 
design or not.

It's definitely not documented if it is by design.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2012-02-03 Thread R. David Murray

Changes by R. David Murray :


--
nosy: +belopolsky

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2012-02-03 Thread R. David Murray

R. David Murray  added the comment:

I don't think I would have ever thought of testing a datetime for its truth 
value.  But the behavior you observe is consistent with the rest of Python: 0 
is false.

I wonder if this is by design or by accident.

--
nosy: +r.david.murray

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2012-02-03 Thread Lakin Wecker

Changes by Lakin Wecker :


--
components: +Library (Lib)
type:  -> behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2012-02-03 Thread Lakin Wecker

Lakin Wecker  added the comment:

I'm updating the versions to the ones that I've actually tried it on - this is 
not an exhaustive search at this point.

--
versions: +Python 2.6, Python 2.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13936] datetime.time(0, 0, 0) evaluates to False despite being a valid time

2012-02-03 Thread Lakin Wecker

New submission from Lakin Wecker :

midnight is represented by datetime.time(0,0,0).  However, this time (unlike 
all other valid times, including datetime.time(0,0,1)) evalutes to false in if 
conditions:

import datetime
if datetime.time(0,0,0):
print "datetime.time(0,0,0) is not a bug!"
else:
print "datetime.time(0,0,0) is a bug!"

if datetime.time(0,0,1):
print "datetime.time(0,0,1) is not a bug!"
else:
print "datetime.time(0,0,1) is a bug!"

--
messages: 152556
nosy: Lakin.Wecker
priority: normal
severity: normal
status: open
title: datetime.time(0,0,0) evaluates to False despite being a valid time

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com