#38 framework: make date format locale specific
Merged by plautrba. Opened by vmojzis.
vmojzis/setroubleshoot date  into  master

Download 38.patch

Hardcoded date format may cause confusion in non-english locales since
both the order of items and delimiters differ between locales.

Before:
en_US: Wed Mar 25, 2020 07:40 EDT
ja_JP: 水 3月 25, 2020 07:40 EDT
cs_CZ: St bře 25, 2020 07:40 EDT
After:
en_US: Wed 25 Mar 2020 12:24:22 PM CET
ja_JP: 2020年03月25日 12時24分22秒
cs_CZ: St 25. března 2020, 12:24:22

Would it be possible and simper to use datetime.strftime("%c %Z") ? https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior

Would it be possible and simper to use datetime.strftime("%c %Z") ? https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior

That looks better, except for the en_US locale, where it shows the %Z twice because
%c in this locale expands into "'%a %d %b %Y %r %Z"

>>> locale.setlocale(locale.LC_TIME, "ja_JP.UTF-8")
>>> print(time.strftime("%c %Z"))
2020年03月24日 12時35分40秒 EDT
>>> locale.setlocale(locale.LC_TIME, "cs_CZ.UTF-8")
>>> print(time.strftime("%c %Z"))
Út 24. března 2020, 12:53:35 EDT
>>> locale.setlocale(locale.LC_TIME, "en_US.UTF-8")
>>> print(time.strftime("%c %Z"))
Tue 24 Mar 2020 12:50:39 PM EDT EDT

I could use

locale.nl_langinfo(locale.D_T_FMT)

(which produces expanded version of %c) and cut off the %Z if it is present, but I'm not sure if that wouldn't break with some other locale.

Could we just drop %Z format string? It looks like a zone is used whenever it's expected so we would follow locale defaults instead of adding zone when it's not expected.

Simply setting the date_format to "%x %X %Z" would, however, serve the same purpose as the submitted code.

I am wondering if the time zone name is really necessary. It seems that it was probably introduced because it's customary to show it in the US. Using date_format = "%c" seems to produce the best results (most verbose and locale specific).
I'll ask the localization team.

Could we just drop %Z format string? It looks like a zone is used whenever it's expected so we would follow locale defaults instead of adding zone when it's not expected.

Sorry, agree, I was just writing the same thing.

:thumbsup: :dollar:

rebased onto 74ad075c2c4ac6b2e99cebff3edb2e86febf65ec

Updated.

rebased onto faff25140908a594c74c82f8b63ccc4436610be1

Updated and tested.

Thanks!

Pull-Request has been merged by plautrba

Metadata