Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2738a64

Browse files
committed
Fix regression due to changeset 2096158376e5 (issue #13305).
1 parent e695eec commit 2738a64

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

Lib/xmlrpc/client.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,33 @@ def __repr__(self):
250250
# Wrapper for XML-RPC DateTime values. This converts a time value to
251251
# the format used by XML-RPC.
252252
# <p>
253-
# The value can be given as a string in the format
254-
# "yyyymmddThh:mm:ss", as a 9-item time tuple (as returned by
253+
# The value can be given as a datetime object, as a string in the
254+
# format "yyyymmddThh:mm:ss", as a 9-item time tuple (as returned by
255255
# time.localtime()), or an integer value (as returned by time.time()).
256256
# The wrapper uses time.localtime() to convert an integer to a time
257257
# tuple.
258258
#
259-
# @param value The time, given as an ISO 8601 string, a time
260-
# tuple, or a integer time value.
259+
# @param value The time, given as a datetime object, an ISO 8601 string,
260+
# a time tuple, or an integer time value.
261+
262+
263+
# Issue #13305: different format codes across platforms
264+
_day0 = datetime(1, 1, 1)
265+
if _day0.strftime('%Y') == '0001': # Mac OS X
266+
def _iso8601_format(value):
267+
return value.strftime("%Y%m%dT%H:%M:%S")
268+
elif _day0.strftime('%4Y') == '0001': # Linux
269+
def _iso8601_format(value):
270+
return value.strftime("%4Y%m%dT%H:%M:%S")
271+
else:
272+
def _iso8601_format(value):
273+
return value.strftime("%Y%m%dT%H:%M:%S").zfill(17)
274+
del _day0
275+
261276

262277
def _strftime(value):
263278
if isinstance(value, datetime):
264-
return value.strftime("%Y%m%dT%H:%M:%S")
279+
return _iso8601_format(value)
265280

266281
if not isinstance(value, (tuple, time.struct_time)):
267282
if value == 0:
@@ -288,7 +303,7 @@ def make_comparable(self, other):
288303
o = other.value
289304
elif isinstance(other, datetime):
290305
s = self.value
291-
o = other.strftime("%Y%m%dT%H:%M:%S")
306+
o = _iso8601_format(other)
292307
elif isinstance(other, str):
293308
s = self.value
294309
o = other

0 commit comments

Comments
 (0)