Implement Temporal.Duration.prototype.toLocaleString#5091
Implement Temporal.Duration.prototype.toLocaleString#5091SKM2227229725 wants to merge 4 commits intoboa-dev:mainfrom
Conversation
There was a problem hiding this comment.
Thanks for pointing that out. I’ve removed the unrelated README change from the PR.
| let duration_format_prop = intl_obj.get(js_string!("DurationFormat"), context)?; | ||
|
|
||
| // Check if DurationFormat exists and is a constructor. | ||
| if let Some(constructor) = duration_format_prop.as_constructor() { | ||
| // Construct: new Intl.DurationFormat(locales, options) | ||
| let formatter = constructor.construct(&[locales.clone(), options.clone()], context)?; | ||
|
|
||
| // Get the format method. | ||
| let format_method = formatter.get(js_string!("format"), context)?; | ||
| if let Some(format_fn) = format_method.as_callable() { | ||
| // Call format with the duration object. | ||
| return format_fn.call(&formatter.into(), &[this.clone()], context); |
There was a problem hiding this comment.
DurationFormat doesn't exist in our Intl implementation, so this will always fail. Please validate what your LLM generates before pushing changes.
There was a problem hiding this comment.
@jedel1043 Thanks for the feedback! You're right, Intl.DurationFormat is not currently implemented in Boa.
I'll update the implementation to remove that usage and instead fall back to the existing toString behavior until full Intl support is available.
|
Closing. I'm not entirely sure we should be touching implementing Duration.p.toLocaleString without having the initial implementations of the other Temporal builtins. Note, ICU4X's duration format crate is still experimental and would need to be implemented with either the experimental crate or have the crate stabilized first. |
Fixes #5088
Summary
Implements
Temporal.Duration.prototype.toLocaleStringwith support for bothintland non-intlbuild configurations.Changes
Method Implementation: Added
to_locale_stringto theDurationstruct.Intl Integration:
intlis enabled, the implementation dynamically usesIntl.DurationFormatfrom the global object to format the duration.intlis disabled, it falls back to the ISO-8601 string representation usingas_temporal_string.Safety: Uses safe property access and type checking to prevent panics if the global
Intlobject is modified.Registration: Registers the method in the
Durationprototype during intrinsic initialization.Verification
localesandoptionsarguments.thisvalue.cargo check.