[PATCH] date representation: use ISO8601 rather than a specific locale
Mads Kiilerich
mads at kiilerich.com
Fri Mar 6 11:16:48 EST 2015
On 03/06/2015 05:08 PM, Thomas De Schampheleire wrote:
> On Fri, Mar 6, 2015 at 4:31 PM, Mads Kiilerich <mads at kiilerich.com> wrote:
>> On 03/06/2015 02:03 PM, Thomas De Schampheleire wrote:
>>> On Thu, Feb 26, 2015 at 10:51 PM, Thomas De Schampheleire
>>> <patrickdepinguin at gmail.com> wrote:
>>>> # HG changeset patch
>>>> # User Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
>>>> # Date 1424987487 -3600
>>>> # Thu Feb 26 22:51:27 2015 +0100
>>>> # Node ID d80090d1053468f6b84eb8ef41c62446995ddb73
>>>> # Parent c7f97c237dacbed8770d4aacf20feb8175ee8d99
>>>> date representation: use ISO8601 rather than a specific locale
>>>>
>>>> Dates, in particular in technical systems like Kallithea, are
>>>> better shown in a clear concise format like ISO8601 (YYYY-MM-DD)
>>>> than in a verbose format like 'Thu, Feb 26 2015'.
>>>>
>>>> This commit changes all dates to ISO8601.
>>>>
>>>> ---
>>>> If desired, we could create two functions: one that returns ISO format
>>>> and
>>>> another for the locale format. Depending on the usage, one or the other
>>>> is
>>>> shown. I'm not very fond of that though, it looks inconsistent.
>>>>
>>>> diff --git a/kallithea/lib/helpers.py b/kallithea/lib/helpers.py
>>>> --- a/kallithea/lib/helpers.py
>>>> +++ b/kallithea/lib/helpers.py
>>>> @@ -469,7 +469,7 @@
>>>>
>>>> def fmt_date(date):
>>>> if date:
>>>> - _fmt = u"%a, %d %b %Y %H:%M:%S".encode('utf8')
>>
>> Heh - making a const unicode string with all ascii chars and then encoding
>> it to utf8 ... that seems a bit convoluted ;-)
>>
>> It does however raise the question of how this function was supposed to
>> handle locales where the name of the day or month had unicode chars.
>>
>> With your changes it will always only be ascii chars and it would perhaps be
>> more clear to use unicode(...) instead of .decode.
>>
>>>> + _fmt = u"%Y-%m-%d %H:%M:%S".encode('utf8')
>>>> return date.strftime(_fmt).decode('utf8')
> I'm not very familiar with unicode and didn't really understand that
> part of the original code, to be honest.
>
> Do you mean this:
>
> _fmt = "%Y-%m-%d %H:%M:%S"
> return unicode(date.strftime(_fmt))
>
> and thus finally simply:
>
> return unicode(date.strftime(DATETIME_FORMAT))
Yes, i did.
That will however apparently also put an "invisible" constraint on
DATETIME_FORMAT; it must be unicode-able without specifying encoding.
I think the big unknown for me is whether datetime.datatime strftime
ever can be localized and return unicode strings or if it always will be
in english and thus be pure ascii that trivially converts to unicode.
Perhaps also whether it will return a unicode string if it is given a
unicode format string.
/Mads
More information about the kallithea-general
mailing list