Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
baf853c5
Commit
baf853c5
authored
May 31, 2007
by
Walter Dörwald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change timedelta.__str__() to return a unicode object.
parent
bafa137c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
36 deletions
+19
-36
Modules/datetimemodule.c
Modules/datetimemodule.c
+19
-36
No files found.
Modules/datetimemodule.c
View file @
baf853c5
...
...
@@ -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__. */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment