@@ -32,6 +32,9 @@ use temporal_rs::{
3232 options:: { RoundingIncrement , RoundingMode , RoundingOptions } ,
3333} ;
3434
35+ #[ cfg( test) ]
36+ mod tests;
37+
3538/// The `Temporal.Instant` built-in implementation
3639///
3740/// More information:
@@ -664,8 +667,11 @@ impl Instant {
664667 ///
665668 /// [spec]: https://tc39.es/proposal-temporal/#sec-temporal.instant.tolocalestring
666669 /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/toLocaleString
667- fn to_locale_string ( this : & JsValue , _: & [ JsValue ] , context : & mut Context ) -> JsResult < JsValue > {
668- // TODO: Update for ECMA-402 compliance
670+ fn to_locale_string (
671+ this : & JsValue ,
672+ args : & [ JsValue ] ,
673+ context : & mut Context ,
674+ ) -> JsResult < JsValue > {
669675 let object = this. as_object ( ) ;
670676 let instant = object
671677 . as_ref ( )
@@ -675,12 +681,37 @@ impl Instant {
675681 . with_message ( "the this object must be a Temporal.Instant object." )
676682 } ) ?;
677683
678- let ixdtf = instant. inner . to_ixdtf_string_with_provider (
679- None ,
680- ToStringRoundingOptions :: default ( ) ,
681- context. timezone_provider ( ) ,
682- ) ?;
683- Ok ( JsString :: from ( ixdtf) . into ( ) )
684+ #[ cfg( feature = "intl" ) ]
685+ {
686+ use crate :: builtins:: intl:: date_time_format:: {
687+ FormatDefaults , FormatType , format_date_time_locale,
688+ } ;
689+
690+ let locales = args. get_or_undefined ( 0 ) ;
691+ let options = args. get_or_undefined ( 1 ) ;
692+
693+ // Converting epoch milliseconds
694+ let epoch_ms = instant. inner . epoch_milliseconds ( ) as f64 ;
695+
696+ return format_date_time_locale (
697+ locales,
698+ options,
699+ FormatType :: Any ,
700+ FormatDefaults :: All ,
701+ epoch_ms,
702+ context,
703+ ) ;
704+ }
705+
706+ #[ cfg( not( feature = "intl" ) ) ]
707+ {
708+ let ixdtf = instant. inner . to_ixdtf_string_with_provider (
709+ None ,
710+ ToStringRoundingOptions :: default ( ) ,
711+ context. timezone_provider ( ) ,
712+ ) ?;
713+ Ok ( JsString :: from ( ixdtf) . into ( ) )
714+ }
684715 }
685716
686717 /// 8.3.13 `Temporal.Instant.prototype.toJSON ( )`
0 commit comments