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

Fix wasm32-unknown-unknown build #655

Merged
merged 2 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion time/src/offset_date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,7 @@ impl From<js_sys::Date> for OffsetDateTime {
///
/// This may panic if the timestamp can not be represented.
fn from(js_date: js_sys::Date) -> Self {
use time_core::convert::Millisecond;
jedel1043 marked this conversation as resolved.
Show resolved Hide resolved
// get_time() returns milliseconds
let timestamp_nanos = (js_date.get_time() * Nanosecond::per(Millisecond) as f64) as i128;
Self::from_unix_timestamp_nanos(timestamp_nanos)
Expand All @@ -1610,11 +1611,12 @@ impl From<js_sys::Date> for OffsetDateTime {
))]
impl From<OffsetDateTime> for js_sys::Date {
fn from(datetime: OffsetDateTime) -> Self {
use time_core::convert::Millisecond;
// new Date() takes milliseconds
let timestamp = (datetime.unix_timestamp_nanos()
/ Nanosecond::per(Millisecond).cast_signed().extend::<i128>())
as f64;
js_sys::Date::new(&timestamp.into())
Self::new(&timestamp.into())
}
}
// endregion trait impls
2 changes: 2 additions & 0 deletions time/src/sys/local_offset_at/wasm_js.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use num_conv::{CastSigned, Extend};
jedel1043 marked this conversation as resolved.
Show resolved Hide resolved

use crate::convert::*;
use crate::{OffsetDateTime, UtcOffset};

Expand Down
Loading