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

question: accepting both string or Object inputs in one method #1407

Closed
syg opened this issue Mar 3, 2021 · 2 comments
Closed

question: accepting both string or Object inputs in one method #1407

syg opened this issue Mar 3, 2021 · 2 comments

Comments

@syg
Copy link

syg commented Mar 3, 2021

In the course of reviewing the spec draft, I see that the from() method, perhaps others as well, accept both a string and an Object input. I have a preference for making calls to any kind of parser look explicit.

Where can I read about the motivation for these methods accepting both strings and Objects? Was the ergonomic hit from splitting the functions to one that parses string input and one that takes structured data deemed unacceptable?

@ptomato
Copy link
Collaborator

ptomato commented Mar 4, 2021

Sorry, I meant to respond to this yesterday, but digging up the relevant discussions took some time 😄

On both from() as well as other methods accepting strings we have had it both ways at some point during the proposal's history, before settling on the status quo. For a unified from() vs separate from() and fromString() methods, the discussion is in #230. There doesn't seem to be a lot of background there and it was before I started working on this, so maybe @pipobscure could weigh in.

For other methods, the status quo is that any entry point that accepts a Temporal object can also accept the corresponding ISO string. The main reason for settling on this change was due to collecting feedback from JS developers and starting to write cookbook examples using the polyfill ourselves, and discovering that it's really cumbersome and makes code less readable to call from() explicitly if you are effectively providing a literal value and not a variable, e.g. dt.since(Temporal.PlainDateTime.from('2000-01-01')) instead of the more concise dt.since('2000-01-01').

Relevant discussions about accepting strings in other methods:

@ptomato ptomato added this to the Stage 3 milestone Mar 4, 2021
@ptomato
Copy link
Collaborator

ptomato commented Mar 20, 2021

@syg Please let me know if you have further questions on this topic or we need to dig up more background.

@ptomato ptomato closed this as completed Mar 20, 2021
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