-
Notifications
You must be signed in to change notification settings - Fork 159
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
Lack of throwing for most Object as Calendar in new Temporal.Plain*()? #1652
Comments
For the original context, see #300. Another related discussion is #1294. I agree this is not like the way datetime-like objects work, but if we want to support plain-object calendars as implementations of the calendar protocol, there isn't really a "shape" to which a calendar-like object must conform, since calendar methods are optional. So I believe the way you described it is correct. As per #1432, if this is causing problems in the implementation, especially with respect to optimizability, I think we should put it on the agenda to discuss in a Temporal champions meeting. |
Really!?! So... there are no minimum requirement for the calendar object and could be Object? Again, I don't feel there is a need for discussion of this in the agenda. I just need to confirm that is the design intend for this issue. I am closing down this issue since ptomato already answer my question. |
OK, I'm happy to put it on next week's agenda if you change your mind and want to discuss it (or @sffc since I saw you thumbsed-up the comment) but unless I hear anything to the contrary I'll leave this as closed. |
This is really a question which I am puzzle, not a suggestion or opinion. I just try to understand the logic behind this.
So... if I pass in a object, except those which have a calendar property but anything else , something like {foo: "bar", year:5} as calendarLike to the new Temporal.Plain*() constructor call, is it by design NOT to check that and throw any error?
For example, let's say we have the following code:
it won't throw at this moment, right? Is thsi by design?
3.1.1 Temporal.PlainDate ( isoYear, isoMonth, isoDay [ , calendarLike ] )
https://tc39.es/proposal-temporal/#sec-temporal-plaindate-objects
ToTemporalCalendarWithISODefault( {foo: 'bar'} )
12.1.22 ToTemporalCalendarWithISODefault ( temporalCalendarLike )
https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendarwithisodefault
2. Return ? ToTemporalCalendar(temporalCalendarLike).
12.1.21 ToTemporalCalendar ( temporalCalendarLike )
https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendar
b. If ? HasProperty(temporalCalendarLike, "calendar") is false, return temporalCalendarLike.
so ToTemporalCalendar({foo: 'bar'} ) return {foo: 'bar'}
and ToTemporalCalendarWithISODefault ({foo: 'bar'}) return {foo: 'bar'}
and after running
8. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
in 3.1.1 Temporal.PlainDate ( isoYear, isoMonth, isoDay [ , calendarLike ] )
calendar is {foo: 'bar'}
and then call 9.
9. Return ? CreateTemporalDate(y, m, d, calendar, NewTarget).
which is now
9. Return ? CreateTemporalDate(2021, 3, 15, {foo: 'bar'}. NewTarget).
https://tc39.es/proposal-temporal/#sec-temporal-createtemporaldate
and
12. Set object.[[Calendar]] to calendar.
13. Return object.
so the Temporal.PlainDate has a [[Calendar]] point to {foo: 'bar'}
and no exception will be throw at this point. IS this what the champion intend it to be?
and later
3.3.4 get Temporal.PlainDate.prototype.year
will call
4. Return ? CalendarYear(calendar, temporalDate).
and
and at this point a TypeError got throw
Is this how it supposed to work?
@sffc @justingrant @ptomato @Ms2ger @ryzokuken @ljharb @littledan
or is this a mistake in the spec and we supose to throw error while the constructor was called with {foo: 'bar'}
This is purely a question, no opinion. I am just not sure my implementation is correct.
The text was updated successfully, but these errors were encountered: