Skip to content

Commit

Permalink
convert inner datetime to local in to_date_string
Browse files Browse the repository at this point in the history
`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`).
  • Loading branch information
superhawk610 committed Mar 17, 2022
1 parent aaa07cf commit 82101ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion boa_engine/src/builtins/date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/builtins/date/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 82101ba

Please sign in to comment.