Issue #1300 fix: fuzzydate strict date option regex #2354

Open
nandanv2702 wants to merge 2 commits from nandanv2702/issue_1300 into master
nandanv2702 commented 2021-08-13 18:13:26 +00:00 (Migrated from github.com)

Hey! This fix refers to issue #1300

I made changes to two of the files to include regex options to parse dates in the following formats:

  • mm dd yyyy
  • mm dd yy
  • dd mm yyyy
  • dd mm yy

All the aforementioned date formats use the separators . or - or /, e.g.:

  • dd-mm-yy
  • dd.mm.yy
  • dd/mm/yy

This can be activated using the strictDate option in the fuzzydate function which is set to false by default.

Let me know whether this solution is what you were looking for!

Hey! This fix refers to [issue #1300](https://github.com/SheetJS/sheetjs/issues/1300) I made changes to two of the files to include regex options to parse dates in the following formats: - mm dd yyyy - mm dd yy - dd mm yyyy - dd mm yy All the aforementioned date formats use the separators `. or - or /`, e.g.: - dd-mm-yy - dd.mm.yy - dd/mm/yy This can be activated using the strictDate option in the fuzzydate function which is set to `false` by default. Let me know whether this solution is what you were looking for!
SheetJSDev commented 2021-09-11 19:15:19 +00:00 (Migrated from github.com)

ES6 issues aside (we are targeting ES3, so no const or default parameter values or arrow functions) two comments:

  1. the result of the match is not used, so RegExp#test probably should be used. You might also be missing a new RegExp somewhere.

  2. how should the library interpret something ambiguous like 03-02-01 or 01/02/03 ?

ES6 issues aside (we are targeting ES3, so no const or default parameter values or arrow functions) two comments: 1) the result of the match is not used, so [RegExp#test](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test) probably should be used. You might also be missing a new RegExp somewhere. 2) how should the library interpret something ambiguous like `03-02-01` or `01/02/03` ?
nandanv2702 commented 2021-09-23 00:40:08 +00:00 (Migrated from github.com)

Hey! I'll work on the changes for the first point soon, but as for the second - what do you think of including an option similar to dateNF that allows a user to enter the date format as dd-mm-yy, mm-dd-yy etc.?

Alternatively, if strictDates is set to true, we can use dateNF (or the newly defined similar variable as mentioned above) to match any date values to the regex options defined in this PR here

What do you think?

Hey! I'll work on the changes for the first point soon, but as for the second - what do you think of including an option similar to `dateNF` that allows a user to enter the date format as `dd-mm-yy, mm-dd-yy` etc.? Alternatively, if `strictDates` is set to true, we can use `dateNF` (or the newly defined similar variable as mentioned above) to match any date values to the regex options defined in this PR [here](https://github.com/SheetJS/sheetjs/pull/2354/files#diff-4aeb62dc7a6f86c9dedff5f3d3e3144d5a0269b3d9ed7e5cf50d9b39f2a36122R136) What do you think?
nandanv2702 commented 2021-09-30 23:51:41 +00:00 (Migrated from github.com)

Just following up on my last comment - after reading #2196 and #1646, I think it might make more sense to make the following changes:

  1. Change strictDates to a string that can be dd-mm, mm-dd, or true
  2. Refactor STRICT_DATE_REGEX to be an Object with the keys dd-mm and `mm-dd with their respective regex values

This can allow for stricter dates while also letting us switch dd-mm to mm-dd internally since the JS Date function only uses mm-dd. In case strictDates is true, we can test it with all STRICT_DATE_REGEX values and return the first match (which will, by nature, be in the mm-dd format).

I'm currently working on these changes, so let me know if this sounds good!

Just following up on my last comment - after reading #2196 and #1646, I think it might make more sense to make the following changes: 1. Change `strictDates` to a string that can be `dd-mm`, `mm-dd`, or `true` 2. Refactor [`STRICT_DATE_REGEX`](https://github.com/SheetJS/sheetjs/pull/2354/files#diff-4aeb62dc7a6f86c9dedff5f3d3e3144d5a0269b3d9ed7e5cf50d9b39f2a36122R136) to be an Object with the keys `dd-mm` and `mm-dd with their respective regex values This can allow for stricter dates while also letting us switch `dd-mm` to `mm-dd` internally since the JS Date function only uses `mm-dd`. In case `strictDates` is `true`, we can test it with all [`STRICT_DATE_REGEX`](https://github.com/SheetJS/sheetjs/pull/2354/files#diff-4aeb62dc7a6f86c9dedff5f3d3e3144d5a0269b3d9ed7e5cf50d9b39f2a36122R136) values and return the first match (which will, by nature, be in the `mm-dd` format). I'm currently working on these changes, so let me know if this sounds good!
This pull request has changes conflicting with the target branch.
  • bits/20_jsutils.js
  • bits/40_harb.js

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin nandanv2702/issue_1300:nandanv2702/issue_1300
git checkout nandanv2702/issue_1300

Merge

Merge the changes and update on Gitea.
git checkout master
git merge --no-ff nandanv2702/issue_1300
git checkout master
git merge --ff-only nandanv2702/issue_1300
git checkout nandanv2702/issue_1300
git rebase master
git checkout master
git merge --no-ff nandanv2702/issue_1300
git checkout master
git merge --squash nandanv2702/issue_1300
git checkout master
git merge nandanv2702/issue_1300
git push origin master
Sign in to join this conversation.
No description provided.