Page MenuHomePhabricator

jquery.tablesorter should sort plain year digits as date
Open, LowPublic

Description

In some rows of sortable tables stay not the full qualified date, but only the year is known. The enhanchment is, that this is detected by tablesorter. Example:

{| class="wikitable sortable"
! data-sort-type="date" |"Date" 
|-
| 1. 1. 2000
|-
| 2011
|-
| about 1900
|-
| 2010<ref>cite</ref>
|}

Today (2013-01-25) only the first row is a 'date'. To prevent mistake in auto detecting parser this should work only if data-sort-type="date" is spezified.

Sugestion: add folow code at row 926 in jquery.tablesorter.js:
} else if ( ( match = s.match( new RegExp( /(\d{2,4})/) ) ) !== null ) { // only year
s = [ match[1], '99', '99' ];

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 1:15 AM
bzimport set Reference to bz44818.
bzimport added a subscriber: Unknown Object (MLST).

IMHO "Month Year" should be recognized, too.

There is an assortment of enhancements that could be made.

1: Add support for AD/BC
2: Add support for month/year
3: Add support for year only
4: Do something more intelligent with / - ' ' usage ?
5: Write testcases (Really this would help so much...)
6: Fix isoDate to be able to use time notation and timezones.

It's not really hard to do, someone just has to do it. Biggest thing to remember is that table sorter uses 2 functions for everything. One simple function with a simple regex for auto detecting the type of a column based on the first 3 cells, and a second function with logic for calculating the actual sortkey.

Also, there is a lot of inspiration for regex'es perhaps in https://github.com/Mottie/tablesorter

This is a fork of the tablesorter 2.0 version, that seems to be the most well maintained version atm. It has diverted a lot from table sorter in MW, but a lot of the regexes and test cases might still be useful for anyone who wants to dabble in it.

It does require paying attention though. We have also fixed some bugs already, and we don't want to break those situations again (and that is hard to test, since we have few testcases on the regexes atm.

I'm working on the date parser. I think we need a language setting like mw.language.months.names for BC era to detect years before year 0.

Might be, but i'll just note that date parsing (internationally) is simply incredibly difficult and takes up a lot of (slow) code. moment.js is KBs of code and even that doesn't support BC notations as far as I'm aware. Hard problems be hard problems.

Change 426748 had a related patch set uploaded (by MatthiasDD; owner: MatthiasDD):
[mediawiki/core@master] jquery.tablesorter: Improve date parser (only year, BC/AD, asianDate)

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

We should discuss if we need really:

  1. guesstimate centurys (read year 70 as 1970). This is problematic with old years and can imho abandoned.
  2. Year BC detection. It's difficult to test it in all languages. I have used the wikidata object Q39085.
  3. Variable yearBC is stored in mw.language.data because it is language specific. We can use later wgUserLanguage instead of wgPageContentLanguage? Used variable wgDefaultDateFormat and tableSorterCollation is stored in mw.config - why? (RFC)

I'm write now some tests for jquery.tablesorter.test.js.

read year 70 as 1970

The problem with that is that also the native Date parsers of some browsers interpret this as 1970 I think.

Used variable wgDefaultDateFormat and tableSorterCollation is stored in mw.config - why? (RFC)

Because no one fixed it yet :)

We can use later wgUserLanguage instead of wgPageContentLanguage?

Why ? It's content, why would we use the interface language ? Well, you could make the setup depend what we are initialising for, but for wikitable as a generic class in content, wgPageContentLanguage seems appropriate. If the contents language diverges from the wgPageContentLanguage, we should probably have like a data-sort-language attribute or something.

Also, when you work on this, please note that there might be differences between browsers, so run the testcases on multiple browsers, not just on jenkins.

@MatthiasDD: Hi! This task has been assigned to you a while ago. Could you maybe share an update? Do you still plan to work on this task, or do you need any help?

@MatthiasDD: No reply, hence unassigning task (plus Phab account seems to have an invalid email address).