Skip to content
Browse files

unicode: A different version of [5532], based on feedback from Window…

…s users

in far away countries.


git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5534 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent daaa3a1 commit 03ec6423c4850b141730333be4898858e0d45068 @malcolmt malcolmt committed Jun 25, 2007
Showing with 8 additions and 2 deletions.
  1. +8 −2 django/utils/tzinfo.py
View
10 django/utils/tzinfo.py
@@ -1,9 +1,12 @@
"Implementation of tzinfo classes for use with datetime.datetime."
+import locale
import time
from datetime import timedelta, tzinfo
from django.utils.encoding import smart_unicode
+DEFAULT_ENCODING = locale.getdefaultlocale()[1]
+
class FixedOffset(tzinfo):
"Fixed offset in minutes east from UTC."
def __init__(self, offset):
@@ -26,7 +29,7 @@ class LocalTimezone(tzinfo):
"Proxy timezone information from time module."
def __init__(self, dt):
tzinfo.__init__(self, dt)
- self._tzname = smart_unicode(time.tzname[self._isdst(dt)])
+ self._tzname = self.tzname(dt)
def __repr__(self):
return self._tzname
@@ -44,7 +47,10 @@ def dst(self, dt):
return timedelta(0)
def tzname(self, dt):
- return unicode(time.tzname[self._isdst(dt)])
+ try:
+ return smart_unicode(time.tzname[self._isdst(dt)], DEFAULT_ENCODING)
+ except UnicodeDecodeError:
+ return None
def _isdst(self, dt):
tt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)

0 comments on commit 03ec642

Please sign in to comment.
Something went wrong with that request. Please try again.