[issue15443] datetime module has no support for nanoseconds

Alexander Belopolsky report at bugs.python.org
Tue Jul 15 03:37:38 CEST 2014


Alexander Belopolsky added the comment:

> (there's no room for an extra 10 bits in the
> carefully arranged 8-byte internal representation)

According to a comment on top of Include/datetime.h, the internal representation of datetime is 10, not 8 bytes.


/* Fields are packed into successive bytes, each viewed as unsigned and
 * big-endian, unless otherwise noted:
 *
 * byte offset
 *  0           year     2 bytes, 1-9999
 *  2           month    1 byte, 1-12
 *  3           day      1 byte, 1-31
 *  4           hour     1 byte, 0-23
 *  5           minute   1 byte, 0-59
 *  6           second   1 byte, 0-59
 *  7           usecond  3 bytes, 0-999999
 * 10
 */

(if you don't trust the comments check the definitions a few lines below)

#define _PyDateTime_DATETIME_DATASIZE 10

AFAIK, Python objects are allocated with at least 32-bit alignment, so we have at least 2 unused bytes at the end of each datetime object.

Furthermore, out of 24 bits allocated for microseconds, only 20 are used, so nanoseconds can be accommodated by adding a single byte to DATETIME_DATASIZE.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15443>
_______________________________________


More information about the Python-bugs-list mailing list