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

TODO: Determine value of valueOf #25

Closed
mattjohnsonpint opened this issue Jul 8, 2017 · 10 comments
Closed

TODO: Determine value of valueOf #25

mattjohnsonpint opened this issue Jul 8, 2017 · 10 comments

Comments

@mattjohnsonpint
Copy link
Collaborator

mattjohnsonpint commented Jul 8, 2017

We should decide what .toString() and .valueOf() return for each object type. We should also consider the output of console.log for each object type, and whether it is the same or different than the toString output.

@domenic
Copy link
Member

domenic commented Jul 8, 2017

FYI console.log output is not something for specs to decide; it's for individual devtools teams to work through in order to create a UI they feel is best for their users.

@mattjohnsonpint
Copy link
Collaborator Author

mattjohnsonpint commented Jul 8, 2017

Good to know. Though I must say, it's such a P.I.T.A. of a problem today when the toString output doesn't match the console log output. For example:

console.log(new Date());

// Chrome:
//=> Sat Jul 08 2017 16:18:31 GMT-0700 (Pacific Daylight Time)

// FireFox:
//=> Date 2017-07-08T23:18:31.674Z

Chrome output matches toString, but FF matches toISOString with "Date" preceding.

I suppose there's nothing we can do in this spec to deal with that, but it does come up again and again on StackOverflow. Was hoping to at least have a suggested output format for implementers. Would that be allowed?

@domenic
Copy link
Member

domenic commented Jul 10, 2017

Maybe as part of https://console.spec.whatwg.org/ , but definitely not as part of ECMAScript.

@mattjohnsonpint
Copy link
Collaborator Author

Yep. this exactly. Thanks for the link. :)

Ok, so ignoring the console log output, the rest of this issue still stands.

@maggiepint
Copy link
Member

I'm most concerned about valueOf on ZonedInstant. Is the same instant in two different zones comparable? This is probably the hardest hurdle here.

@mattjohnsonpint
Copy link
Collaborator Author

@maggiepint - good point. Need to think about that one more...

@mattjohnsonpint
Copy link
Collaborator Author

To add here: @domenic noted in #35 that Array.prototype.sort uses toString, not valueOf. So let's be sure any toString output is lexicographically sortable. Sticking with ISO8601 will help.

@apaprocki
Copy link
Contributor

apaprocki commented Jul 11, 2017

@maggiepint In our datetime classes, we resisted providing comparison/equality operators that implicitly convert to help avoid human error. The programmer has to explicitly write what they want. It would be akin to requiring something like this:

Verify two zoned instants refer to the same point in UTC:

if (newYorkZonedInstant.toUTC() == tokyoZonedInstant.toUTC()) ...
// 2017-07-11T09:00:00-04:00       2017-07-11T21:00:00+08:00
// v                               v
// 2017-07-11T13:00:00          == 2017-07-11T13:00:00
// true

Verify the local plain datetimes are the same / throw away the offset/zone:

if (newYorkZonedInstant.toPlain() == tokyoZonedInstant.toPlain()) ...
// 2017-07-11T09:00:00-04:00         2017-07-11T21:00:00+08:00
// v                                 v
// 2017-07-11T09:00:00            == 2017-07-11T21:00:00
// false

(We opted to make both functions return the equivalent of PlainDateTime)

@gilmoreorless
Copy link
Contributor

It would also be good to define what the JSON output should be for each type. Date explicitly defines .toJSON() to return the output of .toISOString() (spec).
I'm assuming that for the temporal objects the JSON output would be the same as .toString() (that is, ISO 8601 as mentioned by @mj1856 above), but it should still be explicitly stated.

@maggiepint maggiepint changed the title TODO: Common representations TODO: Determine value of valueOf Jul 24, 2018
@mattjohnsonpint
Copy link
Collaborator Author

Decided in #74 that we will not have a valueOf function, so closing this 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

No branches or pull requests

5 participants