0.2.5: language changes, mostly overflow changes.

This commit is contained in:
Kang Seonghoon 2015-03-06 00:23:51 +09:00
parent 37be780b31
commit 04b179502c
6 changed files with 18 additions and 16 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "chrono"
version = "0.2.4"
version = "0.2.5"
authors = ["Kang Seonghoon <public+rust@mearie.org>"]
description = "Date and time library for Rust"

View File

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

View File

@ -258,10 +258,10 @@ pub fn format<'a, I>(w: &mut fmt::Formatter, date: Option<&NaiveDate>, time: Opt
Item::Numeric(spec, pad) => {
use self::Numeric::*;
let week_from_sun =
|d: &NaiveDate| (d.ordinal() - d.weekday().num_days_from_sunday() + 7) / 7;
let week_from_mon =
|d: &NaiveDate| (d.ordinal() - d.weekday().num_days_from_monday() + 7) / 7;
let week_from_sun = |d: &NaiveDate|
(d.ordinal() as i32 - d.weekday().num_days_from_sunday() as i32 + 7) / 7;
let week_from_mon = |d: &NaiveDate|
(d.ordinal() as i32 - d.weekday().num_days_from_monday() as i32 + 7) / 7;
let (width, v) = match spec {
Year => (4, date.map(|d| d.year() as i64)),

View File

@ -310,11 +310,11 @@ impl Parsed {
let verify_ordinal = |date: NaiveDate| {
let ordinal = date.ordinal();
let weekday = date.weekday();
let week_from_sun = (ordinal - weekday.num_days_from_sunday() + 7) / 7;
let week_from_mon = (ordinal - weekday.num_days_from_monday() + 7) / 7;
let week_from_sun = (ordinal as i32 - weekday.num_days_from_sunday() as i32 + 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.week_from_sun.unwrap_or(week_from_sun) == week_from_sun &&
self.week_from_mon.unwrap_or(week_from_mon) == week_from_mon)
self.week_from_sun.map_or(week_from_sun, |v| v as i32) == week_from_sun &&
self.week_from_mon.map_or(week_from_mon, |v| v as i32) == week_from_mon)
};
// test several possibilities.
@ -349,7 +349,8 @@ impl Parsed {
// `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?
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))
.ok_or(OUT_OF_RANGE));
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.
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))
.ok_or(OUT_OF_RANGE));
if date.year() != year { return Err(OUT_OF_RANGE); } // early exit for correct error

View File

@ -4,7 +4,7 @@
/*!
# Chrono 0.2.4
# Chrono 0.2.5
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

@ -1242,7 +1242,7 @@ mod internals {
pub fn from_mdf(Mdf(mdf): Mdf) -> Of {
let mdl = mdf >> 3;
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)
}
}
@ -1251,7 +1251,7 @@ mod internals {
pub fn valid(&self) -> bool {
let Of(of) = *self;
let ol = of >> 3;
ol - MIN_OL <= MAX_OL - MIN_OL
MIN_OL <= ol && ol <= MAX_OL
}
#[inline]
@ -1289,7 +1289,7 @@ mod internals {
pub fn isoweekdate_raw(&self) -> (u32, Weekday) {
// week ordinal = ordinal + delta
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())
}