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

Add initial support for the wasm32 arch #287

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions Cargo.toml
Expand Up @@ -24,20 +24,36 @@ name = "chrono"

[features]
default = ["clock"]
clock = ["time"]
clock = []

[dependencies]
time = { version = "0.1.39", optional = true }
num-integer = { version = "0.1.36", default-features = false }
num-traits = { version = "0.2", default-features = false }
rustc-serialize = { version = "0.3.20", optional = true }
serde = { version = "1", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = { version = "0.2" }
js-sys = "0.3" # contains FFI bindings for the JS Date API

[target.'cfg(unix)'.dependencies]
libc = "0.2.1"

[target.'cfg(target_os = "redox")'.dependencies]
redox_syscall = "0.1"
libc = "0.2.1"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.0", features = ["std", "minwinbase", "minwindef", "ntdef", "profileapi", "sysinfoapi", "timezoneapi"] }
libc = "0.2.1"

[dev-dependencies]
serde_json = { version = "1" }
serde_derive = { version = "1" }
bincode = { version = "0.8.0" }
num-iter = { version = "0.1.35", default-features = false }
log = "0.4"
winapi = { version = "0.3.0", features = ["std", "processthreadsapi", "winbase"] }

[package.metadata.docs.rs]
all-features = true
Expand Down
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -172,8 +172,7 @@ Addition and subtraction is also supported.
The following illustrates most supported operations to the date and time:

```rust
use chrono::prelude::*;
use time::Duration;
use chrono::{prelude::*, Duration};

// assume this returned `2014-11-28T21:45:59.324310806+09:00`:
let dt = Local::now();
Expand Down
31 changes: 23 additions & 8 deletions src/lib.rs
Expand Up @@ -158,9 +158,8 @@
//! The following illustrates most supported operations to the date and time:
//!
//! ```rust
//! # extern crate chrono; extern crate time; fn main() {
//! use chrono::prelude::*;
//! use time::Duration;
//! # extern crate chrono; fn main() {
//! use chrono::{prelude::*, Duration};
//!
//! # /* we intentionally fake the datetime...
//! // assume this returned `2014-11-28T21:45:59.324310806+09:00`:
Expand Down Expand Up @@ -405,17 +404,35 @@
trivially_copy_pass_by_ref,
))]

#[cfg(feature="clock")]
extern crate time as oldtime;

// These are required by the `time` module:
#[cfg(all(feature="clock", target_os = "redox"))]
extern crate syscall;
#[cfg(unix)]
extern crate libc;
#[cfg(all(feature="clock", windows))]
extern crate winapi;
#[cfg(test)]
#[macro_use]
extern crate log;

extern crate num_integer;
extern crate num_traits;
#[cfg(feature = "rustc-serialize")]
extern crate rustc_serialize;
#[cfg(feature = "serde")]
extern crate serde as serdelib;
#[cfg(target_arch = "wasm32")]
extern crate wasm_bindgen;
#[cfg(target_arch = "wasm32")]
extern crate js_sys;


pub mod time;
pub use time::{Duration, PreciseTime, SteadyTime};

pub use time as oldtime;
// this reexport is to aid the transition and should not be in the prelude!
pub use oldtime::Duration;

#[cfg(feature="clock")]
#[doc(no_inline)] pub use offset::Local;
Expand Down Expand Up @@ -447,8 +464,6 @@ macro_rules! try_opt {
}

