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

Replaced ISO8601 with new code #2009

Closed
wants to merge 2 commits into from

Conversation

sahilsuman933
Copy link

@sahilsuman933 sahilsuman933 commented Jul 27, 2022

Signed-off-by: Sahil Suman sahilsuman933@gmail.com

  • Replaced the iso8601 method with new code
  • Added new test cases

Fixes - #2003 #1883 #1046

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)

@codecov
Copy link

codecov bot commented Jul 27, 2022

Codecov Report

Merging #2009 (a68859c) into master (1bb14e8) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master     #2009   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          104       104           
  Lines         2203      2183   -20     
  Branches       477       468    -9     
=========================================
- Hits          2203      2183   -20     
Impacted Files Coverage Δ
src/lib/isISO8601.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1bb14e8...a68859c. Read the comment docs.

@sahilsuman933
Copy link
Author

@rubiin, can you please review this PR.

Copy link
Member

@WikiRik WikiRik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you undo all the style changes in this PR? Those make this PR much larger than needed

Copy link
Member

@rubiin rubiin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to avoid style changes. You can check with git diff for things that you have chnaged

Signed-off-by: Sahil Suman <sahilsuman933@gmail.com>
Signed-off-by: Sahil Suman <sahilsuman933@gmail.com>
@sahilsuman933
Copy link
Author

@rubiin and @WikiRik You can do the PR review now.

@sahilsuman933 sahilsuman933 requested a review from rubiin July 27, 2022 13:50
@sahilsuman933 sahilsuman933 requested review from WikiRik and removed request for WikiRik August 10, 2022 23:59
Copy link
Member

@WikiRik WikiRik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code was mostly based on http://www.pelagodesign.com/blog/2009/05/20/iso-8601-date-validation-that-doesnt-suck/
Is that article incorrect?

This PR also removes the options that we had so we'll have to deprecate those first and release this rewrite in the next major release or add some sort of backwards compatibility. Agree @rubiin ?

Copy link
Contributor

@braaar braaar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While there seem to be real bugs in the code, as evidenced by the linked issues, you have not properly accounted for the removal of many of the valid ISO8691 timestamps in the test code.

If they are valid ISO8601 timestamps they should pass the test. If they are not valid and were added to the test code erroneously, that ought to be corrected, of course.

