[PATCH] date representation: use ISO8601 rather than a specific locale

Thomas De Schampheleire patrickdepinguin at gmail.com
Fri Mar 6 11:08:21 EST 2015


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

?

>>>
>> config/conf.py actually contains definitions DATETIME_FORMAT and
>> DATE_FORMAT, included from lib/helpers.py but not used:
>>
>> DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
>> DATE_FORMAT = "%Y-%m-%d"
>>
>> We should probably use that instead.
>
>
> Agreed. They seems to be unused and could be removed, but having constants
> as constants seems nice ;-)
>
>> What is the feedback on this patch?
>
>
> No objections - I would push it soon ... but I guess you will post an
> updated version?

Yes, I will update, awaiting your answers to my latest questions...

Thanks,
Thomas


More information about the kallithea-general mailing list