[Python-ideas] bool(datetime.time(0, 0))

Alexander Belopolsky alexander.belopolsky at gmail.com
Mon May 7 18:57:47 CEST 2012


On Mon, May 7, 2012 at 12:33 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
>> I have a feeling that "readers" here are readers of documentation or
>> tutorials rather than readers of actual code.
>
> I was talking about readers of code. If I read code where boolean
> testing of a time object is done, I wouldn't assume the intent is to
> test for midnight (unless there's a comment indicating so).

I understand your hypothetical, but does such code actually exist in
the wild or are we debating the number of angels than can dance at
midnight?  Yes, if I were to rely on bool(time(0)) exact behavior, I
would comment my code.  Do we know one way or another whether such
code exists?

As a matter of coding stile, I recommend avoiding use of datetime.time
objects.  More often than not, time values are meaningless when
detached from the date value.  This is particularly true when timezone
aware instances are used.  Lack of support for time + timedelta makes
naked timevalues inconvenient even in reasonable applications that
deal with schedules that repeat from day to day.   If perceived
uncertainly over the truth value will further dissuade anyone from
using naked time objects, I am all for it.

Note that since date range starts at date(1,1,1) we don't have the
same problem with the date or datetime objects.



More information about the Python-ideas mailing list