Skip to content

Commit

Permalink
0.1.9: language changes.
Browse files Browse the repository at this point in the history
- `Add` and `Sub` switches to associated types.
  • Loading branch information
lifthrasiir committed Jan 5, 2015
1 parent 94df518 commit e2ddee2
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chrono"
version = "0.1.8"
version = "0.1.9"
authors = ["Kang Seonghoon <[email protected]>"]

description = "Date and time library for Rust"
Expand All @@ -15,5 +15,5 @@ license = "MIT/Apache-2.0"
name = "chrono"

[dependencies]
time = "0.1.7"
time = "0.1.9"

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[Chrono][doc] 0.1.8
[Chrono][doc] 0.1.9
===================

[![Chrono on Travis CI][travis-image]][travis]
Expand Down
16 changes: 12 additions & 4 deletions src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
Expand Down
16 changes: 12 additions & 4 deletions src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 12 additions & 4 deletions src/naive/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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();
Expand All @@ -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) }
}
Expand Down
16 changes: 12 additions & 4 deletions src/naive/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) }
}
Expand Down
16 changes: 12 additions & 4 deletions src/naive/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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) }
}
Expand Down
16 changes: 12 additions & 4 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
Expand Down

0 comments on commit e2ddee2

Please sign in to comment.