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

Remove now() fn workaround #44

Open
zrzka opened this issue Dec 1, 2018 · 0 comments
Open

Remove now() fn workaround #44

zrzka opened this issue Dec 1, 2018 · 0 comments
Labels
Arch: wasm Web Assembly related Pending: Vendor fix Waiting for a fix in an external crate Type: Enhancement New feature or request

Comments

@zrzka
Copy link
Contributor

zrzka commented Dec 1, 2018

src/context.rs:

#[cfg(not(target_arch = "wasm32"))]
fn utc_now() -> DateTime<Utc> {
    Utc::now()
}

// chrono crate doesn't support wasm32 arch yet, workaround
#[cfg(target_arch = "wasm32")]
fn utc_now() -> DateTime<Utc> {
    let now = js_sys::Date::new_0();
    let millisecs_since_unix_epoch: u64 = now.get_time() as u64;
    let secs = millisecs_since_unix_epoch / 1000;
    let nanos = 1_000_000 * (millisecs_since_unix_epoch - 1000 * secs);
    let naive = NaiveDateTime::from_timestamp(secs as i64, nanos as u32);
    DateTime::from_utc(naive, Utc)
}
@zrzka zrzka added Type: Enhancement New feature or request Arch: wasm Web Assembly related Pending: Vendor fix Waiting for a fix in an external crate labels Dec 1, 2018
@zrzka zrzka changed the title Remove now() workaround Remove now() fn workaround Dec 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch: wasm Web Assembly related Pending: Vendor fix Waiting for a fix in an external crate Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant