[Python-Dev] Checking input range in time.asctime and time.ctime

Alexander Belopolsky alexander.belopolsky at gmail.com
Wed Jan 5 23:55:19 CET 2011

On Wed, Jan 5, 2011 at 4:33 PM, Guido van Rossum <guido at python.org> wrote:
>> Why >= 1?
> Because that's what the datetime module accepts.

What the datetime module accepts is irrelevant here.  Note that
functions affected by accept2dyear are: time.mktime(), time.asctime(),
time.strftime() and indirectly time.ctime().  Neither of them produces
result that is directly usable by the datetime module.  Furthermore,
this thread started with me arguing that year > 9999 should raise
ValueError and if we wanted to restrict time module functions to
datetime-supported year range, that would be the right thing to do.
If I understand your "garbage in garbage out" principle correctly,
time-processig functions should not introduce arbitrary limits unless
there is a specific reason for them.  In datetime module, calendar
calculations would be too complicated if we had to support date range
that does not fit in 32-bit integer.  There is no such consideration
in the time module, so we should support whatever the underlying
system can.

This said, I would be perfectly happy with just changing y >= 1900 to
y >= 1000.  Doing so will spare us from making a choice between
'0012', '12' and '   12' in time.asctime().   Time-series that extend
back to 19th century are not unheard of and in many places modern
calendar was already in use back then.  Anything prior to year 1000
would certainly require a custom calendar module anyways.

More information about the Python-Dev mailing list