Skip to content

Commit 840f3a8

Browse files
committed
fix time_repr
1 parent a3c165b commit 840f3a8

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Modules/_datetimemodule.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4896,22 +4896,21 @@ time_repr(PyObject *op)
48964896
int fold = TIME_GET_FOLD(self);
48974897
PyObject *result = NULL;
48984898

4899-
if (ns)
4900-
result = PyUnicode_FromFormat("%s(%d, %d, %d, %d, %d)",
4901-
type_name, h, m, s, us, ns);
4902-
else if (us)
4899+
if (us)
49034900
result = PyUnicode_FromFormat("%s(%d, %d, %d, %d)",
49044901
type_name, h, m, s, us);
49054902
else if (s)
49064903
result = PyUnicode_FromFormat("%s(%d, %d, %d)",
49074904
type_name, h, m, s);
49084905
else
49094906
result = PyUnicode_FromFormat("%s(%d, %d)", type_name, h, m);
4910-
if (result != NULL && HASTZINFO(self))
4911-
result = append_keyword_tzinfo(result, self->tzinfo);
4907+
if (result != NULL && ns)
4908+
result = append_keyword_nanosecond(result, ns);
49124909
if (result != NULL && fold)
49134910
result = append_keyword_fold(result, fold);
4914-
return result;
4911+
if (result == NULL || ! HASTZINFO(self))
4912+
return result;
4913+
return append_keyword_tzinfo(result, self->tzinfo);
49154914
}
49164915

49174916
static PyObject *
@@ -6382,10 +6381,10 @@ datetime_repr(PyObject *op)
63826381
GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
63836382
DATE_GET_HOUR(self), DATE_GET_MINUTE(self));
63846383
}
6385-
if (baserepr != NULL && DATE_GET_FOLD(self) != 0)
6386-
baserepr = append_keyword_fold(baserepr, DATE_GET_FOLD(self));
63876384
if (baserepr != NULL && DATE_GET_NANOSECOND(self) != 0)
63886385
baserepr = append_keyword_nanosecond(baserepr, DATE_GET_NANOSECOND(self));
6386+
if (baserepr != NULL && DATE_GET_FOLD(self) != 0)
6387+
baserepr = append_keyword_fold(baserepr, DATE_GET_FOLD(self));
63896388
if (baserepr == NULL || ! HASTZINFO(self))
63906389
return baserepr;
63916390
return append_keyword_tzinfo(baserepr, self->tzinfo);

0 commit comments

Comments
 (0)