-
Notifications
You must be signed in to change notification settings - Fork 160
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
Design of parsing methods #428
Comments
There's discussion of some adjacent things in #198 ("Dates/Times/TimeZones may occur individually or in combination') but for the most part this was already the case when I started working on this proposal, maybe someone else can point to an earlier discussion? |
We discussed this in today's meeting but need to do some more thinking in order to get everyone in agreement, so we'll discuss it again next week. Broadly speaking, there are two use cases:
Some ideas discussed include:
|
What's the use case for this beyond just using |
If you have an ISO string where the date is invalid, for example, |
Ah, OK. Is there a particular reason to support that use case? |
We discussed this morning that it would be important when dealing with data supplied from another program. |
@bakkot I guess in cases where you just don't care about the I guess there's no major harm in enabling both cases? Of course the default (and preferred) way of doing things would be to just run |
To keep the discussion on this moving, I've written up some possibilities in #503. (Not sure it needs to be merged, but this is just to have something to discuss.) As for my personal opinion: I prefer proposal 1, I would not oppose proposal 2 but think it's less convenient, and I think proposal 3 would be a mistake. I'm basing my opinon on the assumption that use case 1 is far more common than use case 2, and further on my strong preference that the most obvious way to parse should not yield a valid Temporal object out of an invalid ISO 8601 string. If my understanding of either of those factors were to change, my preference would probably change as well. |
I added a table with pros and cons to the document. |
Closing this because the design is settled on; we decided in the meeting of 23 April to go with option 1. |
(I haven't been following this proposal closely, sorry. Sorry if this is duplicated elsewhere, and for not raising it earlier. If this has been discussed previously, I will go read that discussion if it is documented somewhere.)
I came across #415 and noticed that the various parsing methods accept inputs which contain information irrelevant to the thing they are parsing for. I think that's bad. (Among other things, it leads to non-obvious questions like the ones raised in that issue.) In my experience, trying to guess the user's intent in cases like this leads to confusing bugs.
For this reason, generally speaking, I think that any parser for a Foo should reject all input strings which contain non-Foo parts. For example,
Date.from('2019-02-16T23:45')
is attempting to parse a string which contains a time, which is not relevant toDate
, and soDate.from
should reject it (that is, throw), not just silently ignore the irrelevant part. The correct way to get aDate
out of a string formatted like aDateTime
should be to parse it as aDateTime
and then extract aDate
out of it.The text was updated successfully, but these errors were encountered: