File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -33,8 +33,25 @@ impl InstantProvider<embassy_time::Duration> for embassy_time::Instant {
3333}
3434
3535#[ cfg( feature = "wasm" ) ]
36- impl InstantProvider < Duration > for js_sys:: Date {
36+ /// A wrapper around `js_sys::Date` that implements `InstantProvider`.
37+ ///
38+ /// This type stores the timestamp as milliseconds since the Unix epoch.
39+ #[ derive( Clone , PartialEq ) ]
40+ pub struct JsInstant ( f64 ) ;
41+
42+ #[ cfg( feature = "wasm" ) ]
43+ impl Sub for JsInstant {
44+ type Output = Duration ;
45+
46+ fn sub ( self , rhs : Self ) -> Self :: Output {
47+ let delta_ms = self . 0 - rhs. 0 ;
48+ Duration :: from_millis ( delta_ms as u64 )
49+ }
50+ }
51+
52+ #[ cfg( feature = "wasm" ) ]
53+ impl InstantProvider < Duration > for JsInstant {
3754 fn now ( ) -> Self {
38- js_sys:: Date :: new_0 ( )
55+ JsInstant ( js_sys:: Date :: now ( ) )
3956 }
4057}
Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ pub use config::{ButtonConfig, Mode};
88pub use instant:: InstantProvider ;
99pub use pin_wrapper:: PinWrapper ;
1010
11+ #[ cfg( feature = "wasm" ) ]
12+ pub use instant:: JsInstant ;
13+
1114/// Button configuration.
1215pub mod config;
1316/// Different current global time sources.
You can’t perform that action at this time.
0 commit comments