-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Adds support for using hifitime in WASM targets #262
Adds support for using hifitime in WASM targets #262
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #262 +/- ##
==========================================
+ Coverage 80.67% 80.74% +0.06%
==========================================
Files 15 16 +1
Lines 3746 3754 +8
==========================================
+ Hits 3022 3031 +9
+ Misses 724 723 -1 ☔ View full report in Codecov by Sentry. |
Since the I'll have a look at doing this over the weekend. |
71ed764
to
ed3a9c7
Compare
@ChristopherRabotin I have moved over what I think is the minimal amount of code to get things going. The The new dependencies are restricted to wasm targets. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, this is exactly what I was asking for. I just have a few comments to use the Unit time in hifitime for the unit conversion from seconds to a Duration structure, and that should be good to merge.
src/system_time.rs
Outdated
pub(crate) fn now() -> f64 { | ||
std::time::SystemTime::now().duration_since(std::time::SystemTime::UNIX_EPOCH) | ||
.expect("System clock was before 1970.") | ||
.as_secs_f64() * 1000.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.as_secs_f64() * 1000.0 | |
.as_secs_f64() * Unit::Second |
By using the Unit enum, the now()
function would directly return a Duration
, so the function could be directly duration_since_unix_epoch()
I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea! I have refactored system_time:: duration_since_unix_epoch()
to directly return hifitime::Duration
src/system_time.rs
Outdated
@@ -0,0 +1,27 @@ | |||
use std::time::Duration; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this import be moved into the now()
function on line 16?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is also used in the return type for duration_since_unix_epoch
No longer relevant as I am now using hifitime::Duration
ed3a9c7
to
422a596
Compare
422a596
to
1e3ea72
Compare
Ok(std_duration) => Ok(Self::from_unix_seconds(std_duration.as_secs_f64())), | ||
Err(_) => Err(Errors::SystemTimeError), | ||
} | ||
let duration = crate::system_time::duration_since_unix_epoch()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this needs to be "from unix duration" now, otherwise it assumes that the reference epoch is J1900 (the TAI ref epoch), but unix seconds are wrt 01 January 1970
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not find a from_unix_duration()
. Should I add it?
Ah, right, seems like it's only on the version 4 development branch. Just
call the from unix seconds :
https://docs.rs/hifitime/latest/hifitime/struct.Epoch.html#method.from_unix_seconds
…On Sat, Dec 9, 2023, 23:19 Thomas Antony ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/epoch.rs
<#262 (comment)>:
> pub fn now() -> Result<Self, Errors> {
- match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
- Ok(std_duration) => Ok(Self::from_unix_seconds(std_duration.as_secs_f64())),
- Err(_) => Err(Errors::SystemTimeError),
- }
+ let duration = crate::system_time::duration_since_unix_epoch()?;
I could not find a from_unix_duration(). Should I add it?
—
Reply to this email directly, view it on GitHub
<#262 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABEZV2AS6RSUO57QSFVADJDYIVH6DAVCNFSM6AAAAABAIYSNUWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTONZTHE3TEMRSGI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
1e3ea72
to
85af13f
Compare
I created a |
Looks good, thank you |
std::time::SystemClock::now()
does not work in the browser. The instant provides an alternative that works in the browser and falls back tostd::time::SystemClock
on non-WASM targets. I have added a newweb
feature flag that enables the extra features from theinstant
crate.This is required for running the ANISE gui in the browser.