0.1.5: language changes.
- Add and Sub requires a value instead of a reference. - Tuple indexing is now ungated. Fixes #15.
This commit is contained in:
parent
0d8f836665
commit
e982cd1851
|
@ -1,12 +1,13 @@
|
||||||
[package]
|
[package]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
authors = ["Kang Seonghoon <public+rust@mearie.org>"]
|
authors = ["Kang Seonghoon <public+rust@mearie.org>"]
|
||||||
|
|
||||||
description = "Date and time library for Rust"
|
description = "Date and time library for Rust"
|
||||||
homepage = "https://github.com/lifthrasiir/rust-chrono"
|
homepage = "https://github.com/lifthrasiir/rust-chrono"
|
||||||
documentation = "https://lifthrasiir.github.io/rust-chrono/chrono/"
|
documentation = "https://lifthrasiir.github.io/rust-chrono/chrono/"
|
||||||
repository = "https://github.com/lifthrasiir/rust-chrono"
|
repository = "https://github.com/lifthrasiir/rust-chrono"
|
||||||
|
keywords = ["date", "time", "calendar"]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
|
|
||||||
|
|
12
src/date.rs
12
src/date.rs
|
@ -262,25 +262,23 @@ impl<Off:Offset> hash::Hash for Date<Off> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Off:Offset> Add<Duration,Date<Off>> for Date<Off> {
|
impl<Off:Offset> Add<Duration,Date<Off>> for Date<Off> {
|
||||||
fn add(&self, rhs: &Duration) -> Date<Off> {
|
fn add(self, rhs: Duration) -> Date<Off> {
|
||||||
Date { date: self.date + *rhs, offset: self.offset.clone() }
|
Date { date: self.date + rhs, offset: self.offset }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Off:Offset> Add<Date<Off>,Date<Off>> for Duration {
|
impl<Off:Offset> Add<Date<Off>,Date<Off>> for Duration {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add(&self, rhs: &Date<Off>) -> Date<Off> { rhs.add(self) }
|
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>,Duration> for Date<Off> {
|
||||||
fn sub(&self, rhs: &Date<Off2>) -> Duration {
|
fn sub(self, rhs: Date<Off2>) -> Duration { self.date - rhs.date }
|
||||||
self.date - rhs.date
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Off:Offset> Sub<Duration,Date<Off>> for Date<Off> {
|
impl<Off:Offset> Sub<Duration,Date<Off>> for Date<Off> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub(&self, rhs: &Duration) -> Date<Off> { self.add(&-*rhs) }
|
fn sub(self, rhs: Duration) -> Date<Off> { self.add(-rhs) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Off:Offset> fmt::Show for Date<Off> {
|
impl<Off:Offset> fmt::Show for Date<Off> {
|
||||||
|
|
|
@ -183,25 +183,23 @@ impl<Off:Offset> hash::Hash for DateTime<Off> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Off:Offset> Add<Duration,DateTime<Off>> for DateTime<Off> {
|
impl<Off:Offset> Add<Duration,DateTime<Off>> for DateTime<Off> {
|
||||||
fn add(&self, rhs: &Duration) -> DateTime<Off> {
|
fn add(self, rhs: Duration) -> DateTime<Off> {
|
||||||
DateTime { datetime: self.datetime + *rhs, offset: self.offset.clone() }
|
DateTime { datetime: self.datetime + rhs, offset: self.offset }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Off:Offset> Add<DateTime<Off>,DateTime<Off>> for Duration {
|
impl<Off:Offset> Add<DateTime<Off>,DateTime<Off>> for Duration {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add(&self, rhs: &DateTime<Off>) -> DateTime<Off> { rhs.add(self) }
|
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>,Duration> for DateTime<Off> {
|
||||||
fn sub(&self, rhs: &DateTime<Off2>) -> Duration {
|
fn sub(self, rhs: DateTime<Off2>) -> Duration { self.datetime - rhs.datetime }
|
||||||
self.datetime - rhs.datetime
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Off:Offset> Sub<Duration,DateTime<Off>> for DateTime<Off> {
|
impl<Off:Offset> Sub<Duration,DateTime<Off>> for DateTime<Off> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub(&self, rhs: &Duration) -> DateTime<Off> { self.add(&-*rhs) }
|
fn sub(self, rhs: Duration) -> DateTime<Off> { self.add(-rhs) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Off:Offset> fmt::Show for DateTime<Off> {
|
impl<Off:Offset> fmt::Show for DateTime<Off> {
|
||||||
|
|
|
@ -52,8 +52,8 @@ fn format(w: &mut Writer, date: Option<&NaiveDate>, time: Option<&NaiveTime>,
|
||||||
(Some('Y'), Some(d), _, _) => try!(write!(w, "{}", d.year())),
|
(Some('Y'), Some(d), _, _) => try!(write!(w, "{}", d.year())),
|
||||||
(Some('C'), Some(d), _, _) => try!(write!(w, "{:02}", d.year() / 100)),
|
(Some('C'), Some(d), _, _) => try!(write!(w, "{:02}", d.year() / 100)),
|
||||||
(Some('y'), Some(d), _, _) => try!(write!(w, "{:02}", d.year() % 100)),
|
(Some('y'), Some(d), _, _) => try!(write!(w, "{:02}", d.year() % 100)),
|
||||||
(Some('G'), Some(d), _, _) => try!(write!(w, "{:04}", d.isoweekdate().val0())),
|
(Some('G'), Some(d), _, _) => try!(write!(w, "{:04}", d.isoweekdate().0)),
|
||||||
(Some('g'), Some(d), _, _) => try!(write!(w, "{:02}", d.isoweekdate().val0() % 100)),
|
(Some('g'), Some(d), _, _) => try!(write!(w, "{:02}", d.isoweekdate().0 % 100)),
|
||||||
|
|
||||||
// month
|
// month
|
||||||
(Some('m'), Some(d), _, _) => try!(write!(w, "{:02}", d.month())),
|
(Some('m'), Some(d), _, _) => try!(write!(w, "{:02}", d.month())),
|
||||||
|
@ -73,7 +73,7 @@ fn format(w: &mut Writer, date: Option<&NaiveDate>, time: Option<&NaiveTime>,
|
||||||
(Some('W'), Some(d), _, _) =>
|
(Some('W'), Some(d), _, _) =>
|
||||||
try!(write!(w, "{:02}", (d.ordinal() - d.weekday().num_days_from_monday()
|
try!(write!(w, "{:02}", (d.ordinal() - d.weekday().num_days_from_monday()
|
||||||
+ 7) / 7)),
|
+ 7) / 7)),
|
||||||
(Some('V'), Some(d), _, _) => try!(write!(w, "{:02}", d.isoweekdate().val1())),
|
(Some('V'), Some(d), _, _) => try!(write!(w, "{:02}", d.isoweekdate().1)),
|
||||||
|
|
||||||
// day of week
|
// day of week
|
||||||
(Some('a'), Some(d), _, _) =>
|
(Some('a'), Some(d), _, _) =>
|
||||||
|
@ -98,12 +98,12 @@ fn format(w: &mut Writer, date: Option<&NaiveDate>, time: Option<&NaiveTime>,
|
||||||
// hour
|
// hour
|
||||||
(Some('H'), _, Some(t), _) => try!(write!(w, "{:02}", t.hour())),
|
(Some('H'), _, Some(t), _) => try!(write!(w, "{:02}", t.hour())),
|
||||||
(Some('k'), _, Some(t), _) => try!(write!(w, "{:2}", t.hour())),
|
(Some('k'), _, Some(t), _) => try!(write!(w, "{:2}", t.hour())),
|
||||||
(Some('I'), _, Some(t), _) => try!(write!(w, "{:02}", t.hour12().val1())),
|
(Some('I'), _, Some(t), _) => try!(write!(w, "{:02}", t.hour12().1)),
|
||||||
(Some('l'), _, Some(t), _) => try!(write!(w, "{:2}", t.hour12().val1())),
|
(Some('l'), _, Some(t), _) => try!(write!(w, "{:2}", t.hour12().1)),
|
||||||
(Some('P'), _, Some(t), _) =>
|
(Some('P'), _, Some(t), _) =>
|
||||||
try!(write!(w, "{}", if t.hour12().val0() {"pm"} else {"am"})),
|
try!(write!(w, "{}", if t.hour12().0 {"pm"} else {"am"})),
|
||||||
(Some('p'), _, Some(t), _) =>
|
(Some('p'), _, Some(t), _) =>
|
||||||
try!(write!(w, "{}", if t.hour12().val0() {"PM"} else {"AM"})),
|
try!(write!(w, "{}", if t.hour12().0 {"PM"} else {"AM"})),
|
||||||
|
|
||||||
// minute
|
// minute
|
||||||
(Some('M'), _, Some(t), _) => try!(write!(w, "{:02}", t.minute())),
|
(Some('M'), _, Some(t), _) => try!(write!(w, "{:02}", t.minute())),
|
||||||
|
|
|
@ -378,7 +378,7 @@ impl Datelike for NaiveDate {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Add<Duration,NaiveDate> for NaiveDate {
|
impl Add<Duration,NaiveDate> for NaiveDate {
|
||||||
fn add(&self, rhs: &Duration) -> NaiveDate {
|
fn add(self, rhs: Duration) -> NaiveDate {
|
||||||
// TODO overflow currently fails
|
// TODO overflow currently fails
|
||||||
|
|
||||||
let year = self.year();
|
let year = self.year();
|
||||||
|
@ -397,11 +397,11 @@ impl Add<Duration,NaiveDate> for NaiveDate {
|
||||||
|
|
||||||
impl Add<NaiveDate,NaiveDate> for Duration {
|
impl Add<NaiveDate,NaiveDate> for Duration {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add(&self, rhs: &NaiveDate) -> NaiveDate { rhs.add(self) }
|
fn add(self, rhs: NaiveDate) -> NaiveDate { rhs.add(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sub<NaiveDate,Duration> for NaiveDate {
|
impl Sub<NaiveDate,Duration> for NaiveDate {
|
||||||
fn sub(&self, rhs: &NaiveDate) -> Duration {
|
fn sub(self, rhs: NaiveDate) -> Duration {
|
||||||
let year1 = self.year();
|
let year1 = self.year();
|
||||||
let year2 = rhs.year();
|
let year2 = rhs.year();
|
||||||
let (year1_div_400, year1_mod_400) = div_mod_floor(year1, 400);
|
let (year1_div_400, year1_mod_400) = div_mod_floor(year1, 400);
|
||||||
|
@ -414,7 +414,7 @@ impl Sub<NaiveDate,Duration> for NaiveDate {
|
||||||
|
|
||||||
impl Sub<Duration,NaiveDate> for NaiveDate {
|
impl Sub<Duration,NaiveDate> for NaiveDate {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub(&self, rhs: &Duration) -> NaiveDate { self.add(&-*rhs) }
|
fn sub(self, rhs: Duration) -> NaiveDate { self.add(-rhs) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for NaiveDate {
|
impl fmt::Show for NaiveDate {
|
||||||
|
|
|
@ -163,11 +163,11 @@ impl Timelike for NaiveDateTime {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Add<Duration,NaiveDateTime> for NaiveDateTime {
|
impl Add<Duration,NaiveDateTime> for NaiveDateTime {
|
||||||
fn add(&self, rhs: &Duration) -> NaiveDateTime {
|
fn add(self, rhs: Duration) -> NaiveDateTime {
|
||||||
// Duration does not directly give its parts, so we need some additional calculations.
|
// Duration does not directly give its parts, so we need some additional calculations.
|
||||||
let days = rhs.num_days();
|
let days = rhs.num_days();
|
||||||
let nanos = (*rhs - Duration::days(days)).num_nanoseconds().unwrap();
|
let nanos = (rhs - Duration::days(days)).num_nanoseconds().unwrap();
|
||||||
debug_assert!(Duration::days(days) + Duration::nanoseconds(nanos) == *rhs);
|
debug_assert!(Duration::days(days) + Duration::nanoseconds(nanos) == rhs);
|
||||||
debug_assert!(-86400_000_000_000 < nanos && nanos < 86400_000_000_000);
|
debug_assert!(-86400_000_000_000 < nanos && nanos < 86400_000_000_000);
|
||||||
|
|
||||||
let mut date = self.date + Duration::days(days);
|
let mut date = self.date + Duration::days(days);
|
||||||
|
@ -185,18 +185,18 @@ impl Add<Duration,NaiveDateTime> for NaiveDateTime {
|
||||||
|
|
||||||
impl Add<NaiveDateTime,NaiveDateTime> for Duration {
|
impl Add<NaiveDateTime,NaiveDateTime> for Duration {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add(&self, rhs: &NaiveDateTime) -> NaiveDateTime { rhs.add(self) }
|
fn add(self, rhs: NaiveDateTime) -> NaiveDateTime { rhs.add(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sub<NaiveDateTime,Duration> for NaiveDateTime {
|
impl Sub<NaiveDateTime,Duration> for NaiveDateTime {
|
||||||
fn sub(&self, rhs: &NaiveDateTime) -> Duration {
|
fn sub(self, rhs: NaiveDateTime) -> Duration {
|
||||||
(self.date - rhs.date) + (self.time - rhs.time)
|
(self.date - rhs.date) + (self.time - rhs.time)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sub<Duration,NaiveDateTime> for NaiveDateTime {
|
impl Sub<Duration,NaiveDateTime> for NaiveDateTime {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub(&self, rhs: &Duration) -> NaiveDateTime { self.add(&-*rhs) }
|
fn sub(self, rhs: Duration) -> NaiveDateTime { self.add(-rhs) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for NaiveDateTime {
|
impl fmt::Show for NaiveDateTime {
|
||||||
|
|
|
@ -133,9 +133,9 @@ impl NaiveTime {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Timelike for NaiveTime {
|
impl Timelike for NaiveTime {
|
||||||
#[inline] fn hour(&self) -> u32 { self.hms().val0() }
|
#[inline] fn hour(&self) -> u32 { self.hms().0 }
|
||||||
#[inline] fn minute(&self) -> u32 { self.hms().val1() }
|
#[inline] fn minute(&self) -> u32 { self.hms().1 }
|
||||||
#[inline] fn second(&self) -> u32 { self.hms().val2() }
|
#[inline] fn second(&self) -> u32 { self.hms().2 }
|
||||||
#[inline] fn nanosecond(&self) -> u32 { self.frac }
|
#[inline] fn nanosecond(&self) -> u32 { self.frac }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -172,10 +172,10 @@ impl Timelike for NaiveTime {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Add<Duration,NaiveTime> for NaiveTime {
|
impl Add<Duration,NaiveTime> for NaiveTime {
|
||||||
fn add(&self, rhs: &Duration) -> NaiveTime {
|
fn add(self, rhs: Duration) -> NaiveTime {
|
||||||
// there is no direct interface in `Duration` to get only the nanosecond part,
|
// there is no direct interface in `Duration` to get only the nanosecond part,
|
||||||
// so we need to do the additional calculation here.
|
// so we need to do the additional calculation here.
|
||||||
let rhs2 = *rhs - Duration::seconds(rhs.num_seconds());
|
let rhs2 = rhs - Duration::seconds(rhs.num_seconds());
|
||||||
let mut secs = self.secs + (rhs.num_seconds() % 86400 + 86400) as u32;
|
let mut secs = self.secs + (rhs.num_seconds() % 86400 + 86400) as u32;
|
||||||
let mut nanos = self.frac + rhs2.num_nanoseconds().unwrap() as u32;
|
let mut nanos = self.frac + rhs2.num_nanoseconds().unwrap() as u32;
|
||||||
|
|
||||||
|
@ -192,11 +192,11 @@ impl Add<Duration,NaiveTime> for NaiveTime {
|
||||||
|
|
||||||
impl Add<NaiveTime,NaiveTime> for Duration {
|
impl Add<NaiveTime,NaiveTime> for Duration {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add(&self, rhs: &NaiveTime) -> NaiveTime { rhs.add(self) }
|
fn add(self, rhs: NaiveTime) -> NaiveTime { rhs.add(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sub<NaiveTime,Duration> for NaiveTime {
|
impl Sub<NaiveTime,Duration> for NaiveTime {
|
||||||
fn sub(&self, rhs: &NaiveTime) -> Duration {
|
fn sub(self, rhs: NaiveTime) -> Duration {
|
||||||
// the number of whole non-leap seconds
|
// the number of whole non-leap seconds
|
||||||
let secs = self.secs as i64 - rhs.secs as i64 - 1;
|
let secs = self.secs as i64 - rhs.secs as i64 - 1;
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ impl Sub<NaiveTime,Duration> for NaiveTime {
|
||||||
|
|
||||||
impl Sub<Duration,NaiveTime> for NaiveTime {
|
impl Sub<Duration,NaiveTime> for NaiveTime {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub(&self, rhs: &Duration) -> NaiveTime { self.add(&-*rhs) }
|
fn sub(self, rhs: Duration) -> NaiveTime { self.add(-rhs) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Show for NaiveTime {
|
impl fmt::Show for NaiveTime {
|
||||||
|
|
12
src/time.rs
12
src/time.rs
|
@ -111,25 +111,23 @@ impl<Off:Offset> hash::Hash for Time<Off> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Off:Offset> Add<Duration,Time<Off>> for Time<Off> {
|
impl<Off:Offset> Add<Duration,Time<Off>> for Time<Off> {
|
||||||
fn add(&self, rhs: &Duration) -> Time<Off> {
|
fn add(self, rhs: Duration) -> Time<Off> {
|
||||||
Time { time: self.time + *rhs, offset: self.offset.clone() }
|
Time { time: self.time + rhs, offset: self.offset }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Off:Offset> Add<Time<Off>,Time<Off>> for Duration {
|
impl<Off:Offset> Add<Time<Off>,Time<Off>> for Duration {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add(&self, rhs: &Time<Off>) -> Time<Off> { rhs.add(self) }
|
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>,Duration> for Time<Off> {
|
||||||
fn sub(&self, rhs: &Time<Off2>) -> Duration {
|
fn sub(self, rhs: Time<Off2>) -> Duration { self.time - rhs.time }
|
||||||
self.time - rhs.time
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Off:Offset> Sub<Duration,Time<Off>> for Time<Off> {
|
impl<Off:Offset> Sub<Duration,Time<Off>> for Time<Off> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub(&self, rhs: &Duration) -> Time<Off> { self.add(&-*rhs) }
|
fn sub(self, rhs: Duration) -> Time<Off> { self.add(-rhs) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Off:Offset> fmt::Show for Time<Off> {
|
impl<Off:Offset> fmt::Show for Time<Off> {
|
||||||
|
|
Loading…
Reference in New Issue