Skip to content
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

[Merged by Bors] - convert inner datetime to local in to_date_string #1953

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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