-
Notifications
You must be signed in to change notification settings - Fork 157
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
era
isn't implemented in ISO calendar. Expected?
#901
Comments
But it should definitely not throw, its value is just |
What about this? Temporal.Absolute.from('2020-08-05T20:06:13+0900').toDateTime('Europe/Paris').with({era: 'BC'}).era Seems really odd that I can "set" a property using IMHO, if Doing this would probably be helpful to validate Temporal's end-to-end support for calendars adding additional properties, including:
I'm not familiar enough with calendar plans to know if solutions to all of above are already defined and tested. But seems like removing |
We had agreed elsewhere (can't remember where) that |
ICU is wishy-washy here. It always has an era available, but sometimes it is bogus, since not all calendars have any concept of era. I think ICU uses AD/BC for Gregorian. I would have a slight preference for Temporal to keep era as a property only on calendars that actually need it in their data model.
That's the case with literally any property passed to
This would be possible if we made all calendar fields into own properties (#917). Otherwise, it would be even more weird if Japanese dates had an own property but Gregorian dates didn't have any own properties. Putting the property on the prototype puts things on an even playing field. This is why things are the way they are right now. |
Also see #918 for another potential solution. |
Sure, but we don't return My main issue is that we're implying (via That said, I realize that there are really separate questions here:
Are we worried that this just kicks the can down the road to the first calendar that wants to add its own properties? Is there something special about "era" that won't apply to the next non-ISO property we discover? |
I think it's more accurate to say there's something special about era that won't apply to the next non-ISO, userland calendar property we discover. |
Oh, we definitely should not return
I claim it's only a problem for TypeScript, then. For regular JavaScript, a non-existent property is virtually indistinguishable from a property that returns undefined. You should be able to do some TypeScript shenanigans to fix the TypeScript problem. For your questions:
No and no.
Absolutely not.
Semantically, no. As I said above, I believe this is a TypeScript problem, not a Temporal problem.
Yes, they should. The imperfect way we were planning on doing this was to include enough properties by default to cover the 402 calendars, and most custom calendars should fit inside that set of properties, and if they want more properties, they extend the Temporal.Date prototype. Yuck, I know.
In the current model, my understanding is that all properties beyond those required for the ISO calendar should be extensions to the Temporal prototypes defined in 402 (rather than 262). So, 402 is free to add whatever it wants to the prototype.
era is in the same category as year, month, and day, and it should be documented in the same way. All of those properties return data calculated by or proxied through the calendar. Hypothetically, a calendar could not define months or years at all, and that's okay.
Yes, there are, but I'd need to look it up to get a full list.
No, there's nothing special about "era". It should not be in 262. It should, however, be in 402, and TypeScript should not complain if you try accessing it. |
@sffc @ptomato Could we discuss this in tomorrow's meeting or a subsequent one?
I agree with Shane here. This one is probably the top priority in my list in this issue. IMHO, types should not return fields in the FWIW, the current behavior is what @ptomato said:
The easiest thing to do would be to create TS types that list era and any other built-in calendar properties as optional fields. type DateTimeFields = {
// era: string | undefined; // CURRENT
era?: string | undefined; // PROPOSED
yearType?: string | undefined; // PROPOSED
// other built-in calendars' properties would go here
year: number;
month: number;
// . . .
} It might be possible to do something more sophisticated like making calendar-aware types generic, with an ISO default. This would support different fields per-calendar with everything validated by TypeScript. Kinda like this: (totally untested, may not work). Honestly I'm only 50/50 that this would be better than the optional fields approach above. class TemporalDate<C extends Temporal.CalendarProtocol = Temporal.Calendar.ISO>
implements ReturnType<C['dateFromFields']> {
// . . .
static from(item: Temporal.Date<C> | DateLike<C> | string, options?: AssignmentOptions): Temporal.Date<C>;
toLocalDateTime(data: { timeZone: Temporal.TimeZone; time?: Temporal.Time }): LocalDateTime<C>;
} But if it works, it'd enable TS code like this: dateISO = Temporal.Date.from('2020-01-01');
dateISO.era; // TS compiler error: `era` is not defined on type Temporal.Date<Temporal.ISOCalendar>
dateJPN = Temporal.Date<Temporal.JapaneseCalendar>.from('2020-01-01[c=japanese]');
// The syntax below might also be possible but not sure:
// dateJPN = Temporal.Date<'japanese'>.from('2020-01-01[c=japanese]');
dateJPN.era; // no error
dateJPN.toLocalDateTime('America/Los_Angeles').era; // also no error. the type is "infectious"
// It's also possible that we could infer the type of the Date via the calendar string literal
// Not 100% sure that would work though.
dateJPN2 = Temporal.Date.from({year: 2020, month: 1, day: 1, calendar: 'japanese').era; I'm dubious that the generic approach would be worth the extra complexity, but it might be worth a little time to experiment with. It'd definitely be helpful for custom calendars where the optional fields approach wouldn't work. |
Meeting, Sept. 18: The change we will make to address this is that |
Conclusions from yesterday's meeting:
|
I didn't think the last conclusion (about the "gregory" calendar) was part of what we had decided, to be honest I thought it was facetious, in a (successful) attempt to lighten the mood in the meeting! If we are seriously considering that, then I have some concerns:
I'm not against adding an era to the |
Agree. Historically, the AD vs. CE thing has been a political flashpoint. It'd be nice to avoid it. |
I was serious about the difference between "iso8601" and "gregory" being how they deal with eras. I also want to emphasize that the "gregory" calendar is not part of 262. It's something that 402 needs to decide on how to standardize. We will need to spin off discussions in 402 about how to handle each and every calendar, "gregory" included.
It's already the case that we will need to make the call about how to name eras in other calendar systems. For identifiers, we should probably stick with lowercase. CLDR uses integers 0 and 1 as the identifiers (I don't know if I agree with that, but it's something to consider). The English localization of era 0 is "BC" with variant "BCE" and of era 1 is "AD" with variant "CE" (see here). Variants might be triggered based on the display context (see tc39/ecma402#355). "gregory" is named after the pope and is inherently tied to Christianity, just like the Hebrew, Islamic, and Buddhist calendars to their respective religions. Therefore, religious era names are acceptable. "iso8601" is an international standard that avoids the use of religious era names.
You can already explicitly request that the era is outputted. new Date().toLocaleDateString("en", { year: "numeric", month: "short", day: "numeric", era: "short" })
// "Sep 20, 2020 AD" If you don't request a specific option, it's up to the datetime pattern matching algorithm to pick the best format for your calendar system. See more discussion in tc39/ecma402#394. That particular case looks like a bug that CLDR should be able to fix by tailoring the era display based on the sign of the year. |
OK, then it sounds like this is a question that can be deferred until more calendars are implemented, which I believe was something that Shane's team might work on? In any case if it is in the 402 domain then it's not needed for our Stage 3 review. |
I don't have an opinion about which milestone this is attached to, but I do think we should have guidance for calendar implementers for how Also we should make a call about how Not sure which milestone is important for those two things. |
I guess we still do have to implement the other two conclusions from #901 (comment) before freezing the proposal. I'll move this back into the earlier milestone, then. |
If I may add among the guidances to implementers who intent to use the era field in Temporal objects. I would suggest that the era field be a plain integer if it is used in a custom calendar. The representation of this field should be deferred to Intl, since it is the same problem as for the other fields: year, month, day. |
The main problem with representing eras as numbers is that doing so does not make sense in all calendar systems. In the Japanese calendar, eras are identified by their name in Unicode code points (or potentially a corresponding romanization), and there isn't necessarily a well-defined "first era". Using strings to identify eras is more generalizable. |
The ISO-8601 calendar should not return an era from getFields(). Only calendars that require an era, such as the Japanese calendar, should do so. See: #901
As part of this issue we decided that another difference between the ISO and Gregorian calendars is that the latter has BC/AD eras. It's indeterminate how this will exactly be standardized, as that's up to ECMA-402, but we add it to the experimental Gregorian calendar in the polyfill. See: #901
The ISO-8601 calendar should not return an era from getFields(). Only calendars that require an era, such as the Japanese calendar, should do so. See: #901
As part of this issue we decided that another difference between the ISO and Gregorian calendars is that the latter has BC/AD eras. It's indeterminate how this will exactly be standardized, as that's up to ECMA-402, but we add it to the experimental Gregorian calendar in the polyfill. See: #901
The ISO-8601 calendar should not return an era from getFields(). Only calendars that require an era, such as the Japanese calendar, should do so. See: #901
As part of this issue we decided that another difference between the ISO and Gregorian calendars is that the latter has BC/AD eras. It's indeterminate how this will exactly be standardized, as that's up to ECMA-402, but we add it to the experimental Gregorian calendar in the polyfill. See: #901
Are we planning to implement the
era
property on the ISO calendar?Expected:
"AD"
?"CE"
?"A.D."
?"C.E."
?Actual:
undefined
I can see the justification for not implementing it (e.g. if we don't want to wade into the political debate about AD vs. CE) but if it's intentionally not implemented then should the property throw when called?
The text was updated successfully, but these errors were encountered: