Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dateparser fails if trailing text #1842

Open
mokraemer opened this issue Jul 24, 2023 · 2 comments
Open

Dateparser fails if trailing text #1842

mokraemer opened this issue Jul 24, 2023 · 2 comments

Comments

@mokraemer
Copy link

if you have a column like this:
2023-01-01: Text

The shortDate parser is applied to this column because the regex tests for ^datefomat
The format function "just" reformats the date in this column and keeps trailling text. Therefore this becomes
"2023/01/01: Text"
which is applied to this:

var date = new Date( dateString );
		return date instanceof Date && isFinite( date ) ? date.getTime() : '';

This will always be false. As new Date("2023/01/01: Text") returns false.

this can be solved:
a) don't apply this filter if we have trailling text (regex with $ at the end)
b) remove trailling text if the format function is called.
c) format all dates as yyyy-mm-dd and just apply the natural sorting algorithm - so trailling text is sorted as well

Solution c looks best to me.

@Mottie
Copy link
Owner

Mottie commented Jul 24, 2023

Try using one of the parsers in parser-date-extract.js

@mokraemer
Copy link
Author

this does not help, if you want this to be done automatically.

Added a simple custom parser:

		$.tablesorter.addParser({
			id: 'newShortDate', // 'mmddyyyy', 'ddmmyyyy' or 'yyyymmdd'
			is: function(str){
				str = (str || '').replace($.tablesorter.regex.spaces, ' ').replace($.tablesorter.regex.shortDateReplace, '/');
				return $.tablesorter.regex.shortDateTest.test(str);
			},
			format: function(str, table, cell, cellIndex){
				return str;
			},
			type: 'text'
		});

But it should be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants