From e2ddee2f764c8779ebf959008915bcbb8bc39994 Mon Sep 17 00:00:00 2001 From: Kang Seonghoon Date: Mon, 5 Jan 2015 18:31:15 +0900 Subject: [PATCH] 0.1.9: language changes. - `Add` and `Sub` switches to associated types. --- Cargo.toml | 4 ++-- README.md | 2 +- src/date.rs | 16 ++++++++++++---- src/datetime.rs | 16 ++++++++++++---- src/lib.rs | 2 +- src/naive/date.rs | 16 ++++++++++++---- src/naive/datetime.rs | 16 ++++++++++++---- src/naive/time.rs | 16 ++++++++++++---- src/time.rs | 16 ++++++++++++---- 9 files changed, 76 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 530bf1c..2a089e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chrono" -version = "0.1.8" +version = "0.1.9" authors = ["Kang Seonghoon "] description = "Date and time library for Rust" @@ -15,5 +15,5 @@ license = "MIT/Apache-2.0" name = "chrono" [dependencies] -time = "0.1.7" +time = "0.1.9" diff --git a/README.md b/README.md index 1662391..db5dd7f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[Chrono][doc] 0.1.8 +[Chrono][doc] 0.1.9 =================== [![Chrono on Travis CI][travis-image]][travis] diff --git a/src/date.rs b/src/date.rs index 696e19f..636ad9c 100644 --- a/src/date.rs +++ b/src/date.rs @@ -263,22 +263,30 @@ impl hash::Hash for Date { fn hash(&self, state: &mut hash::sip::SipState) { self.date.hash(state) } } -impl Add> for Date { +impl Add for Date { + type Output = Date; + fn add(self, rhs: Duration) -> Date { Date { date: self.date + rhs, offset: self.offset } } } -impl Add,Date> for Duration { +impl Add> for Duration { + type Output = Date; + #[inline] fn add(self, rhs: Date) -> Date { rhs.add(self) } } -impl Sub,Duration> for Date { +impl Sub> for Date { + type Output = Duration; + fn sub(self, rhs: Date) -> Duration { self.date - rhs.date } } -impl Sub> for Date { +impl Sub for Date { + type Output = Date; + #[inline] fn sub(self, rhs: Duration) -> Date { self.add(-rhs) } } diff --git a/src/datetime.rs b/src/datetime.rs index 47f4171..26951a6 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -184,22 +184,30 @@ impl hash::Hash for DateTime { fn hash(&self, state: &mut hash::sip::SipState) { self.datetime.hash(state) } } -impl Add> for DateTime { +impl Add for DateTime { + type Output = DateTime; + fn add(self, rhs: Duration) -> DateTime { DateTime { datetime: self.datetime + rhs, offset: self.offset } } } -impl Add,DateTime> for Duration { +impl Add> for Duration { + type Output = DateTime; + #[inline] fn add(self, rhs: DateTime) -> DateTime { rhs.add(self) } } -impl Sub,Duration> for DateTime { +impl Sub> for DateTime { + type Output = Duration; + fn sub(self, rhs: DateTime) -> Duration { self.datetime - rhs.datetime } } -impl Sub> for DateTime { +impl Sub for DateTime { + type Output = DateTime; + #[inline] fn sub(self, rhs: Duration) -> DateTime { self.add(-rhs) } } diff --git a/src/lib.rs b/src/lib.rs index 42ac92a..636d5d7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ /*! -# Chrono 0.1.8 +# Chrono 0.1.9 Date and time handling for Rust. (also known as `rust-chrono`) It aims to be a feature-complete superset of the [time](https://github.com/rust-lang/time) library. diff --git a/src/naive/date.rs b/src/naive/date.rs index b6c3c41..e8971e3 100644 --- a/src/naive/date.rs +++ b/src/naive/date.rs @@ -378,7 +378,9 @@ impl Datelike for NaiveDate { } } -impl Add for NaiveDate { +impl Add for NaiveDate { + type Output = NaiveDate; + fn add(self, rhs: Duration) -> NaiveDate { // TODO overflow currently fails @@ -396,12 +398,16 @@ impl Add for NaiveDate { } } -impl Add for Duration { +impl Add for Duration { + type Output = NaiveDate; + #[inline] fn add(self, rhs: NaiveDate) -> NaiveDate { rhs.add(self) } } -impl Sub for NaiveDate { +impl Sub for NaiveDate { + type Output = Duration; + fn sub(self, rhs: NaiveDate) -> Duration { let year1 = self.year(); let year2 = rhs.year(); @@ -413,7 +419,9 @@ impl Sub for NaiveDate { } } -impl Sub for NaiveDate { +impl Sub for NaiveDate { + type Output = NaiveDate; + #[inline] fn sub(self, rhs: Duration) -> NaiveDate { self.add(-rhs) } } diff --git a/src/naive/datetime.rs b/src/naive/datetime.rs index 074e4a2..657e0bf 100644 --- a/src/naive/datetime.rs +++ b/src/naive/datetime.rs @@ -163,7 +163,9 @@ impl Timelike for NaiveDateTime { } } -impl Add for NaiveDateTime { +impl Add for NaiveDateTime { + type Output = NaiveDateTime; + fn add(self, rhs: Duration) -> NaiveDateTime { // Duration does not directly give its parts, so we need some additional calculations. let days = rhs.num_days(); @@ -184,18 +186,24 @@ impl Add for NaiveDateTime { } } -impl Add for Duration { +impl Add for Duration { + type Output = NaiveDateTime; + #[inline] fn add(self, rhs: NaiveDateTime) -> NaiveDateTime { rhs.add(self) } } -impl Sub for NaiveDateTime { +impl Sub for NaiveDateTime { + type Output = Duration; + fn sub(self, rhs: NaiveDateTime) -> Duration { (self.date - rhs.date) + (self.time - rhs.time) } } -impl Sub for NaiveDateTime { +impl Sub for NaiveDateTime { + type Output = NaiveDateTime; + #[inline] fn sub(self, rhs: Duration) -> NaiveDateTime { self.add(-rhs) } } diff --git a/src/naive/time.rs b/src/naive/time.rs index 9a42068..bad92ed 100644 --- a/src/naive/time.rs +++ b/src/naive/time.rs @@ -172,7 +172,9 @@ impl Timelike for NaiveTime { } } -impl Add for NaiveTime { +impl Add for NaiveTime { + type Output = NaiveTime; + fn add(self, rhs: Duration) -> NaiveTime { // there is no direct interface in `Duration` to get only the nanosecond part, // so we need to do the additional calculation here. @@ -191,12 +193,16 @@ impl Add for NaiveTime { } } -impl Add for Duration { +impl Add for Duration { + type Output = NaiveTime; + #[inline] fn add(self, rhs: NaiveTime) -> NaiveTime { rhs.add(self) } } -impl Sub for NaiveTime { +impl Sub for NaiveTime { + type Output = Duration; + fn sub(self, rhs: NaiveTime) -> Duration { // the number of whole non-leap seconds let secs = self.secs as i64 - rhs.secs as i64 - 1; @@ -213,7 +219,9 @@ impl Sub for NaiveTime { } } -impl Sub for NaiveTime { +impl Sub for NaiveTime { + type Output = NaiveTime; + #[inline] fn sub(self, rhs: Duration) -> NaiveTime { self.add(-rhs) } } diff --git a/src/time.rs b/src/time.rs index 9b0294c..1f685d7 100644 --- a/src/time.rs +++ b/src/time.rs @@ -112,22 +112,30 @@ impl hash::Hash for Time { fn hash(&self, state: &mut hash::sip::SipState) { self.time.hash(state) } } -impl Add> for Time { +impl Add for Time { + type Output = Time; + fn add(self, rhs: Duration) -> Time { Time { time: self.time + rhs, offset: self.offset } } } -impl Add,Time> for Duration { +impl Add> for Duration { + type Output = Time; + #[inline] fn add(self, rhs: Time) -> Time { rhs.add(self) } } -impl Sub,Duration> for Time { +impl Sub> for Time { + type Output = Duration; + fn sub(self, rhs: Time) -> Duration { self.time - rhs.time } } -impl Sub> for Time { +impl Sub for Time { + type Output = Time; + #[inline] fn sub(self, rhs: Duration) -> Time { self.add(-rhs) } }