mirror of
https://github.com/django/django.git
synced 2025-07-05 10:19: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."
|
"Implementation of tzinfo classes for use with datetime.datetime."
|
||||||
|
|
||||||
|
import locale
|
||||||
import time
|
import time
|
||||||
from datetime import timedelta, tzinfo
|
from datetime import timedelta, tzinfo
|
||||||
from django.utils.encoding import smart_unicode
|
from django.utils.encoding import smart_unicode
|
||||||
|
|
||||||
|
DEFAULT_ENCODING = locale.getdefaultlocale()[1]
|
||||||
|
|
||||||
class FixedOffset(tzinfo):
|
class FixedOffset(tzinfo):
|
||||||
"Fixed offset in minutes east from UTC."
|
"Fixed offset in minutes east from UTC."
|
||||||
def __init__(self, offset):
|
def __init__(self, offset):
|
||||||
@ -26,7 +29,7 @@ class LocalTimezone(tzinfo):
|
|||||||
"Proxy timezone information from time module."
|
"Proxy timezone information from time module."
|
||||||
def __init__(self, dt):
|
def __init__(self, dt):
|
||||||
tzinfo.__init__(self, dt)
|
tzinfo.__init__(self, dt)
|
||||||
self._tzname = smart_unicode(time.tzname[self._isdst(dt)])
|
self._tzname = self.tzname(dt)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self._tzname
|
return self._tzname
|
||||||
@ -44,7 +47,10 @@ class LocalTimezone(tzinfo):
|
|||||||
return timedelta(0)
|
return timedelta(0)
|
||||||
|
|
||||||
def tzname(self, dt):
|
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):
|
def _isdst(self, dt):
|
||||||
tt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)
|
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