Commit 7682d043 authored by Amaury Forgeot d'Arc's avatar Amaury Forgeot d'Arc

Merged revisions 77122 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r77122 | amaury.forgeotdarc | 2009-12-29 23:03:38 +0100 (mar., 29 déc. 2009) | 3 lines

  #7413: Passing '\0' as the separator to datetime.datetime.isoformat()
  used to drop the time part of the result.
........
parent 2b4b2d1c
...@@ -1173,6 +1173,7 @@ class TestDateTime(TestDate): ...@@ -1173,6 +1173,7 @@ class TestDateTime(TestDate):
self.assertEqual(t.isoformat(), "0002-03-02T04:05:01.000123") self.assertEqual(t.isoformat(), "0002-03-02T04:05:01.000123")
self.assertEqual(t.isoformat('T'), "0002-03-02T04:05:01.000123") self.assertEqual(t.isoformat('T'), "0002-03-02T04:05:01.000123")
self.assertEqual(t.isoformat(' '), "0002-03-02 04:05:01.000123") self.assertEqual(t.isoformat(' '), "0002-03-02 04:05:01.000123")
self.assertEqual(t.isoformat('\x00'), "0002-03-02\x0004:05:01.000123")
# str is ISO format with the separator forced to a blank. # str is ISO format with the separator forced to a blank.
self.assertEqual(str(t), "0002-03-02 04:05:01.000123") self.assertEqual(str(t), "0002-03-02 04:05:01.000123")
......
...@@ -12,6 +12,9 @@ What's New in Python 2.6.5 ...@@ -12,6 +12,9 @@ What's New in Python 2.6.5
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #7413: Passing '\0' as the separator to datetime.datetime.isoformat()
used to drop the time part of the result.
- Issue #6108: unicode(exception) and str(exception) should return the same - Issue #6108: unicode(exception) and str(exception) should return the same
message when only __str__ (and not __unicode__) is overridden in the subclass. message when only __str__ (and not __unicode__) is overridden in the subclass.
......
...@@ -1362,21 +1362,26 @@ isoformat_date(PyDateTime_Date *dt, char buffer[], int bufflen) ...@@ -1362,21 +1362,26 @@ isoformat_date(PyDateTime_Date *dt, char buffer[], int bufflen)
x = PyOS_snprintf(buffer, bufflen, x = PyOS_snprintf(buffer, bufflen,
"%04d-%02d-%02d", "%04d-%02d-%02d",
GET_YEAR(dt), GET_MONTH(dt), GET_DAY(dt)); GET_YEAR(dt), GET_MONTH(dt), GET_DAY(dt));
assert(bufflen >= x);
return buffer + x; return buffer + x;
} }
static void static char *
isoformat_time(PyDateTime_DateTime *dt, char buffer[], int bufflen) isoformat_time(PyDateTime_DateTime *dt, char buffer[], int bufflen)
{ {
int x;
int us = DATE_GET_MICROSECOND(dt); int us = DATE_GET_MICROSECOND(dt);
PyOS_snprintf(buffer, bufflen, x = PyOS_snprintf(buffer, bufflen,
"%02d:%02d:%02d", /* 8 characters */ "%02d:%02d:%02d",
DATE_GET_HOUR(dt), DATE_GET_HOUR(dt),
DATE_GET_MINUTE(dt), DATE_GET_MINUTE(dt),
DATE_GET_SECOND(dt)); DATE_GET_SECOND(dt));
assert(bufflen >= x);
if (us) if (us)
PyOS_snprintf(buffer + 8, bufflen - 8, ".%06d", us); x += PyOS_snprintf(buffer + x, bufflen - x, ".%06d", us);
assert(bufflen >= x);
return buffer + x;
} }
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
...@@ -4200,8 +4205,8 @@ datetime_isoformat(PyDateTime_DateTime *self, PyObject *args, PyObject *kw) ...@@ -4200,8 +4205,8 @@ datetime_isoformat(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
cp = isoformat_date((PyDateTime_Date *)self, buffer, sizeof(buffer)); cp = isoformat_date((PyDateTime_Date *)self, buffer, sizeof(buffer));
assert(cp != NULL); assert(cp != NULL);
*cp++ = sep; *cp++ = sep;
isoformat_time(self, cp, sizeof(buffer) - (cp - buffer)); cp = isoformat_time(self, cp, sizeof(buffer) - (cp - buffer));
result = PyString_FromString(buffer); result = PyString_FromStringAndSize(buffer, cp - buffer);
if (result == NULL || ! HASTZINFO(self)) if (result == NULL || ! HASTZINFO(self))
return result; return result;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment