Page MenuHomePhabricator

Language::getHumanTimestamp does not do what it says it should do
Open, Needs TriagePublic

Description

Language::getHumanTimestamp does not work. With one Timestamp it just gives the day date (4 april). With another it returns nothing when not logged in, or the full formatted string when logged in (2015-11-30T02:49:14 following date format settings).

It also does not add an 'ago' to the end, nor does it put an amount of days or whatever past (such as '19 days ago', which I would have expected from the 4 april one)

It does, however, follow the date format preferences, which does not make sense either.

Event Timeline

Test case:

> $lang = Language::factory( 'en' ); $time = new MWTimestamp( '20151115000000' ); echo $lang->getHumanTimestamp( $time );
00:00, 15 November 2015

Expected result: something like "5 months ago" or so. Or anything that matches the documentation, really, which claims:

	 * Get the timestamp in a human-friendly relative format, e.g., "3 days ago".
	 *
	 * Determine the difference between the timestamp and the current time, and
	 * generate a readable timestamp by returning "<N> <units> ago", where the
	 * largest possible unit is used.

I don't see the word "ago" in the output anywhere, no matter how hard I look.

Tested both on the ShoutWiki codebase (latest 1.26) as well as on my Labs instance, which is running a somewhat outdated 1.27alpha build. Same unexpected/unwanted result on both instead of the desired result.

// Timestamps are in different years: use full timestamp
// Also do full timestamp for future dates

That looks like it may be at fault here, since you're testing with a date from last year.

			// Timestamps are in same year,  but more than 5 days ago: show day and month only.

And that too.

So what you're saying it it only does what it says it will (Get the timestamp in a human-friendly relative format, e.g., "3 days ago") if it's under four days old?

That is incredibly misleading.

Basically, the doc commen is incomplete description of what it does, as half of the description is in inline comments that do not get reflected in the docs. :(

I would recommend a combination of updating the doc comment and... Probably not having the exception for things over 5 days old, which seems oddish.

Relative timestamps offer diminishing returns and increasing costs the farther the time gets (see tracking bug), which is probably the reason of the "exception". A more accurate name would probably be maybeGetMoreConciseTimestamp(), given the goal of those who developed this function was apparently to reduce the total screen estate taken by timestamps in the most common cases.

Any system relying on "ago" is bound to be untranslatable in some languages, so any expansion of that construction should come only after ensuring its actual translatability in several languages.