#1081 closed defect (fixed)
strftime uses locale-dependant encoding
Reported by: | Owned by: | Christopher Lenz | |
---|---|---|---|
Priority: | normal | Milestone: | 0.9 |
Component: | general | Version: | devel |
Severity: | normal | Keywords: | strftime locale encoding |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
Throughout trac, strftime is used to format dates/times. The user has however no control over what encoding strftime returns it string in since that is a feature of the underlying C-library. In most cases, the default encoding for the current locale is used.
I use UTF-8 for my trac deployment since that is most compatible with strings from the Subversion system. Dates are however always returned in latin1 encoding since my loacle is latin1-based (there is no utf8 encoding for IS locale available yet).
Trac should centralize date/time formatting in a single module wrapping strftime and friends, and ensure that the formatted dates are returned with the right encoding. I think this would also make date/time formatting more flexible and easy to manipulate by the user, and beneficial for other things as well.
Attachments (0)
Change History (10)
comment:1 by , 20 years ago
comment:2 by , 20 years ago
The formating above was supposed to be: {{ import time original_strftime = time.strftime def strftime_utf8(format, t=None):
return unicode(original_strftime(format,t), 'iso8859-1').encode('utf-8') time.strftime = strftime_utf8
}}
Sorry.
comment:3 by , 20 years ago
I'm probably retarded..
import time original_strftime = time.strftime def strftime_utf8(format, t=None): return unicode(original_strftime(format,t), 'iso8859-1').encode('utf-8') time.strftime = strftime_utf8
comment:7 by , 19 years ago
Milestone: | → 0.9 |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:8 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Should be fixed in [2251].
comment:9 by , 18 years ago
here's a solution to multi-encoding circumstances:
import locale encoding = locale.getlocale()[1] UTF8time = time.strftime(format,t).decode(encoding)
note that locale.setlocale() may have to be used prior.
comment:10 by , 18 years ago
i must be retarded as well…
import locale encoding = locale.getlocale()[1] UTF8time = time.strftime(format,t).decode(encoding)
note that locale.setlocale() may have to be used prior.
In the meantime, a workaround is to rebind time.strftime to a function that returns a correctly encoded string.
In my case, I added this to the top of ModPythonHandler.py: %% import time original_strftime = time.strftime def strftime_utf8(format, t=None):
time.strftime = strftime_utf8 %%