From 82101ba1e3b991bc70e8ac171a9c7d07ffcf752e Mon Sep 17 00:00:00 2001 From: Aaron Ross Date: Thu, 17 Mar 2022 01:05:04 -0700 Subject: [PATCH] convert inner datetime to local in `to_date_string` `Date.prototype.toDateString` should return a value representing the local date. The Rust `Date` inner value represents UTC time, so it should be adjusted to local time before formatting (see `to_string` and `to_time_string`). --- boa_engine/src/builtins/date/mod.rs | 7 ++++++- boa_engine/src/builtins/date/tests.rs | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/boa_engine/src/builtins/date/mod.rs b/boa_engine/src/builtins/date/mod.rs index 9460229aa0f..d6d6d43dd6f 100644 --- a/boa_engine/src/builtins/date/mod.rs +++ b/boa_engine/src/builtins/date/mod.rs @@ -1634,7 +1634,12 @@ impl Date { // 4. Let t be LocalTime(tv). // 5. Return DateString(t). if let Some(t) = tv.0 { - Ok(t.format("%a %b %d %Y").to_string().into()) + Ok(Local::now() + .timezone() + .from_utc_datetime(&t) + .format("%a %b %d %Y") + .to_string() + .into()) } else { Ok(JsString::from("Invalid Date").into()) } diff --git a/boa_engine/src/builtins/date/tests.rs b/boa_engine/src/builtins/date/tests.rs index 7a2eebdacd6..057fd576fd1 100644 --- a/boa_engine/src/builtins/date/tests.rs +++ b/boa_engine/src/builtins/date/tests.rs @@ -1199,7 +1199,7 @@ fn date_proto_to_string() { Some(JsValue::new( Local .from_local_datetime(&NaiveDateTime::new( - NaiveDate::from_ymd(2020, 6, 8), + NaiveDate::from_ymd(2020, 7, 8), NaiveTime::from_hms_milli(9, 16, 15, 779) )) .earliest() @@ -1225,7 +1225,7 @@ fn date_proto_to_time_string() { Some(JsValue::new( Local .from_local_datetime(&NaiveDateTime::new( - NaiveDate::from_ymd(2020, 6, 8), + NaiveDate::from_ymd(2020, 7, 8), NaiveTime::from_hms_milli(9, 16, 15, 779) )) .earliest()