Use web-time to return a SystemTime that works under WASM

The `MilliSecondsSinceUnixEpoch::to_system_time()` method returns the
`SystemTime` type from the standard library.

The `std::time::SystemTime::elapsed()` method sadly panics under WASM.
Instead of returning the `SystemTime` from the standard library we're
now returning a drop-in replacement of this type coming from the web-time
crate.
This commit is contained in:
Damir Jelić 2024-03-20 12:19:18 +01:00 committed by GitHub
parent 6c4d1c0fd7
commit ccd3b81557
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 1 deletions

View File

@ -14,6 +14,9 @@ Breaking changes:
Improvements:
- Use the [web-time](https://github.com/daxpedda/web-time) crate to return a
`SystemTime` that works under WASM in the
`MilliSecondsSinceUnixEpoch::to_system_time()` method.
- Stabilize support for `.m.rule.suppress_edits` push rule (MSC3958 / Matrix 1.9)
- Add `MatrixVersion::V1_9`
- Point links to the Matrix 1.9 specification

View File

@ -77,6 +77,7 @@ time = "0.3.34"
tracing = { workspace = true, features = ["attributes"] }
url = "2.2.2"
uuid = { version = "1.0.0", optional = true, features = ["v4"] }
web-time = "1.1.0"
wildmatch = "2.0.0"
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]

View File

@ -1,11 +1,12 @@
use std::{
fmt,
time::{Duration, SystemTime, UNIX_EPOCH},
time::{Duration, UNIX_EPOCH},
};
use js_int::{uint, UInt};
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
use web_time::SystemTime;
/// A timestamp represented as the number of milliseconds since the unix epoch.
#[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]