[Zope-Checkins] SVN: Zope/trunk/lib/python/DateTime/DateTime.py strftime() accepts unicode strings again

Andreas Jung andreas at andreas-jung.com
Wed May 25 08:36:55 EDT 2005


Log message for revision 30494:
  strftime() accepts unicode strings again
  

Changed:
  U   Zope/trunk/lib/python/DateTime/DateTime.py

-=-
Modified: Zope/trunk/lib/python/DateTime/DateTime.py
===================================================================
--- Zope/trunk/lib/python/DateTime/DateTime.py	2005-05-24 21:47:17 UTC (rev 30493)
+++ Zope/trunk/lib/python/DateTime/DateTime.py	2005-05-25 12:36:25 UTC (rev 30494)
@@ -1488,10 +1488,22 @@
         tzdiff = _tzoffset(ltz, self._t) - _tzoffset(self._tz, self._t)
         zself  = self + tzdiff/86400.0
         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), 
                microseconds).strftime(format) 
+        return format_is_unicode and unicode(ds, 'utf-8') or ds
 
+
     # General formats from previous DateTime
     def Date(self):
         """Return the date string for the object."""



More information about the Zope-Checkins mailing list