[Python-checkins] CVS: python/nondist/sandbox/datetime datetime.c,1.8,1.9

Fred L. Drake fdrake@users.sourceforge.net
Tue, 26 Mar 2002 14:38:49 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory usw-pr-cvs1:/tmp/cvs-serv18127

Modified Files:
	datetime.c 
Log Message:
Make str() of datetime objects match the Python prototype.

Index: datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** datetime.c	26 Mar 2002 22:22:50 -0000	1.8
--- datetime.c	26 Mar 2002 22:38:45 -0000	1.9
***************
*** 160,167 ****
  }
  
  static PyObject *
  datetime_str(PyDateTime_Object *self)
  {
!     return datetime_repr(self);
  }
  
--- 160,181 ----
  }
  
+ static void
+ isoformat(PyDateTime_Object *dt, char sep, char buffer[], int bufflen)
+ {
+     PyOS_snprintf(buffer, bufflen,
+                   "%04d-%02d-%02d%c%02d:%02d:%02d.%06d",
+                   GET_YEAR(dt), GET_MONTH(dt), GET_DAY(dt),
+                   sep,
+                   GET_HOUR(dt), GET_MINUTE(dt), GET_SECOND(dt),
+                   GET_MICROSECOND(dt));
+ }
+ 
  static PyObject *
  datetime_str(PyDateTime_Object *self)
  {
!     char buffer[128];
!     isoformat(self, ' ', buffer, sizeof(buffer));
! 
!     return PyString_FromString(buffer);
  }
  
***************
*** 316,320 ****
  }
  
- 
  static PyObject *
  datetime_isoformat(PyDateTime_Object *self, PyObject *args, PyObject *kw)
--- 330,333 ----
***************
*** 327,337 ****
      if (!PyArg_ParseTupleAndKeywords(args, kw, "|c:isoformat", keywords, &sep))
          return NULL;
  
-     PyOS_snprintf(buffer, sizeof(buffer),
-                   "%04d-%02d-%02d%c%02d:%02d:%02d.%06d",
-                   GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
-                   sep,
-                   GET_HOUR(self), GET_MINUTE(self), GET_SECOND(self),
-                   GET_MICROSECOND(self));
      return PyString_FromString(buffer);
  }
--- 340,345 ----
      if (!PyArg_ParseTupleAndKeywords(args, kw, "|c:isoformat", keywords, &sep))
          return NULL;
+     isoformat(self, sep, buffer, sizeof(buffer));
  
      return PyString_FromString(buffer);
  }