0.1.9: language changes.

- `Add` and `Sub` switches to associated types.
This commit is contained in:
Kang Seonghoon 2015-01-05 18:31:15 +09:00
parent 94df51861f
commit e2ddee2f76
9 changed files with 76 additions and 28 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "chrono"
version = "0.1.8"
version = "0.1.9"
authors = ["Kang Seonghoon <public+rust@mearie.org>"]
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"

View File

@ -1,4 +1,4 @@
[Chrono][doc] 0.1.8
[Chrono][doc] 0.1.9
===================
[![Chrono on Travis CI][travis-image]][travis]

View File

@ -263,22 +263,30 @@ impl<Off:Offset> hash::Hash for Date<Off> {
fn hash(&self, state: &mut hash::sip::SipState) { self.date.hash(state) }
}
impl<Off:Offset> Add<Duration,Date<Off>> for Date<Off> {
impl<Off:Offset> Add<Duration> for Date<Off> {
type Output = Date<Off>;
fn add(self, rhs: Duration) -> Date<Off> {
Date { date: self.date + rhs, offset: self.offset }
}
}
impl<Off:Offset> Add<Date<Off>,Date<Off>> for Duration {
impl<Off:Offset> Add<Date<Off>> for Duration {
type Output = Date<Off>;
#[inline]
fn add(self, rhs: Date<Off>) -> Date<Off> { rhs.add(self) }
}
impl<Off:Offset, Off2:Offset> Sub<Date<Off2>,Duration> for Date<Off> {
impl<Off:Offset, Off2:Offset> Sub<Date<Off2>> for Date<Off> {
type Output = Duration;
fn sub(self, rhs: Date<Off2>) -> Duration { self.date - rhs.date }
}
impl<Off:Offset> Sub<Duration,Date<Off>> for Date<Off> {
impl<Off:Offset> Sub<Duration> for Date<Off> {
type Output = Date<Off>;
#[inline]
fn sub(self, rhs: Duration) -> Date<Off> { self.add(-rhs) }
}

View File

@ -184,22 +184,30 @@ impl<Off:Offset> hash::Hash for DateTime<Off> {
fn hash(&self, state: &mut hash::sip::SipState) { self.datetime.hash(state) }
}
impl<Off:Offset> Add<Duration,DateTime<Off>> for DateTime<Off> {
impl<Off:Offset> Add<Duration> for DateTime<Off> {
type Output = DateTime<Off>;
fn add(self, rhs: Duration) -> DateTime<Off> {
DateTime { datetime: self.datetime + rhs, offset: self.offset }
}
}
impl<Off:Offset> Add<DateTime<Off>,DateTime<Off>> for Duration {
impl<Off:Offset> Add<DateTime<Off>> for Duration {
type Output = DateTime<Off>;
#[inline]
fn add(self, rhs: DateTime<Off>) -> DateTime<Off> { rhs.add(self) }
}
impl<Off:Offset, Off2:Offset> Sub<DateTime<Off2>,Duration> for DateTime<Off> {
impl<Off:Offset, Off2:Offset> Sub<DateTime<Off2>> for DateTime<Off> {
type Output = Duration;
fn sub(self, rhs: DateTime<Off2>) -> Duration { self.datetime - rhs.datetime }
}
impl<Off:Offset> Sub<Duration,DateTime<Off>> for DateTime<Off> {
impl<Off:Offset> Sub<Duration> for DateTime<Off> {
type Output = DateTime<Off>;
#[inline]
fn sub(self, rhs: Duration) -> DateTime<Off> { self.add(-rhs) }
}

View File

@ -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.

View File

@ -378,7 +378,9 @@ impl Datelike for NaiveDate {
}
}
impl Add<Duration,NaiveDate> for NaiveDate {
impl Add<Duration> for NaiveDate {
type Output = NaiveDate;
fn add(self, rhs: Duration) -> NaiveDate {
// TODO overflow currently fails
@ -396,12 +398,16 @@ impl Add<Duration,NaiveDate> for NaiveDate {
}
}
impl Add<NaiveDate,NaiveDate> for Duration {
impl Add<NaiveDate> for Duration {
type Output = NaiveDate;
#[inline]
fn add(self, rhs: NaiveDate) -> NaiveDate { rhs.add(self) }
}
impl Sub<NaiveDate,Duration> for NaiveDate {
impl Sub<NaiveDate> 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<NaiveDate,Duration> for NaiveDate {
}
}
impl Sub<Duration,NaiveDate> for NaiveDate {
impl Sub<Duration> for NaiveDate {
type Output = NaiveDate;
#[inline]
fn sub(self, rhs: Duration) -> NaiveDate { self.add(-rhs) }
}

View File

@ -163,7 +163,9 @@ impl Timelike for NaiveDateTime {
}
}
impl Add<Duration,NaiveDateTime> for NaiveDateTime {
impl Add<Duration> 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<Duration,NaiveDateTime> for NaiveDateTime {
}
}
impl Add<NaiveDateTime,NaiveDateTime> for Duration {
impl Add<NaiveDateTime> for Duration {
type Output = NaiveDateTime;
#[inline]
fn add(self, rhs: NaiveDateTime) -> NaiveDateTime { rhs.add(self) }
}
impl Sub<NaiveDateTime,Duration> for NaiveDateTime {
impl Sub<NaiveDateTime> for NaiveDateTime {
type Output = Duration;
fn sub(self, rhs: NaiveDateTime) -> Duration {
(self.date - rhs.date) + (self.time - rhs.time)
}
}
impl Sub<Duration,NaiveDateTime> for NaiveDateTime {
impl Sub<Duration> for NaiveDateTime {
type Output = NaiveDateTime;
#[inline]
fn sub(self, rhs: Duration) -> NaiveDateTime { self.add(-rhs) }
}

View File

@ -172,7 +172,9 @@ impl Timelike for NaiveTime {
}
}
impl Add<Duration,NaiveTime> for NaiveTime {
impl Add<Duration> 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<Duration,NaiveTime> for NaiveTime {
}
}
impl Add<NaiveTime,NaiveTime> for Duration {
impl Add<NaiveTime> for Duration {
type Output = NaiveTime;
#[inline]
fn add(self, rhs: NaiveTime) -> NaiveTime { rhs.add(self) }
}
impl Sub<NaiveTime,Duration> for NaiveTime {
impl Sub<NaiveTime> 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<NaiveTime,Duration> for NaiveTime {
}
}
impl Sub<Duration,NaiveTime> for NaiveTime {
impl Sub<Duration> for NaiveTime {
type Output = NaiveTime;
#[inline]
fn sub(self, rhs: Duration) -> NaiveTime { self.add(-rhs) }
}

View File

@ -112,22 +112,30 @@ impl<Off:Offset> hash::Hash for Time<Off> {
fn hash(&self, state: &mut hash::sip::SipState) { self.time.hash(state) }
}
impl<Off:Offset> Add<Duration,Time<Off>> for Time<Off> {
impl<Off:Offset> Add<Duration> for Time<Off> {
type Output = Time<Off>;
fn add(self, rhs: Duration) -> Time<Off> {
Time { time: self.time + rhs, offset: self.offset }
}
}
impl<Off:Offset> Add<Time<Off>,Time<Off>> for Duration {
impl<Off:Offset> Add<Time<Off>> for Duration {
type Output = Time<Off>;
#[inline]
fn add(self, rhs: Time<Off>) -> Time<Off> { rhs.add(self) }
}
impl<Off:Offset, Off2:Offset> Sub<Time<Off2>,Duration> for Time<Off> {
impl<Off:Offset, Off2:Offset> Sub<Time<Off2>> for Time<Off> {
type Output = Duration;
fn sub(self, rhs: Time<Off2>) -> Duration { self.time - rhs.time }
}
impl<Off:Offset> Sub<Duration,Time<Off>> for Time<Off> {
impl<Off:Offset> Sub<Duration> for Time<Off> {
type Output = Time<Off>;
#[inline]
fn sub(self, rhs: Duration) -> Time<Off> { self.add(-rhs) }
}