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

time parser regex #1269

Closed
lesilent opened this issue Aug 1, 2016 · 1 comment
Closed

time parser regex #1269

lesilent opened this issue Aug 1, 2016 · 1 comment

Comments

@lesilent
Copy link

lesilent commented Aug 1, 2016

Hi, I'm trying to sort a time column and ran into small issue. Basically, the hours in my time are zero padded to two digits (eg. 09:52 PM) and tablesorter doesn't seem to handle that. After digging through the code, I think isolated to source to the regex used in the time parser. Below are the lines in question:

// match 24 hour time & 12 hours time + am/pm - see http://regexr.com/3c3tk
ts.regex.timeTest = /^([1-9]|1[0-2]):([0-5]\d)(\s[AP]M)$|^((?:[01]\d|[2][0-4]):[0-5]\d)$/i;
ts.regex.timeMatch = /([1-9]|1[0-2]):([0-5]\d)(\s[AP]M)|((?:[01]\d|[2][0-4]):[0-5]\d)/i;

I checked out the url at regexr.com and noticed that it failed to match the last time of "09:59 PM". Is that the correct behavior? Is it possible to update the regex to also handle zero padded hours by adding 0? like so:

ts.regex.timeTest = /^(0?[1-9]|1[0-2]):([0-5]\d)(\s[AP]M)$|^((?:[01]\d|[2][0-4]):[0-5]\d)$/i;
ts.regex.timeMatch = /(0?[1-9]|1[0-2]):([0-5]\d)(\s[AP]M)|((?:[01]\d|[2][0-4]):[0-5]\d)/i;
@Mottie
Copy link
Owner

Mottie commented Aug 1, 2016

Hi @lesilent!

You're right! Thanks for the report and fix!

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

No branches or pull requests

2 participants