mirror of
https://github.com/django/django.git
synced 2025-07-04 01:39:20 +00:00
unicode: A different version of [5532], based on feedback from Windows users
in far away countries. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5534 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
daaa3a1dde
commit
03ec6423c4
@ -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 @@ class LocalTimezone(tzinfo):
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user