Edgewall Software

Ticket #2905: trac_2905.diff

File trac_2905.diff, 1.4 KB (added by cmlenz, 3 years ago)

Patch

  • trac/util/__init__.py

     
    1717# Author: Jonas Borgström <jonas@edgewall.com> 
    1818#         Matthew Good <trac@matt-good.net> 
    1919 
     20import locale 
    2021import md5 
    2122import os 
    2223import re 
     
    173174            t = time.localtime(int(t)) 
    174175 
    175176    text = time.strftime(format, t) 
    176     return to_utf8(text) 
     177    encoding = locale.getlocale(locale.LC_TIME)[1] or \ 
     178               locale.getpreferredencoding() 
     179    return unicode(text, encoding, 'replace') 
    177180 
    178181def format_date(t=None, format='%x', gmt=False): 
    179182    return format_datetime(t, format, gmt) 
     
    184187def get_date_format_hint(): 
    185188    t = time.localtime(0) 
    186189    t = (1999, 10, 29, t[3], t[4], t[5], t[6], t[7], t[8]) 
    187     tmpl = time.strftime('%x', t) 
     190    tmpl = format_date(t) 
    188191    return tmpl.replace('1999', 'YYYY', 1).replace('99', 'YY', 1) \ 
    189192               .replace('10', 'MM', 1).replace('29', 'DD', 1) 
    190193 
    191194def get_datetime_format_hint(): 
    192195    t = time.localtime(0) 
    193196    t = (1999, 10, 29, 23, 59, 58, t[6], t[7], t[8]) 
    194     tmpl = time.strftime('%x %X', t) 
     197    tmpl = format_datetime(t) 
    195198    return tmpl.replace('1999', 'YYYY', 1).replace('99', 'YY', 1) \ 
    196199               .replace('10', 'MM', 1).replace('29', 'DD', 1) \ 
    197200               .replace('23', 'hh', 1).replace('59', 'mm', 1) \