Page MenuHomePhabricator

Add support for "months" to Language::formatDuration
Open, Needs TriagePublic

Description

Language::formatDuration formats date intervals in seconds to human-readable strings like "5 days, 2 hours and 8 seconds".

It supports a number of time intervals like "years", "weeks", 'days" but not "months". I suspect this is complicated because months are irregular but from the user's perspective a string like "2 months and 4 days" [ago] makes perfect sense even though it can be ambiguous[1].

[1] On March 31, "1 month ago" refers to when exactly?

This change would be useful on the newcomer homepage, which is a feature to help newcomers get oriented when they first create their account, so they can figure out how to start editing quickly. In particular, in the parts of the homepage that say how the long the user has had their account, and that say how long since their mentor has been active.

Event Timeline

The Growth team is considering this task for the hackathon. We're happy to collaborate with other participants on this.

@SBisson: The Stockholm Hackathon or the Prague Hackathon? Just doublechecking.

@SBisson: The Stockholm Hackathon or the Prague Hackathon? Just doublechecking.

The Prague hackathon. I picked the wrong tag initially then I batch updated the tasks but missed this one. Thanks for catching it.

kostajh subscribed.

Moving to External as it seems like this is best managed by the stewards of the MediaWiki-Internationalization board, and I don't think Growth-Team has an urgent need for this task nor time to work on it in the short-to-medium term.

I think we can simply assume that a month is 30 days long. That way we end up with 12.2 months in a year, but that still rounds to 12.

I think we can simply assume that a month is 30 days long. That way we end up with 12.2 months in a year, but that still rounds to 12.

That would mean July 1 was one month ago compared to July 31, and July 31 was one month and one day ago compared to August 31. A bit weird although not terrible. And it should work for locales with non-Gregorian calendars as well, which all have similar month lengths.

That would mean July 1 was one month ago compared to July 31, and July 31 was one month and one day ago compared to August 31. A bit weird although not terrible. And it should work for locales with non-Gregorian calendars as well, which all have similar month lengths.

Yea, if you look at the dates, it's odd. But I think the idea is that peole just want to get a sense of "how long ago" this way, and for that purpose, it's fine I think.

Actually, for this purpose, it would be fine to just omit the days completely...

Alternatively, we can just look at year, month and day as three integers, and calculate the output based on that. In that case, we would drop suppor for weeks.

Change #1026987 had a related patch set uploaded (by Addshore; author: Addshore):

[mediawiki/core@master] Add months as duration to Language:formatDuration

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

Change #1027058 had a related patch set uploaded (by Addshore; author: Addshore):

[mediawiki/core@master] Add Language formatDurationBetweenTimestamps

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

Change #1026987 merged by jenkins-bot:

[mediawiki/core@master] Add months as duration to Language:formatDuration

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

Change #1027065 had a related patch set uploaded (by Ollie Shotton; author: Ollie Shotton):

[mediawiki/core@master] Add Language formatDurationBetweenTimestamps

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

Change #1027058 abandoned by Addshore:

[mediawiki/core@master] Add Language formatDurationBetweenTimestamps

Reason:

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

Change #1027065 merged by jenkins-bot:

[mediawiki/core@master] Add Language::formatDurationBetweenTimestamps method

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

The "weeks" support drop caused T365530 in the mentor dashboard from GrowthExperiments. That's been already handled but maybe we should review for existing callers more scrupulously.