Why did you not add 2018-09-11T10:16.000Z (from #2003) to invalidISO8601? That is one of the key bugs your are trying to fix, so you should test for it.

2021-12-13T04:29:08+14:01 and 2021-12-13T04:29:08-12:01 (from #1883) should also be added to invalidISO8601.

'2009-05',
'2009-123',
'2009-222',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a valid ordinal date.

'2009-222',
'2009-001',
'2009-W01-1',
'2009-W51-1',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a valid Week with weekday

'2009-W51-1',
'2009-W511',
'2009-W33',
'2009W511',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a valid week with weekday without separators

Comment on lines -10326 to -10327
'20090519',
'2009123',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are valid ISO dates. Separators (hyphens) can be omitted

The ISO 8601 standard allows these separators to be omitted (e.g., 19980512 for a date), but expressions are much easier to read when separators are used.

'2009-05-19 14:39:22-06:00',
'2009-05-19 14:39:22+0600',
'2009-05-19 14:39:22-01',
'20090621T0545Z',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid ISO8601 without separators

Comment on lines -10353 to -10361
'2010-02-18T16:23:48,444',
'2010-02-18T16:23:48,3-06:00',
'2010-02-18T16:23.4',
'2010-02-18T16:23,25',
'2010-02-18T16:23.33+0600',
'2010-02-18T16.23334444',
'2010-02-18T16,2283',
'2009-05-19 143922.500',
'2009-05-19 1439,55',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have the actual spec on hand, but the article @WikiRik linked includes these examples as valid, so I can only assume that this is some obscure syntax that is still a part of the spec. As the article says, If we are invoking the name ISO8601 we ought to respect the spec, even though it includes some wacky things.

@sahilsuman933
Copy link
Author

Do I have to make any changes @braaar cause it's been 27 days and this PR is still not merged after getting the approval.

@braaar
Copy link
Contributor

braaar commented Aug 23, 2022

Do I have to make any changes @braaar cause it's been 27 days and this PR is still not merged after getting the approval.

I don't intend to cause offence here, but I think this PR is far from mergeable.

I don't know what @rubiin's thoughts are, but are you can see from my comments there are a number of unexplained (possibly breaking) changes that I think should be accounted for before this is ready to merge. I would suggest you go back and answer my comments individually with your explanation for the changes.

You should also address @WikiRik's comments about breaking the existing options and backwards compatibility.

@sahilsuman933
Copy link
Author

In order to fix this issue, I referred to Joi, validated all the test cases, and separated them according to their validation. Also, I thought it unnecessary to have a strict separator cause most of the validators don't have it, so I removed it, and the article that @WikiRik mentioned is quite old that's why I didn't follow that article.

So what do you want me to do precisely @braaar?

@braaar
Copy link
Contributor

braaar commented Aug 23, 2022

In order to fix this issue, I referred to Joi, validated all the test cases, and separated them according to their validation. Also, I thought it unnecessary to have a strict separator cause most of the validators don't have it, so I removed it, and the article that @WikiRik mentioned is quite old that's why I didn't follow that article.

Joi isn't the arbiter of what test cases to include here, the International Organization for Standardization is.

Does Joi implement the ISO8601 spec correctly?

So what do you want me to do precisely @braaar?

  1. Undo all your changes to the test code
  2. Add the following cases to invalidIso8601
  • 2018-09-11T10:16.000Z
  • 2021-12-13T04:29:08+14:01
  • 2021-12-13T04:29:08-12:01
  1. See if your new code passes the tests

If it passes the tests, bravo! You have shortened the code and fixed the bugs!

If it doesn't, your code doesn't work properly and needs to be fixed. If the breaking changes were made purposefully, we need to have a conversation about which variants of the ISO8601 spec we might want to deprecate. You seem to want to deprecate a whole lot of variants of ISO860, but you have not actually argued this point so I am left guessing as to your intentions.

What I think is the real solution

I suspect that there is a divide between people who want to accept the entire ISO8601 spec, and people who want a stricter validator that accepts only a specific subset of the ISO8601 spec, such as 2022-08-23T15:47:31+00:00 and 2022-08-23T15:47:31Z. There is a real concern that when accepting the entirety of the ISO8601 spec, some false positives can sneak through. It's entirely possible for someone to accidentally type a valid ordinal date when in fact the intention is to type a standard date and time. Contributors in Joi have had a similar discussion. This division should be sorted out by having an option (or options) for strictness. I believe removing all options is throwing the baby out with the bathwater.

I would be very happy to see some documentation about the JavaScript conventions for the ISO8601 spec. Have you found any such documentation?

I may completely misread your intentions here. I am assuming you don't want isISO8601 to accept the entire ISO8601 spec, but if your goal is merely to fix the issues you linked, then this whole discussion doesn't belong in this PR.

@braaar
Copy link
Contributor

braaar commented Aug 23, 2022

I don't want to patronize here, but I think you have a narrow interpretation of ISO8601, since you wrote this in #2003

For example, 2009-222 is not a valid ISO8601 date but is put in the validISO8601.

This is a valid ordinal date, at least according to the wikipedia article for ISO8601 (and the aforementioned article about ISO8601 validation)

@sahilsuman933
Copy link
Author

Yeah, you are right @braaar Joi isn't the arbiter. After this conversation with you, I came to know that I had a narrow interpretation of ISO8601. I used to think something like this format is a valid ISO8601 1997-07-16T19:20:30+01:00. but that's not the case, it seems. Also, you are right about not deprecating variants of ISO8601.

So, I will first learn about what ISO8601 is and how many divisions we can break this format to cover the large majority of demands. I will give you a summary before implementing this. This whole process might take some time but don't worry, I will not leave this PR hanging until it is merged. :)

@sahilsuman933
Copy link
Author

I did my study on ISO8601, and I found out that it is unnecessary to cover the whole interpretation of ISO8601. Implementing it only for the Date in UTC format will be better as it is the most used format. Also, if you see, most of the issues that we got are related to this format only.

So, I propose converting the entire validation algorithm for the Date in UTC format. Also, I will improve the implementation of the strict mode. What's your opinion about this, @braaar, @WikiRik and @rubiin?

Should I proceed with the implementation?

@braaar
Copy link
Contributor

braaar commented Aug 30, 2022

I did my study on ISO8601, and I found out that it is unnecessary to cover the whole interpretation of ISO8601. Implementing it only for the Date in UTC format will be better as it is the most used format. Also, if you see, most of the issues that we got are related to this format only.

So, I propose converting the entire validation algorithm for the Date in UTC format. Also, I will improve the implementation of the strict mode. What's your opinion about this, @braaar, @WikiRik and @rubiin?

Should I proceed with the implementation?

I think fixing the bugs on the existing validator should be a priority.

A new strict mode with a more narrow conception of ISO8601 will probably be appreciated by many. Feel free to drop a comment here explaining exactly which format(s) you intend to allow in the strict mode.

@sahilsuman933
Copy link
Author

Now, I feel like we don't even need the strict mode. But, still, if we want to add it, we can cover the ordinal date, week with weekends and week.

// @braaar

@braaar
Copy link
Contributor

braaar commented Sep 2, 2022

Now, I feel like we don't even need the strict mode. But, still, if we want to add it, we can cover the ordinal date, week with weekends and week.

// @braaar

I'm starting to think that maybe it's best to have one PR for fixing the bugs you linked here, and one PR for new features (and possibly breaking changes).

It could also make more sense to create an issue where people can discuss what options they would like to have. You can propose modes such as

  • mode that accepts only the UTC date time `2022-08-23T15:47:31Z
  • mode that accepts only the standard 8601 date time with time zone 1997-07-16T19:20:30+01:00
  • mode that accepts the ones above, plus ordinal dates
  • some kind of advanced configuration object where you can pick and choose which formats you want to accept?

In that issue we could also discuss what we want to do in terms of breaking changes. If we want for example the UTC one to be the default, we should schedule it as a breaking change for the next major release. Obviously we have to agree first on what is the best thing to have as the default behaviour, however.

@sahilsuman933
Copy link
Author

Okay, @braaar.

I will close this PR and create a new one to fix those issues. Also, can you tell me where I can discuss these new features?

@braaar
Copy link
Contributor

braaar commented Sep 5, 2022

Okay, @braaar.

I will close this PR and create a new one to fix those issues. Also, can you tell me where I can discuss these new features?

Create an issue? :)

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

Successfully merging this pull request may close these issues.

4 participants