Commit daedce19 authored by Andreas Jung's avatar Andreas Jung

strftime() accepts unicode format strings again

parent 5c847fc9
...@@ -1488,9 +1488,20 @@ class DateTime: ...@@ -1488,9 +1488,20 @@ class DateTime:
tzdiff = _tzoffset(ltz, self._t) - _tzoffset(self._tz, self._t) tzdiff = _tzoffset(ltz, self._t) - _tzoffset(self._tz, self._t)
zself = self + tzdiff/86400.0 zself = self + tzdiff/86400.0
microseconds = int((zself._second - zself._nearsec) * 1000000) microseconds = int((zself._second - zself._nearsec) * 1000000)
return datetime(zself._year, zself._month, zself._day, zself._hour,
# Note: in older version strftime() accept also unicode strings
# as format strings (just because time.strftime() did not perform
# any type checking). So we convert unicode strings to utf8,
# pass them to strftime and convert them back to unicode if necessary
format_is_unicode = False
if isinstance(format, unicode):
format = format.encode('utf-8')
format_is_unicode = True
ds = datetime(zself._year, zself._month, zself._day, zself._hour,
zself._minute, int(zself._nearsec), zself._minute, int(zself._nearsec),
microseconds).strftime(format) microseconds).strftime(format)
return format_is_unicode and unicode(ds, 'utf-8') or ds
# General formats from previous DateTime # General formats from previous DateTime
def Date(self): def Date(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment