On 3/9/07, Guido van Rossum <[EMAIL PROTECTED]> wrote: > On 3/9/07, BJörn Lindqvist <[EMAIL PROTECTED]> wrote: > > On 3/9/07, Guido van Rossum <[EMAIL PROTECTED]> wrote: > > > On 3/9/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > > The range of datetime objects far exceeds that of the current Unix > > > > timestamp. Given that the range of current (32-bit) Unix timestamps is > > > > approximately 1970 to 2038, What would the output of this be? > > > > > > > > dt = datetime.datetime(3000, 1, 1, 0, 0, 0) > > > > print dt.totimestamp() > > > > dt = datetime.datetime(1900, 1, 1, 0, 0, 0) > > > > print dt.totimestamp() > > > > > > If you extend the range to 64 bits there's no problem: the first > > > should print 32503680000, the second -2208988800. > > > > I think it should be a ValueError, given that the programmer is very > > likely to further use the returned timestamp to for example insert > > stuff in a database. Unix timestamps are not unambiguously defined for > > any years other than 1970 to 2038 imho. > > But they will be. And they already are on some platforms. The database > should raise an OverflowError if a timestamp is out of range, but it > would be unpythonic to limit those outcomes to 32 bits.
Then I guess datetime.fromtimestamp() also should be fixed?: >>> datetime.fromtimestamp(-1) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: timestamp out of range for platform localtime()/gmtime() function >>> datetime.fromtimestamp(-0.5) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: microsecond must be in 0..999999 >>> datetime.fromtimestamp(9999999999) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: timestamp out of range for platform time_t Would be nice if datetime.fromtimestamp(dt.totimestamp()) == dt worked for all datetimes. -- mvh Björn _______________________________________________ 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/archive%40mail-archive.com