Year 0 and year 10,000 in timetuple
While datetime range is limited to years from 1 through 9999, it is possible to produce time tuple with year 0 or year 10,000:
t1 = datetime.min.replace(tzinfo=timezone.max) t2 = datetime.max.replace(tzinfo=timezone.min) t1.utctimetuple().tm_year 0 t2.utctimetuple().tm_year 10000
Most if not all functions consuming timetuples are not designed to handle years beyond 9999 and such timetuples cannot be converted back to datetime. I would like to make utctimetuple() method to raise OverflowError on values like t1 or t2 above. These values are most certainly a mistake in application ad it is better to detect them earlier before they make their way into system functions that cannot handle them. See issues 9005 and 6608 on the tracker. http://bugs.python.org/issue9005 http://bugs.python.org/issue6608
But what if they are used intentionally as "impossible" or sentinel values? --Guido (on Android) On Jun 19, 2010 2:37 PM, "Alexander Belopolsky" < alexander.belopolsky@gmail.com> wrote:
While datetime range is limited to years from 1 through 9999, it is possible to produce time tuple with year 0 or year 10,000:
t1 = datetime.min.replace(tzinfo=timezone.max) t2 = datetime.max.replace(tzinfo=timezone.min) t1.utctimetuple().tm_year 0 t2.utctimetuple().tm_year 10000
Most if not all functions consuming timetuples are not designed to handle years beyond 9999 and such timetuples cannot be converted back to datetime.
I would like to make utctimetuple() method to raise OverflowError on values like t1 or t2 above. These values are most certainly a mistake in application ad it is better to detect them earlier before they make their way into system functions that cannot handle them.
See issues 9005 and 6608 on the tracker.
http://bugs.python.org/issue9005 http://bugs.python.org/issue6608 _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
On Jun 19, 2010, at 6:12 PM, Guido van Rossum <guido@python.org> wrote:
But what if they are used intentionally as "impossible" or sentinel values?
That would be another reason not to produce them accidently. Note that I am proposing disallowing production of out of range years from valid datetime objects, not consumption of them if that is allowed anywhere.
On Sat, Jun 19, 2010 at 3:31 PM, Alexander Belopolsky <alexander.belopolsky@gmail.com> wrote:
On Jun 19, 2010, at 6:12 PM, Guido van Rossum <guido@python.org> wrote:
But what if they are used intentionally as "impossible" or sentinel values?
That would be another reason not to produce them accidently. Note that I am proposing disallowing production of out of range years from valid datetime objects, not consumption of them if that is allowed anywhere.
OK. -- --Guido van Rossum (python.org/~guido)
participants (2)
-
Alexander Belopolsky
-
Guido van Rossum