-
Notifications
You must be signed in to change notification settings - Fork 153
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
size-suggestion: Further reduce methods of Temporal.Now
?
#2862
Comments
Temporal.Now
?Temporal.Now
?
I'm concerned about Something like
Two methods with |
Could we just put "system calendar" in the method name to make it super-clear what's going on? Something like: This is analogous to why I'm arguing to retain |
OK we probably at least want |
I think it'd be OK to remove |
It is certainly true that we didn't have ZDT when |
I'm hearing a rough consensus above for removing We could do more but it sounds like we'd need more discussion about those, but that shouldn't stop us from moving fwd on the non-contentious removal? |
Here's a few options we can discuss (at this week's champions meeting) for what additional functions could be removed from Option 1
Option 2
Option 3
Personally I like option 2 and option 1 about equally. Option 2 shrinks more functions, while option 1 makes PlainTime, PlainDate, and timezone IDs more discoverable for n00bs. Both are IMO useful goals. If we choose option 2, we can always extend I assume that Option 3 would be harder to get approval, both because it's a larger change and also because there's no umbrella object to disable for hosts that want to disallow code to access the host environment, which was AFAIK the main reason we have a Now object and not Regardless of the options chosen, I think it'd be better to remove the ISO suffix for the reasons outlined here. |
To be more specific, the principle there was separation—if the capability to read a system clock were on the various classes, then they could not be safely shared in general, but not sharing them would also come at the expense of their purely computational functionality. |
Option 2 and 3 both sound good to me. |
(fwiw, a shared |
Meeting 2025-05-30: No consensus to remove more functions. |
The TC39 Agenda has the following code snippet that would break if we made this change. Temporal.ZonedDateTime.from('2024-06-11T10:00[Europe/Helsinki]')
.withTimeZone(Temporal.Now.timeZoneId()) // your time zone
.toLocaleString() |
After the slate of removals that was approved on 2024-06-12, we are not going to pursue this unless it is really an obstacle for implementations to ship. |
In #2846, we're proposing to shrink Temporal.Now to fewer methods:
In #2846 (comment), @littledan suggested an even further simplification: replace the Temporal.Now object with a single
Temporal.now()
function that returns aTemporal.ZonedDateTime
instance. All the methods ofTemporal.Now
would be available via a single method or getter call from the resulting ZDT object:Temporal.Now.instant()
=>Temporal.now().toInstant()
Temporal.Now.zonedDateTimeISO()
=>Temporal.now()
Temporal.Now.plainDateTimeISO()
=>Temporal.now().toPlainDateTime()
Temporal.Now.plainDateISO()
=>Temporal.now().toPlainDate()
Temporal.Now.plainTimeISO()
=>Temporal.now().toPlainTime()
Temporal.Now.timeZoneId()
=>Temporal.now().timeZoneId
Doing this would save 5 methods in code size and would simplify developer experience.
Some possible downsides:
Instant
considerably more expensive, because todayTemporal.Now.instant()
doesn't require callingSystemTimeZoneIdentifier
, which is an ICU call and I assume it's not super-cheap. (Although it may be cacheable so this cost might be easy to optimize?)Temporal.nowWithSystemCalendar()
or, at the very least,Temporal.systemCalendar()
that could be passed towithCalendar
.Note that there are intermediate possible solutions too, for example, leaving
Temporal.Now
with only two methods:instant()
(for performance) andzonedDateTimeISO()
(or maybezonedDateTime()
depending on the renaming discussion in #2846 (comment)).The text was updated successfully, but these errors were encountered: