[Python-checkins] python/nondist/sandbox/datetime obj_datetime.c,1.4,1.5
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Thu, 21 Nov 2002 11:47:36 -0800
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv19476
Modified Files:
obj_datetime.c
Log Message:
datetime_now(): Removed the last use of gettimeofday(), but *this* one
had a real point to it. I'll have to fix this later, but it doesn't look
easy to do so, and I don't want to get paralyzed by this at the start.
It still doesn't compile on Windows, but gettimeofday ain't the problem
anymore -- I'm not sure what is.
Index: obj_datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_datetime.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** obj_datetime.c 21 Nov 2002 19:31:30 -0000 1.4
--- obj_datetime.c 21 Nov 2002 19:47:34 -0000 1.5
***************
*** 288,291 ****
--- 288,299 ----
datetime_now(PyObject *self, PyObject *cls)
{
+ /* XXX MAJOR: This needs to get some notion of current time
+ * XXX to better than 1-second resolution. Doing this in a x-
+ * XXX platform way is mondo painful. Maybe floattime() from
+ * XXX timemodule.c is good enough? We're running out of bits
+ * XXX in a typical time_t, though, and gettimeofday() should do
+ * XXX better than floattime() -- but gettimeofday isn't portable.
+ */
+ #if 0
/* XXX need to create the instance by calling cls(y,mon,d,h,min,s,u) */
struct timeval t;
***************
*** 305,308 ****
--- 313,329 ----
tm->tm_mday, tm->tm_hour, tm->tm_min,
tm->tm_sec, t.tv_usec);
+ #else
+ /* XXX need to create the instance by calling cls(y,mon,d,h,min,s,u) */
+ struct tm *tm;
+ time_t timet;
+
+ time(&timet);
+ tm = localtime(&timet);
+
+ return PyObject_CallFunction(cls, "iiiiiil",
+ tm->tm_year + 1900, tm->tm_mon + 1,
+ tm->tm_mday, tm->tm_hour, tm->tm_min,
+ tm->tm_sec, 0);
+ #endif
}