Edgewall Software
Modify

Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#1081 closed defect (fixed)

strftime uses locale-dependant encoding

Reported by: arnarb@… 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 arnarb@…, 19 years ago

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):

return unicode(original_strftime(format,t), 'iso8859-1').encode('utf-8')

time.strftime = strftime_utf8 %%

comment:2 by arnarb@…, 19 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 anonymous, 19 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:4 by Christopher Lenz, 19 years ago

#1086 has been marked as duplicate of this ticket.

comment:5 by Christopher Lenz, 19 years ago

#1499 has been marked as duplicate of this ticket.

comment:6 by Vincent, 19 years ago

Do the change on source:util.py so it works everywhere

comment:7 by Christopher Lenz, 19 years ago

Milestone: 0.9
Owner: changed from Jonas Borgström to Christopher Lenz
Status: newassigned

comment:8 by Christopher Lenz, 19 years ago

Resolution: fixed
Status: assignedclosed

Should be fixed in [2251].

comment:9 by anonymous, 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 anonymous, 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.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christopher Lenz.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christopher Lenz to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.