0.2.5: language changes, mostly overflow changes.
This commit is contained in:
parent
37be780b31
commit
04b179502c
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
version = "0.2.4"
|
version = "0.2.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"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[Chrono][doc] 0.2.4
|
[Chrono][doc] 0.2.5
|
||||||
===================
|
===================
|
||||||
|
|
||||||
[![Chrono on Travis CI][travis-image]][travis]
|
[![Chrono on Travis CI][travis-image]][travis]
|
||||||
|
|
|
@ -258,10 +258,10 @@ pub fn format<'a, I>(w: &mut fmt::Formatter, date: Option<&NaiveDate>, time: Opt
|
||||||
Item::Numeric(spec, pad) => {
|
Item::Numeric(spec, pad) => {
|
||||||
use self::Numeric::*;
|
use self::Numeric::*;
|
||||||
|
|
||||||
let week_from_sun =
|
let week_from_sun = |d: &NaiveDate|
|
||||||
|d: &NaiveDate| (d.ordinal() - d.weekday().num_days_from_sunday() + 7) / 7;
|
(d.ordinal() as i32 - d.weekday().num_days_from_sunday() as i32 + 7) / 7;
|
||||||
let week_from_mon =
|
let week_from_mon = |d: &NaiveDate|
|
||||||
|d: &NaiveDate| (d.ordinal() - d.weekday().num_days_from_monday() + 7) / 7;
|
(d.ordinal() as i32 - d.weekday().num_days_from_monday() as i32 + 7) / 7;
|
||||||
|
|
||||||
let (width, v) = match spec {
|
let (width, v) = match spec {
|
||||||
Year => (4, date.map(|d| d.year() as i64)),
|
Year => (4, date.map(|d| d.year() as i64)),
|
||||||
|
|
|
@ -310,11 +310,11 @@ impl Parsed {
|
||||||
let verify_ordinal = |date: NaiveDate| {
|
let verify_ordinal = |date: NaiveDate| {
|
||||||
let ordinal = date.ordinal();
|
let ordinal = date.ordinal();
|
||||||
let weekday = date.weekday();
|
let weekday = date.weekday();
|
||||||
let week_from_sun = (ordinal - weekday.num_days_from_sunday() + 7) / 7;
|
let week_from_sun = (ordinal as i32 - weekday.num_days_from_sunday() as i32 + 7) / 7;
|
||||||
let week_from_mon = (ordinal - weekday.num_days_from_monday() + 7) / 7;
|
let week_from_mon = (ordinal as i32 - weekday.num_days_from_monday() as i32 + 7) / 7;
|
||||||
(self.ordinal.unwrap_or(ordinal) == ordinal &&
|
(self.ordinal.unwrap_or(ordinal) == ordinal &&
|
||||||
self.week_from_sun.unwrap_or(week_from_sun) == week_from_sun &&
|
self.week_from_sun.map_or(week_from_sun, |v| v as i32) == week_from_sun &&
|
||||||
self.week_from_mon.unwrap_or(week_from_mon) == week_from_mon)
|
self.week_from_mon.map_or(week_from_mon, |v| v as i32) == week_from_mon)
|
||||||
};
|
};
|
||||||
|
|
||||||
// test several possibilities.
|
// test several possibilities.
|
||||||
|
@ -349,7 +349,8 @@ impl Parsed {
|
||||||
|
|
||||||
// `firstweek+1`-th day of January is the beginning of the week 1.
|
// `firstweek+1`-th day of January is the beginning of the week 1.
|
||||||
if week_from_sun > 53 { return Err(OUT_OF_RANGE); } // can it overflow?
|
if week_from_sun > 53 { return Err(OUT_OF_RANGE); } // can it overflow?
|
||||||
let ndays = firstweek + (week_from_sun - 1) * 7 + weekday.num_days_from_sunday();
|
let ndays = firstweek + (week_from_sun as i32 - 1) * 7 +
|
||||||
|
weekday.num_days_from_sunday() as i32;
|
||||||
let date = try!(newyear.checked_add(Duration::days(ndays as i64))
|
let date = try!(newyear.checked_add(Duration::days(ndays as i64))
|
||||||
.ok_or(OUT_OF_RANGE));
|
.ok_or(OUT_OF_RANGE));
|
||||||
if date.year() != year { return Err(OUT_OF_RANGE); } // early exit for correct error
|
if date.year() != year { return Err(OUT_OF_RANGE); } // early exit for correct error
|
||||||
|
@ -373,7 +374,8 @@ impl Parsed {
|
||||||
|
|
||||||
// `firstweek+1`-th day of January is the beginning of the week 1.
|
// `firstweek+1`-th day of January is the beginning of the week 1.
|
||||||
if week_from_mon > 53 { return Err(OUT_OF_RANGE); } // can it overflow?
|
if week_from_mon > 53 { return Err(OUT_OF_RANGE); } // can it overflow?
|
||||||
let ndays = firstweek + (week_from_mon - 1) * 7 + weekday.num_days_from_monday();
|
let ndays = firstweek + (week_from_mon as i32 - 1) * 7 +
|
||||||
|
weekday.num_days_from_monday() as i32;
|
||||||
let date = try!(newyear.checked_add(Duration::days(ndays as i64))
|
let date = try!(newyear.checked_add(Duration::days(ndays as i64))
|
||||||
.ok_or(OUT_OF_RANGE));
|
.ok_or(OUT_OF_RANGE));
|
||||||
if date.year() != year { return Err(OUT_OF_RANGE); } // early exit for correct error
|
if date.year() != year { return Err(OUT_OF_RANGE); } // early exit for correct error
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
||||||
# Chrono 0.2.4
|
# Chrono 0.2.5
|
||||||
|
|
||||||
Date and time handling for Rust. (also known as `rust-chrono`)
|
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.
|
It aims to be a feature-complete superset of the [time](https://github.com/rust-lang/time) library.
|
||||||
|
|
|
@ -1242,7 +1242,7 @@ mod internals {
|
||||||
pub fn from_mdf(Mdf(mdf): Mdf) -> Of {
|
pub fn from_mdf(Mdf(mdf): Mdf) -> Of {
|
||||||
let mdl = mdf >> 3;
|
let mdl = mdf >> 3;
|
||||||
match MDL_TO_OL.get(mdl as usize) {
|
match MDL_TO_OL.get(mdl as usize) {
|
||||||
Some(&v) => Of(mdf - ((v as i32 as u32 & 0x3ff) << 3)),
|
Some(&v) => Of(mdf.wrapping_sub((v as i32 as u32 & 0x3ff) << 3)),
|
||||||
None => Of(0)
|
None => Of(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1251,7 +1251,7 @@ mod internals {
|
||||||
pub fn valid(&self) -> bool {
|
pub fn valid(&self) -> bool {
|
||||||
let Of(of) = *self;
|
let Of(of) = *self;
|
||||||
let ol = of >> 3;
|
let ol = of >> 3;
|
||||||
ol - MIN_OL <= MAX_OL - MIN_OL
|
MIN_OL <= ol && ol <= MAX_OL
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1289,7 +1289,7 @@ mod internals {
|
||||||
pub fn isoweekdate_raw(&self) -> (u32, Weekday) {
|
pub fn isoweekdate_raw(&self) -> (u32, Weekday) {
|
||||||
// week ordinal = ordinal + delta
|
// week ordinal = ordinal + delta
|
||||||
let Of(of) = *self;
|
let Of(of) = *self;
|
||||||
let weekord = (of >> 4) + self.flags().isoweek_delta();
|
let weekord = (of >> 4).wrapping_add(self.flags().isoweek_delta());
|
||||||
(weekord / 7, num::from_u32(weekord % 7).unwrap())
|
(weekord / 7, num::from_u32(weekord % 7).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue