Fix emscripten and guard against cargo test + wasm32-unknown-unknown
This commit is contained in:
parent
f52a29398c
commit
f21b1fbf21
|
@ -35,7 +35,8 @@ num-traits = { version = "0.2", default-features = false }
|
||||||
rustc-serialize = { version = "0.3.20", optional = true }
|
rustc-serialize = { version = "0.3.20", optional = true }
|
||||||
serde = { version = "1", optional = true }
|
serde = { version = "1", optional = true }
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
|
||||||
|
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(cargo_web)))'.dependencies]
|
||||||
wasm-bindgen = { version = "0.2" }
|
wasm-bindgen = { version = "0.2" }
|
||||||
js-sys = "0.3" # contains FFI bindings for the JS Date API
|
js-sys = "0.3" # contains FFI bindings for the JS Date API
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ bincode = { version = "0.8.0" }
|
||||||
num-iter = { version = "0.1.35", default-features = false }
|
num-iter = { version = "0.1.35", default-features = false }
|
||||||
doc-comment = "0.3"
|
doc-comment = "0.3"
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
|
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(cargo_web)))'.dev-dependencies]
|
||||||
wasm-bindgen-test = "0.2"
|
wasm-bindgen-test = "0.2"
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
|
|
|
@ -414,11 +414,14 @@ extern crate serde as serdelib;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate doc_comment;
|
extern crate doc_comment;
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(cargo_web)))]
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(cargo_web)))]
|
||||||
extern crate js_sys;
|
extern crate js_sys;
|
||||||
|
|
||||||
|
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), cargo_web))]
|
||||||
|
compile_error!("Chrono currently does not work for wasm32-unknown-unknown + cargo web");
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
doctest!("../README.md");
|
doctest!("../README.md");
|
||||||
|
|
||||||
|
|
|
@ -87,13 +87,13 @@ impl Local {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a `DateTime` which corresponds to the current date.
|
/// Returns a `DateTime` which corresponds to the current date.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
|
||||||
pub fn now() -> DateTime<Local> {
|
pub fn now() -> DateTime<Local> {
|
||||||
tm_to_datetime(oldtime::now())
|
tm_to_datetime(oldtime::now())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a `DateTime` which corresponds to the current date.
|
/// Returns a `DateTime` which corresponds to the current date.
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
|
||||||
pub fn now() -> DateTime<Local> {
|
pub fn now() -> DateTime<Local> {
|
||||||
use super::Utc;
|
use super::Utc;
|
||||||
let now: DateTime<Utc> = super::Utc::now();
|
let now: DateTime<Utc> = super::Utc::now();
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
//! The UTC (Coordinated Universal Time) time zone.
|
//! The UTC (Coordinated Universal Time) time zone.
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
#[cfg(all(feature="clock", not(target_arch = "wasm32")))]
|
#[cfg(all(feature="clock", not(all(target_arch = "wasm32", not(target_os = "emscripten")))))]
|
||||||
use oldtime;
|
use oldtime;
|
||||||
|
|
||||||
use naive::{NaiveDate, NaiveDateTime};
|
use naive::{NaiveDate, NaiveDateTime};
|
||||||
|
@ -38,7 +38,7 @@ impl Utc {
|
||||||
pub fn today() -> Date<Utc> { Utc::now().date() }
|
pub fn today() -> Date<Utc> { Utc::now().date() }
|
||||||
|
|
||||||
/// Returns a `DateTime` which corresponds to the current date.
|
/// Returns a `DateTime` which corresponds to the current date.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
|
||||||
pub fn now() -> DateTime<Utc> {
|
pub fn now() -> DateTime<Utc> {
|
||||||
let spec = oldtime::get_time();
|
let spec = oldtime::get_time();
|
||||||
let naive = NaiveDateTime::from_timestamp(spec.sec, spec.nsec as u32);
|
let naive = NaiveDateTime::from_timestamp(spec.sec, spec.nsec as u32);
|
||||||
|
@ -46,7 +46,7 @@ impl Utc {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a `DateTime` which corresponds to the current date.
|
/// Returns a `DateTime` which corresponds to the current date.
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
|
||||||
pub fn now() -> DateTime<Utc> {
|
pub fn now() -> DateTime<Utc> {
|
||||||
let now = js_sys::Date::new_0();
|
let now = js_sys::Date::new_0();
|
||||||
let millisecs_since_unix_epoch: u64 = now.get_time() as u64;
|
let millisecs_since_unix_epoch: u64 = now.get_time() as u64;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
|
||||||
mod test {
|
mod test {
|
||||||
extern crate chrono;
|
extern crate chrono;
|
||||||
extern crate wasm_bindgen_test;
|
extern crate wasm_bindgen_test;
|
||||||
|
|
Loading…
Reference in New Issue