Page MenuHomePhabricator

Impact Module - longest streak date formatting
Closed, ResolvedPublicBUG REPORT

Description

Reported by @Dyolf77_WMF

Steps to replicate the issue

What happens?:
Current date format is year/day/month

What should have happened instead?:
Arabic format should be: day/month/year

Other information

https://translatewiki.net/wiki/MediaWiki:Growthexperiments-homepage-impact-scores-best-streak-info-data-text/ar

Let's follow "Date format" in preferences if possible.

Event Timeline

KStoller-WMF triaged this task as Low priority.

@Dyolf77_WMF - feel free to add more details or change the description if I missed something. Thanks!

@Sgs I just noticed that you were way ahead of us on this, and mentioned this in the Positive Reinforcement Copy Doc. Thanks for thinking ahead. :)
Let me know if we need to revise the formatting of that string to make it easier to localize.

Should we follow user's date format, which can be customized in preferences? Granted, newcomers are not likely to customize that, but the wiki default date format is presumably acceptable for that wiki's language?

Should we follow user's date format, which can be customized in preferences? Granted, newcomers are not likely to customize that, but the wiki default date format is presumably acceptable for that wiki's language?

That seems ideal to me. I'll add that to the acceptance criteria.

KStoller-WMF renamed this task from Impact Module - date formatting to Impact Module - longest streak date formatting.Nov 19 2022, 4:44 AM
KStoller-WMF raised the priority of this task from Low to Medium.

Rendering a date range involves several questions:

  • How do you separate the parts of the date? (E.g. in English you'd use an em dash with spaces, in Hungarian an en dash without spaces.) Modern Javascript supports it via Intl.DateTimeFormat.formatRange. I don't think there's anything similar in PHP; IntlDateFormatter is fairly similar (uses CLDR like the JS Intl) but doesn't have anything for ranges.
  • How do you format the start and end of the range? PHP and JS Intl seems roughly comparable (unsurprisingly as both are CLDR-based): you get to select short/long/numeric for each component of the date. or short/long/full for the whole date, and then it tries to produce a pattern that's native for the given locale and matches those options. On the server side, there are extra user preferences for full dates, but only for full dates, and TBH I'm not sure what they are supposed to accomplish as usually exactly one of those formats is actually correct for the given locale (e.g. you can switch between dmY and mdY in English, but then we also have a separate en-GB language), so I think it's fine to ignore them.
  • How do you "deduplicate" the start and end of the range (e.g. say "2022 Nov 17 — 19" instead of "2022 Nov 17 — 2022 Nov 19")? Since PHP doesn't support range formatting, it does not support this either. JS Intl seems to be quite intelligent, it can decide based on what format it is using whether deduplication makes sense:
const dates = [ new Date(2000, 0, 10), new Date(2000, 0, 15) ];
const fmt1 = { year: 'numeric', month: 'numeric', day: 'numeric' };
const fmt2 = { year: 'numeric', month: 'short', day: 'numeric' };
console.log(new Intl.DateTimeFormat('en', fmt1).formatRange(...dates));
// "1/10/2000 – 1/15/2000"
console.log(new Intl.DateTimeFormat('en', fmt2).formatRange(...dates));
// "Jan 10 – 15, 2000"
  • How do you "deduplicate" the start and end from current time (e.g. say "Nov 17 — 19" instead of "2022 Nov 17 — 19" if the current year is 2022)? This would have to be hand-initiated, but is achievable with a format option like { month: 'short', day: 'numeric' } (omitting the year equals to hiding it, but only if it's the same it both ends of the range). Is that format going to be sensible for all languages? Not sure ({ dateStyle: 'medium' } would have been more robust but there is no way to start with that and remove the year) bur seems like a reasonable bet.
  • How do you determine the year/month/day (which depends on the calendar the given locale uses)? PHP only supports Gergorian, MediaWiki adds support for several other calendars (see Language::sprintfDate()) but the format string need to specify the format and calendar used. JS Intl seems to support this out of the box:
console.log(new Intl.DateTimeFormat('fa', fmt2).formatRange(...dates));
// "۲۰ تا ۲۵ دی ۱۳۷۸" — ‎۱۳۷۸ is 1378 with Persian numerals

So, JS wins this hands down. We can use formatRange with { dateStyle: 'medium' } or { month: 'short', day: 'numeric' } depending on whether the date range is in the current year. That itself is a bit tricky to determine due to being calendar-dependent, but we can just use the { year: 'numeric' } formatting option and compare the end date and current time.

Change 860824 had a related patch set uploaded (by Gergő Tisza; author: Gergő Tisza):

[mediawiki/extensions/GrowthExperiments@master] NewImpact: Use locale-aware date range formatting for longest streak

https://gerrit.wikimedia.org/r/860824

Change 860824 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@master] NewImpact: Use locale-aware date range formatting for longest streak

https://gerrit.wikimedia.org/r/860824

Etonkovidova subscribed.

Checked in testwiki wmf.19 with uselang=ar - the date format looks as fixed (@Dyolf77_WMF - if you see some issues, please feel free to re-open the task):

Screen Shot 2023-01-20 at 11.48.11 AM.png (938×496 px, 75 KB)


Should we follow user's date format, which can be customized in preferences? Granted, newcomers are not likely to customize that, but the wiki default date format is presumably acceptable for that wiki's language?

Yes, default date format should be ok for any wiki. Currently, the user-set date format is reflected in RC/Warchlist/Contributions/View history/Logs. MentorDashboard doesn't adjust Date of registration column date format for user preferences.
Longest streak date format doesn't reflect user preferences.