summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2007-05-31 18:42:47 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2007-05-31 18:42:47 (GMT)
commitbaf853c5376b9fbbf4f8644de756e36778b3a2be (patch)
tree1fed98693fc495d64ab2a8cb9dddcb44b302993b /Modules
parentbafa137c7e283acd810d7026363352249d2ac947 (diff)
downloadcpython-baf853c5376b9fbbf4f8644de756e36778b3a2be.zip
cpython-baf853c5376b9fbbf4f8644de756e36778b3a2be.tar.gz
cpython-baf853c5376b9fbbf4f8644de756e36778b3a2be.tar.bz2
Change timedelta.__str__() to return a unicode object.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/datetimemodule.c55
1 files changed, 19 insertions, 36 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index c355bb9..d39791a 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -1987,47 +1987,30 @@ delta_repr(PyDateTime_Delta *self)
static PyObject *
delta_str(PyDateTime_Delta *self)
{
- int days = GET_TD_DAYS(self);
- int seconds = GET_TD_SECONDS(self);
int us = GET_TD_MICROSECONDS(self);
- int hours;
- int minutes;
- char buf[100];
- char *pbuf = buf;
- size_t buflen = sizeof(buf);
- int n;
-
- minutes = divmod(seconds, 60, &seconds);
- hours = divmod(minutes, 60, &minutes);
+ int seconds = GET_TD_SECONDS(self);
+ int minutes = divmod(seconds, 60, &seconds);
+ int hours = divmod(minutes, 60, &minutes);
+ int days = GET_TD_DAYS(self);
if (days) {
- n = PyOS_snprintf(pbuf, buflen, "%d day%s, ", days,
- (days == 1 || days == -1) ? "" : "s");
- if (n < 0 || (size_t)n >= buflen)
- goto Fail;
- pbuf += n;
- buflen -= (size_t)n;
- }
-
- n = PyOS_snprintf(pbuf, buflen, "%d:%02d:%02d",
- hours, minutes, seconds);
- if (n < 0 || (size_t)n >= buflen)
- goto Fail;
- pbuf += n;
- buflen -= (size_t)n;
-
- if (us) {
- n = PyOS_snprintf(pbuf, buflen, ".%06d", us);
- if (n < 0 || (size_t)n >= buflen)
- goto Fail;
- pbuf += n;
+ if (us)
+ return PyUnicode_FromFormat("%d day%s, %d:%02d:%02d.%06d",
+ days, (days == 1 || days == -1) ? "" : "s",
+ hours, minutes, seconds, us);
+ else
+ return PyUnicode_FromFormat("%d day%s, %d:%02d:%02d",
+ days, (days == 1 || days == -1) ? "" : "s",
+ hours, minutes, seconds);
+ } else {
+ if (us)
+ return PyUnicode_FromFormat("%d:%02d:%02d.%06d",
+ hours, minutes, seconds, us);
+ else
+ return PyUnicode_FromFormat("%d:%02d:%02d",
+ hours, minutes, seconds);
}
- return PyString_FromStringAndSize(buf, pbuf - buf);
-
- Fail:
- PyErr_SetString(PyExc_SystemError, "goofy result from PyOS_snprintf");
- return NULL;
}
/* Pickle support, a simple use of __reduce__. */