diff --git a/.travis.yml b/.travis.yml index ca0e2d0..26d4978 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,16 +16,19 @@ matrix: include: - rust: nightly env: CLIPPY=y + - rust: stable + os: osx + env: WASMBIND=y + - rust: beta + os: osx + env: WASMBIND=y env: global: - LD_LIBRARY_PATH: /usr/local/lib - CLIPPY: n install: - - if [ "$TRAVIS_OS_NAME" = "osx" ]; then source $HOME/.nvm/nvm.sh; fi - - if [ "$TRAVIS_OS_NAME" = "osx" ]; then nvm install 10; fi - - if [ "$TRAVIS_OS_NAME" = "osx" ]; then nvm use 10; fi - - if [ "$TRAVIS_RUST_VERSION" != "1.13.0" ]; then curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh; fi + - if [ "$TRAVIS_OS_NAME" = "osx" ] && [ "$WASMBIND" = "y" ] ; then source ./ci/install-node.sh; fi script: ./ci/travis.sh notifications: email: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 108f9f0..0c8b941 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,15 @@ Chrono obeys the principle of [Semantic Versioning](http://semver.org/). There were/are numerous minor versions before 1.0 due to the language changes. Versions with only mechanical changes will be omitted from the following list. +## 0.4.9 + +### Fixes + +* Make Datetime arithmatic adjust their offsets after discovering their new + timestamps (@quodlibetor #337) +* Put wasm-bindgen related code and dependencies behind a `wasmbind` feature + gate. (@quodlibetor #335) + ## 0.4.8 ### Fixes diff --git a/Cargo.toml b/Cargo.toml index ecb2dcf..4ef98fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ name = "chrono" [features] default = ["clock"] clock = ["time"] +wasmbind = ["wasm-bindgen", "js-sys"] [dependencies] libc = { version = "0.2", default-features = false } @@ -35,10 +36,9 @@ num-traits = { version = "0.2", default-features = false } rustc-serialize = { version = "0.3.20", optional = true } serde = { version = "1", optional = true } - [target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies] -wasm-bindgen = { version = "0.2" } -js-sys = "0.3" # contains FFI bindings for the JS Date API +wasm-bindgen = { version = "0.2", optional = true } +js-sys = { version = "0.3", optional = true } # contains FFI bindings for the JS Date API [dev-dependencies] serde_json = { version = "1" } diff --git a/ci/install-node.sh b/ci/install-node.sh new file mode 100644 index 0000000..65318b3 --- /dev/null +++ b/ci/install-node.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +echo "installing node via nvm" + +source "$HOME/.nvm/nvm.sh" +nvm install 10 +nvm use 10 +curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh diff --git a/ci/travis.sh b/ci/travis.sh index 2747fee..04dfe83 100755 --- a/ci/travis.sh +++ b/ci/travis.sh @@ -29,6 +29,21 @@ build_and_test() { # also vary the local time zone to (hopefully) catch tz-dependent bugs # also avoid doc-testing multiple times---it takes a lot and rarely helps cargo clean + + if [ "${WASMBIND}" != "y" ]; then + build_and_test_nonwasm + else + build_and_test_wasm + fi + + if [[ "$CHANNEL" == stable ]]; then + if [[ -n "$TRAVIS" ]] ; then + check_readme + fi + fi +} + +build_and_test_nonwasm() { channel build -v TZ=ACST-9:30 channel test -v --lib channel build -v --features rustc-serialize @@ -47,9 +62,11 @@ build_and_test() { TZ=UTC0 channel test -v --no-default-features --features serde --lib channel build -v --no-default-features --features serde,rustc-serialize TZ=Asia/Katmandu channel test -v --no-default-features --features serde,rustc-serialize --lib +} + +build_and_test_wasm() { + channel build --features wasmbind -v - if [ -n "${TRAVIS}" ] && [ "${TRAVIS_RUST_VERSION}" != "1.13.0" ]; then - # wasm tests touch tests/wasm.rs # ensure rebuild happens so TZ / NOW take effect TZ=ACST-9:30 NOW=$(date +%s) wasm-pack test --node touch tests/wasm.rs @@ -58,13 +75,6 @@ build_and_test() { TZ=UTC0 NOW=$(date +%s) wasm-pack test --node touch tests/wasm.rs TZ=Asia/Katmandu NOW=$(date +%s) wasm-pack test --node - fi - - if [[ "$CHANNEL" == stable ]]; then - if [[ -n "$TRAVIS" ]] ; then - check_readme - fi - fi } build_only() { diff --git a/src/lib.rs b/src/lib.rs index 2962e65..b43fa0d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -414,9 +414,9 @@ extern crate serde as serdelib; #[cfg(test)] #[macro_use] extern crate doc_comment; -#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] +#[cfg(all(target_arch = "wasm32", feature="wasmbind"))] extern crate wasm_bindgen; -#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] +#[cfg(all(target_arch = "wasm32", feature="wasmbind"))] extern crate js_sys; #[cfg(test)] diff --git a/src/offset/local.rs b/src/offset/local.rs index 68c27c4..70c01e6 100644 --- a/src/offset/local.rs +++ b/src/offset/local.rs @@ -87,13 +87,13 @@ impl Local { } /// Returns a `DateTime` which corresponds to the current date. - #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + #[cfg(not(all(target_arch = "wasm32", feature = "wasmbind")))] pub fn now() -> DateTime { tm_to_datetime(oldtime::now()) } /// Returns a `DateTime` which corresponds to the current date. - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(all(target_arch = "wasm32", feature = "wasmbind"))] pub fn now() -> DateTime { use super::Utc; let now: DateTime = super::Utc::now(); diff --git a/src/offset/utc.rs b/src/offset/utc.rs index 36f4e5f..87a4fba 100644 --- a/src/offset/utc.rs +++ b/src/offset/utc.rs @@ -4,7 +4,7 @@ //! The UTC (Coordinated Universal Time) time zone. use std::fmt; -#[cfg(all(feature="clock", not(all(target_arch = "wasm32", not(target_os = "emscripten")))))] +#[cfg(all(feature="clock", not(all(target_arch = "wasm32", feature = "wasmbind"))))] use oldtime; use naive::{NaiveDate, NaiveDateTime}; @@ -38,7 +38,7 @@ impl Utc { pub fn today() -> Date { Utc::now().date() } /// Returns a `DateTime` which corresponds to the current date. - #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + #[cfg(not(all(target_arch = "wasm32", feature = "wasmbind")))] pub fn now() -> DateTime { let spec = oldtime::get_time(); 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. - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(all(target_arch = "wasm32", feature = "wasmbind"))] pub fn now() -> DateTime { let now = js_sys::Date::new_0(); let millisecs_since_unix_epoch: u64 = now.get_time() as u64; diff --git a/tests/wasm.rs b/tests/wasm.rs index b95d9f0..e125372 100644 --- a/tests/wasm.rs +++ b/tests/wasm.rs @@ -1,4 +1,4 @@ -#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] +#[cfg(all(target_arch = "wasm32", feature = "wasmbind"))] mod test { extern crate chrono; extern crate wasm_bindgen_test;