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

Steven D'Aprano steve at pearwood.info
Wed May 9 07:42:28 CEST 2012


On Tue, May 08, 2012 at 01:57:32PM -0400, Terry Reedy wrote:
> On 5/8/2012 7:36 AM, M.-A. Lemburg wrote:
> 
> >It's perfectly fine for time value to mimic a boolean value
> >by following the same paradigm as a float "seconds since midnight"
> >value.
> 
> Ah, I think this is the key to the dispute as to whether midnight should 
> be False or True. Is the implementation of time of day as seconds since 
> midnight essential (then midnight should be False) or accidental (then 
> midnight should be True like all other times)? Different discussants 
> disagree on the premise and hence the conclusion.

If we implemented times as an Hour-Minute-Second tuple would that imply 
that midnight was True because the tuple (0, 0, 0) is not an empty 
tuple? I don't think so.


> If one first implements time-of-day as a number representing seconds 
> from midnight, then bool(midmight) is bool(0) is False, like it or not. 
> If one later wraps the number as a Time object, as Python did, then 
> seconds from midnight and the specialness of midnight is essential for 
> the new object to be a completely back-compatible drop-in replacement 
> (with augmentations). Anyway, if 'from midnight' is part of the core 
> concept of the class, the current behavior is correct.

Just because times can be implemented as (say) floats doesn't mean it is 
sensible to treat them as floats. "Square root of 3:15pm" isn't a 
meaningful concept.


> If one starts with time-of-day as a concept independent of linear 
> numbers, as smoothly flowing around a circle, then making any particular 
> time of day (or point on the circle) special seems wrong.

Precisely.

Especially when that special-time-of-day depends on the timezone.

[...]
> Abstractly, the second viewpoint seems correct. Pragmatically, however, 
> civilized humans (those with clocks ;-) have standardized on local 
> nominal midnight as the base point for numerically measuring time of day.

Even if that is correct, and I think that orthodox Jews may disagree 
that the day begins at midnight (even those with clocks), the 
datetime.time class does not fit that model. Local midnight is not 
necessarily false.



-- 
Steven



More information about the Python-ideas mailing list