@@ -1700,8 +1700,8 @@ static PyObject *delta_negative(PyObject *op);
17001700
17011701/* Add formatted UTC offset string to buf. buf has no more than
17021702 * buflen bytes remaining. If use_utc_designator is true,
1703- * tzinfo.tzname(tzinfoarg) will be called, and if it returns " UTC" ,
1704- * only " Z\0" will be added. Otherwise, the UTC offset is gotten by calling
1703+ * tzinfo.tzname(tzinfoarg) will be called, and if it returns ' UTC' ,
1704+ * only ' Z\0' will be added. Otherwise, the UTC offset is gotten by calling
17051705 * tzinfo.utcoffset(tzinfoarg). If that returns None, \0 is stored into
17061706 * *buf, and that's all. Else the returned value is checked for sanity (an
17071707 * integer in range), and if that's OK it's converted to an hours & minutes
@@ -1712,8 +1712,8 @@ static PyObject *delta_negative(PyObject *op);
17121712 */
17131713static int
17141714format_utcoffset (char * buf , size_t buflen , const char * sep ,
1715- int use_utc_designator ,
1716- PyObject * tzinfo , PyObject * tzinfoarg )
1715+ int use_utc_designator ,
1716+ PyObject * tzinfo , PyObject * tzinfoarg )
17171717{
17181718 PyObject * offset ;
17191719 int hours , minutes , seconds , microseconds ;
@@ -1722,14 +1722,8 @@ format_utcoffset(char *buf, size_t buflen, const char *sep,
17221722 assert (buflen >= 1 );
17231723
17241724 if (use_utc_designator ) {
1725- PyObject * name = PyObject_CallMethod (tzinfo , "tzname" , "O" , tzinfoarg );
1726- if (name == NULL )
1727- return -1 ;
1728- int tz_is_utc = (PyUnicode_Check (name ) &&
1729- 0 == strcmp ("UTC" , PyUnicode_AsUTF8 (name )));
1730- Py_DECREF (name );
1731-
1732- if (tz_is_utc ) {
1725+ PyObject * name = PyObject_CallMethod (tzinfo , "tzname" , "O" , tzinfoarg );
1726+ if (PyUnicode_Check (name ) && strcmp ("UTC" , PyUnicode_AsUTF8 (name ))) {
17331727 PyOS_snprintf (buf , buflen , "Z" );
17341728 return 0 ;
17351729 }
@@ -1787,6 +1781,7 @@ make_somezreplacement(PyObject *object, char *sep, PyObject *tzinfoarg)
17871781 if (format_utcoffset (buf ,
17881782 sizeof (buf ),
17891783 sep ,
1784+ 0 ,
17901785 tzinfo ,
17911786 tzinfoarg ) < 0 )
17921787 return NULL ;
0 commit comments