[Python-checkins] python/dist/src/Modules datetimemodule.c,NONE,1.1
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Mon, 16 Dec 2002 12:18:16 -0800
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv26267/python/Modules
Added Files:
datetimemodule.c
Log Message:
datetime escapes the sandbox. The Windows build is all set. I leave it
to others to argue about how to build it on other platforms (on Windows
it's in its own DLL).
--- NEW FILE: datetimemodule.c ---
/* C implementation for the date/time type documented at
* http://www.zope.org/Members/fdrake/DateTimeWiki/FrontPage
*/
#include "Python.h"
#include "modsupport.h"
#include "structmember.h"
#include <time.h>
#include "datetime.h"
/* We require that C int be at least 32 bits, and use int virtually
* everywhere. In just a few cases we use a temp long, where a Python
* API returns a C long. In such cases, we have to ensure that the
* final result fits in a C int (this can be an issue on 64-bit boxes).
*/
#if SIZEOF_INT < 4
# error "datetime.c requires that C int have at least 32 bits"
[...5036 lines suppressed...]
assert(DI100Y == days_before_year(100+1));
us_per_us = PyInt_FromLong(1);
us_per_ms = PyInt_FromLong(1000);
us_per_second = PyInt_FromLong(1000000);
us_per_minute = PyInt_FromLong(60000000);
seconds_per_day = PyInt_FromLong(24 * 3600);
if (us_per_us == NULL || us_per_ms == NULL || us_per_second == NULL ||
us_per_minute == NULL || seconds_per_day == NULL)
return;
/* The rest are too big for 32-bit ints, but even
* us_per_week fits in 40 bits, so doubles should be exact.
*/
us_per_hour = PyLong_FromDouble(3600000000.0);
us_per_day = PyLong_FromDouble(86400000000.0);
us_per_week = PyLong_FromDouble(604800000000.0);
if (us_per_hour == NULL || us_per_day == NULL || us_per_week == NULL)
return;
}