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

Absorb the time crate #286

Closed
wants to merge 8 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Versions with only mechanical changes will be omitted from the following list.
### Internal improvements

* Use Criterion for benchmarks (@quodlibetor)
* Absorb the time crate so that we no longer depend on a deprecated external
package (@jjpe in #286)

## 0.4.10

Expand Down
19 changes: 17 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ name = "chrono"
default = ["clock", "std"]
alloc = []
std = []
clock = ["time", "std"]
clock = ["std"]
wasmbind = ["wasm-bindgen", "js-sys"]
__internal_bench = []

[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 }
Expand All @@ -42,13 +41,29 @@ serde = { version = "1.0.99", default-features = false, optional = true }
wasm-bindgen = { version = "0.2", optional = true }
js-sys = { version = "0.3", optional = true } # 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"

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
mach = "0.3"

[dev-dependencies]
serde_json = { version = "1", default-features = false }
serde_derive = { version = "1", default-features = false }
bincode = { version = "0.8.0" }
num-iter = { version = "0.1.35", default-features = false }
criterion = { version = "0.3" }
doc-comment = "0.3"
log = "0.4"

[target.'cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))'.dev-dependencies]
wasm-bindgen-test = "0.2"
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ use chrono::prelude::*;
### Duration

Chrono currently uses
the [`time::Duration`](https://docs.rs/time/0.1.40/time/struct.Duration.html) type
from the `time` crate to represent the magnitude of a time span.
the [`Duration`](https://docs.rs/chrono/struct.Duration.html) type
in the `time` module to represent the magnitude of a time span.
Since this has the same name to the newer, standard type for duration,
the reference will refer this type as `OldDuration`.
Note that this is an "accurate" duration represented as seconds and
Expand All @@ -98,9 +98,9 @@ type to represent a date and a time in a timezone.

For more abstract moment-in-time tracking such as internal timekeeping
that is unconcerned with timezones, consider
[`time::SystemTime`](https://doc.rust-lang.org/std/time/struct.SystemTime.html),
[`SystemTime`](https://doc.rust-lang.org/std/time/struct.SystemTime.html),
which tracks your system clock, or
[`time::Instant`](https://doc.rust-lang.org/std/time/struct.Instant.html), which
[`Instant`](https://doc.rust-lang.org/std/time/struct.Instant.html), which
is an opaque but monotonically-increasing representation of a moment in time.

`DateTime` is timezone-aware and must be constructed from
Expand Down Expand Up @@ -175,7 +175,7 @@ The following illustrates most supported operations to the date and time:
extern crate time;

use chrono::prelude::*;
use time::Duration;
use chrono::Duration;

// assume this returned `2014-11-28T21:45:59.324310806+09:00`:
let dt = FixedOffset::east(9*3600).ymd(2014, 11, 28).and_hms_nano(21, 45, 59, 324310806);
Expand Down Expand Up @@ -390,4 +390,3 @@ and consequently `Utc.ymd(2014, 1, 30).with_month(2)` returns `None`.

Advanced time zone handling is not yet supported.
For now you can try the [Chrono-tz](https://github.com/chronotope/chrono-tz/) crate instead.

37 changes: 23 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +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};
//!
//! // assume this returned `2014-11-28T21:45:59.324310806+09:00`:
//! let dt = FixedOffset::east(9*3600).ymd(2014, 11, 28).and_hms_nano(21, 45, 59, 324310806);
Expand Down Expand Up @@ -413,29 +409,44 @@ extern crate std as core;
#[cfg(all(feature = "std", not(feature="alloc")))]
extern crate std as alloc;

#[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(all(feature="clock", any(target_os = "macos", target_os = "ios")))]
extern crate mach;
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(test)]
#[macro_use]
extern crate doc_comment;
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))]
extern crate wasm_bindgen;
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))]
extern crate js_sys;
#[cfg(feature = "bench")]
extern crate test;

#[cfg(test)]
#[macro_use]
extern crate log;
#[cfg(test)]
#[macro_use]
extern crate doc_comment;

#[cfg(test)]
doctest!("../README.md");


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 @@ -467,8 +478,6 @@ macro_rules! try_opt {
}

mod div;
#[cfg(not(feature="clock"))]
mod oldtime;
pub mod offset;
pub mod naive {
//! Date and time types unconcerned with timezones.
Expand Down
31 changes: 12 additions & 19 deletions src/naive/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,10 +841,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 @@ -877,10 +876,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 @@ -915,9 +913,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 @@ -1366,9 +1363,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 @@ -1408,9 +1404,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 @@ -1452,9 +1447,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 @@ -2199,4 +2193,3 @@ mod tests {
"2009,09,01,00,53");
}
}

Loading