mod div;
#[cfg(not(feature="clock"))]
mod oldtime;
pub mod offset;
pub mod naive {
//! Date and time types which do not concern about the timezones.
Expand Down
35 changes: 14 additions & 21 deletions src/naive/date.rs
Expand Up @@ -788,10 +788,9 @@ impl NaiveDate {
/// # Example
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// use chrono::NaiveDate;
/// # extern crate chrono; fn main() {
/// use chrono::{NaiveDate, Duration};
/// use chrono::naive::MAX_DATE;
/// use time::Duration;
///
/// let d = NaiveDate::from_ymd(2015, 9, 5);
/// assert_eq!(d.checked_add_signed(Duration::days(40)),
Expand Down Expand Up @@ -824,10 +823,9 @@ impl NaiveDate {
/// # Example
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// use chrono::NaiveDate;
/// # extern crate chrono; fn main() {
/// use chrono::{NaiveDate, Duration};
/// use chrono::naive::MIN_DATE;
/// use time::Duration;
///
/// let d = NaiveDate::from_ymd(2015, 9, 5);
/// assert_eq!(d.checked_sub_signed(Duration::days(40)),
Expand Down Expand Up @@ -862,9 +860,8 @@ impl NaiveDate {
/// # Example
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// use chrono::NaiveDate;
/// use time::Duration;
/// # extern crate chrono; fn main() {
/// use chrono::{NaiveDate, Duration};
///
/// let from_ymd = NaiveDate::from_ymd;
/// let since = NaiveDate::signed_duration_since;
Expand Down Expand Up @@ -1311,9 +1308,8 @@ impl Datelike for NaiveDate {
/// # Example
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// use chrono::NaiveDate;
/// use time::Duration;
/// # extern crate chrono; fn main() {
/// use chrono::{NaiveDate, Duration};
///
/// let from_ymd = NaiveDate::from_ymd;
///
Expand Down Expand Up @@ -1353,9 +1349,8 @@ impl AddAssign<OldDuration> for NaiveDate {
/// # Example
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// use chrono::NaiveDate;
/// use time::Duration;
/// # extern crate chrono; fn main() {
/// use chrono::{NaiveDate, Duration};
///
/// let from_ymd = NaiveDate::from_ymd;
///
Expand Down Expand Up @@ -1387,7 +1382,7 @@ impl SubAssign<OldDuration> for NaiveDate {

/// Subtracts another `NaiveDate` from the current date.
/// Returns a `Duration` of integral numbers.
///
///
/// This does not overflow or underflow at all,
/// as all possible output fits in the range of `Duration`.
///
Expand All @@ -1397,9 +1392,8 @@ impl SubAssign<OldDuration> for NaiveDate {
/// # Example
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// use chrono::NaiveDate;
/// use time::Duration;
/// # extern crate chrono; fn main() {
/// use chrono::{NaiveDate, Duration};
///
/// let from_ymd = NaiveDate::from_ymd;
///
Expand Down Expand Up @@ -1629,7 +1623,7 @@ mod serde {
impl<'de> de::Visitor<'de> for NaiveDateVisitor {
type Value = NaiveDate;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result
{
write!(formatter, "a formatted date string")
}
Expand Down Expand Up @@ -2118,4 +2112,3 @@ mod tests {
"2009,09,01,00,53");
}
}

70 changes: 28 additions & 42 deletions src/naive/datetime.rs
Expand Up @@ -402,9 +402,8 @@ impl NaiveDateTime {
/// # Example
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// use chrono::NaiveDate;
/// use time::Duration;
/// # extern crate chrono; fn main() {
/// use chrono::{NaiveDate, Duration};
///
/// let from_ymd = NaiveDate::from_ymd;
///
Expand All @@ -430,9 +429,8 @@ impl NaiveDateTime {
/// Overflow returns `None`.
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// # use chrono::NaiveDate;
/// # use time::Duration;
/// # extern crate chrono; fn main() {
/// # use chrono::{NaiveDate, Duration};
/// # let hms = |h, m, s| NaiveDate::from_ymd(2016, 7, 8).and_hms(h, m, s);
/// assert_eq!(hms(3, 5, 7).checked_add_signed(Duration::days(1_000_000_000)), None);
/// # }
Expand All @@ -442,9 +440,8 @@ impl NaiveDateTime {
/// but the addition assumes that it is the only leap second happened.
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// # use chrono::NaiveDate;
/// # use time::Duration;
/// # extern crate chrono; fn main() {
/// # use chrono::{NaiveDate, Duration};
/// # let from_ymd = NaiveDate::from_ymd;
/// # let hmsm = |h, m, s, milli| from_ymd(2016, 7, 8).and_hms_milli(h, m, s, milli);
/// let leap = hmsm(3, 5, 59, 1_300);
Expand Down Expand Up @@ -488,9 +485,8 @@ impl NaiveDateTime {
/// # Example
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// use chrono::NaiveDate;
/// use time::Duration;
/// # extern crate chrono; fn main() {
/// use chrono::{NaiveDate, Duration};
///
/// let from_ymd = NaiveDate::from_ymd;
///
Expand All @@ -516,9 +512,8 @@ impl NaiveDateTime {
/// Overflow returns `None`.
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// # use chrono::NaiveDate;
/// # use time::Duration;
/// # extern crate chrono; fn main() {
/// # use chrono::{NaiveDate, Duration};
/// # let hms = |h, m, s| NaiveDate::from_ymd(2016, 7, 8).and_hms(h, m, s);
/// assert_eq!(hms(3, 5, 7).checked_sub_signed(Duration::days(1_000_000_000)), None);
/// # }
Expand All @@ -528,9 +523,8 @@ impl NaiveDateTime {
/// but the subtraction assumes that it is the only leap second happened.
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// # use chrono::NaiveDate;
/// # use time::Duration;
/// # extern crate chrono; fn main() {
/// # use chrono::{NaiveDate, Duration};
/// # let from_ymd = NaiveDate::from_ymd;
/// # let hmsm = |h, m, s, milli| from_ymd(2016, 7, 8).and_hms_milli(h, m, s, milli);
/// let leap = hmsm(3, 5, 59, 1_300);
Expand Down Expand Up @@ -570,9 +564,8 @@ impl NaiveDateTime {
/// # Example
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// use chrono::NaiveDate;
/// use time::Duration;
/// # extern crate chrono; fn main() {
/// use chrono::{NaiveDate, Duration};
///
/// let from_ymd = NaiveDate::from_ymd;
///
Expand All @@ -591,9 +584,8 @@ impl NaiveDateTime {
/// there were no other leap seconds happened.
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// # use chrono::NaiveDate;
/// # use time::Duration;
/// # extern crate chrono; fn main() {
/// # use chrono::{NaiveDate, Duration};
/// # let from_ymd = NaiveDate::from_ymd;
/// let leap = from_ymd(2015, 6, 30).and_hms_milli(23, 59, 59, 1_500);
/// assert_eq!(leap.signed_duration_since(from_ymd(2015, 6, 30).and_hms(23, 0, 0)),
Expand Down Expand Up @@ -1188,9 +1180,8 @@ impl hash::Hash for NaiveDateTime {
/// # Example
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// use chrono::NaiveDate;
/// use time::Duration;
/// # extern crate chrono; fn main() {
/// use chrono::{NaiveDate, Duration};
///
/// let from_ymd = NaiveDate::from_ymd;
///
Expand All @@ -1214,9 +1205,8 @@ impl hash::Hash for NaiveDateTime {
/// but the addition assumes that it is the only leap second happened.
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// # use chrono::NaiveDate;
/// # use time::Duration;
/// # extern crate chrono; fn main() {
/// # use chrono::{NaiveDate, Duration};
/// # let from_ymd = NaiveDate::from_ymd;
/// # let hmsm = |h, m, s, milli| from_ymd(2016, 7, 8).and_hms_milli(h, m, s, milli);
/// let leap = hmsm(3, 5, 59, 1_300);
Expand Down Expand Up @@ -1260,9 +1250,8 @@ impl AddAssign<OldDuration> for NaiveDateTime {
/// # Example
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// use chrono::NaiveDate;
/// use time::Duration;
/// # extern crate chrono; fn main() {
/// use chrono::{NaiveDate, Duration};
///
/// let from_ymd = NaiveDate::from_ymd;
///
Expand All @@ -1286,9 +1275,8 @@ impl AddAssign<OldDuration> for NaiveDateTime {
/// but the subtraction assumes that it is the only leap second happened.
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// # use chrono::NaiveDate;
/// # use time::Duration;
/// # extern crate chrono; fn main() {
/// # use chrono::{NaiveDate, Duration};
/// # let from_ymd = NaiveDate::from_ymd;
/// # let hmsm = |h, m, s, milli| from_ymd(2016, 7, 8).and_hms_milli(h, m, s, milli);
/// let leap = hmsm(3, 5, 59, 1_300);
Expand Down Expand Up @@ -1331,9 +1319,8 @@ impl SubAssign<OldDuration> for NaiveDateTime {
/// # Example
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// use chrono::NaiveDate;
/// use time::Duration;
/// # extern crate chrono; fn main() {
/// use chrono::{NaiveDate, Duration};
///
/// let from_ymd = NaiveDate::from_ymd;
///
Expand All @@ -1351,9 +1338,8 @@ impl SubAssign<OldDuration> for NaiveDateTime {
/// there were no other leap seconds happened.
///
/// ~~~~
/// # extern crate chrono; extern crate time; fn main() {
/// # use chrono::NaiveDate;
/// # use time::Duration;
/// # extern crate chrono; fn main() {
/// # use chrono::{NaiveDate, Duration};
/// # let from_ymd = NaiveDate::from_ymd;
/// let leap = from_ymd(2015, 6, 30).and_hms_milli(23, 59, 59, 1_500);
/// assert_eq!(leap - from_ymd(2015, 6, 30).and_hms(23, 0, 0),
Expand Down