Signal-Android icon indicating copy to clipboard operation
Signal-Android copied to clipboard

Date format does not respect locale

Open 2-4601 opened this issue 11 years ago • 11 comments

Currently TS seems to display all dates in the format MMM d, yyyy irrespective of the locale. The dates are translated correctly though.

Here's some information about date formats in various regions: https://en.wikipedia.org/wiki/Date_format_by_country

TS 2.13.0 This issue does not depend on whether you have changed the system language or TS language. Neither work.

2-4601 avatar May 04 '15 13:05 2-4601

If it's the same issue like #2684 it has been fixed in https://github.com/WhisperSystems/TextSecure/commit/d8521637bb2a545d02d2b7a32127a4f01b6d0317

agrajaghh avatar May 04 '15 15:05 agrajaghh

That should be fixed in 2.13.0 beta release, right?

I searched only open issues before creating this so I didn't see #2684. But that issue seems to be about date translations and not about date formatting? Before 2.13.0 I also experienced that issue but it seems to be fixed now.

This issue is about date formatting which does not respect the locale. This was introduced in 2.13.0. I did not see it before. Possibly because #2684 prevented me from seeing translated dates.

For example the Finnish date format should be d. MMM yyyy and not MMM d, yyyy.

TextSecure shows it wrong. Android (System Settings) gets the date formatting right. svejk

2-4601 avatar May 04 '15 17:05 2-4601

oh sry, yes the commit I mentioned is already in 2.13...

agrajaghh avatar May 04 '15 17:05 agrajaghh

ahhh bummer, I thought this line was supposed to take care of that. thanks for the expected vs actual test vectors, I'll look into it.

rhodey avatar May 04 '15 17:05 rhodey

private static void testLocalizedSimpleDateFormat(String template, Locale locale) {
  Log.d(DateUtils.class.getName(), "LOCALE >> " + locale + ", TEMPLATE >> " + template);
  SimpleDateFormat dateFormat = new SimpleDateFormat(template, locale);
  Log.d(DateUtils.class.getName(), "LOCALE >> " + locale + ", LOCALE TEMPLATE >> " + dateFormat.toLocalizedPattern());
}
DateUtils﹕ LOCALE >> fi, TEMPLATE >> MMM d, yyyy HH:mm:ss zzz
DateUtils﹕ LOCALE >> fi, LOCALE TEMPLATE >> MMM d, yyyy HH:mm:ss zzz

:see_no_evil: Java and Android's date processing stuff is junk. We switched to SimpleDateFormat because android.text.format.DateUtils effectively ignores every Locale arg it is passed and now this. All internet advice tells us to use the new Java 8 APIs or DateFormat.getDateInstance(int,Locale), where int refers to a predefined date format string ie no custom date formats.

upon further inspection of the SimpleDateFormat javadoc I found "SimpleDateFormat does not deal with the localization of text other than the pattern letters; that's up to the client of the class."

rhodey avatar May 04 '15 20:05 rhodey

I've banged my head on the wall and lost a fair amount of sleep when handling dates and timezones in code. Luckily I haven't had to do it with Java :)

The mm/dd format doesn't really bother me that much. Especially when the month is displayed as a word (or abbreviation). If it were all numerals e.g. 05/04 it would be much more confusing for the dd/mm part of the world. But the current format May 4 (or the equivalent translation) is OK.

However the Finnish date in TS is pretty confusing because it uses the full month name in an inflected form that is only valid grammar when the format is dd/mm. So toukokuuta 4 is not just wrong format but also improper language :) The abbreviated format tou 4 would be OK. Even though it's not correct format it's still understandable (less invalid grammar). I don't know why the English month name gets abbreviated to the first three letters while the Finnish month is in a full inflected form.

But this is just one language. Other locales might be broken too. Edit: Just tested and all dd/mm locales have the incorrect format but the month name is a three letter abbreviation. Maybe people will start reporting this when 2.13.0 is released on the Play Store.

2-4601 avatar May 04 '15 21:05 2-4601

Generally in Java, if the canned date formats (SHORT, MEDIUM, LONG, FULL) are insufficient and you want to use a custom date format, localization is painful. Element order, punctuation, abbreviations, prefixes/suffixes, etc. all vary wildly between languages and their respective date forms. Developers are usually left to one of three options:

  1. Create a separate format string for each locale (shoot me now)
  2. Use a library like those in ICU
  3. Settle for ugly localization and hope for the best (Signal's current state)

Android 4.3 (API 18, JELLY_BEAN_MR2) added a method that makes option 2 native, implementing ICU4C in the platform via JNI. On a related note, AOSP Issue 171591 requests adding it to the support library for compatibility with prior platforms and bugfix currency; add a star if you'd like.

I'm submitting a PR that implements this method. The following images include cropped screenshots (Nexus 5, Android 6.0 MRA58K) in English, Korean, German, and Finnish, showing dates in the ConversationList, Conversation, and MessageDetails. @agrajaghh , @2-4601 , what do you think?

Before before

After (only Android 4.3 and above) after

unrulygnu avatar Nov 19 '15 06:11 unrulygnu

definitely better in german, it was just wrong before :blush:

agrajaghh avatar Nov 19 '15 08:11 agrajaghh

Yaaasss! This is glorious work. This makes it correct. Thanks.

Any idea why the Finnish date is displayed with full month name (in an inflected form) while other languages display the short abbreviated form?

Edit: Could the shoot me now option be leveraged to Transifex? Or is it more complicated than just creating a perfect string?

2-4601 avatar Nov 19 '15 15:11 2-4601

@2-4601

Any idea why the Finnish date is displayed with full month name (in an inflected form)

MMM is supposed to render an abbreviated textual month name in all languages. I suspect a dangerous combination of Finnish mischief and beer was involved. :stuck_out_tongue_closed_eyes:

Or is it more complicated

Unfortunately, it is. One of the date formats, for instance, is assembled in steps using multiple conditionals.

unrulygnu avatar Nov 19 '15 16:11 unrulygnu

solved in 3.6.0 for >= 4.3 devices

2-4601 avatar Nov 21 '15 01:11 2-4601