Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed step_by change rust issue #27741 #27

Merged
merged 1 commit into from
Jul 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg_attr(feature="clippy", feature(plugin))]
#![cfg_attr(feature="clippy", plugin(clippy))]
#![feature(conservative_impl_trait)]
#![feature(step_by)]
#![feature(iterator_step_by)]

extern crate chrono;
extern crate nom;
Expand Down
37 changes: 21 additions & 16 deletions src/time_unit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@ pub trait TimeUnitField
fn ordinal_from_name(name: &str) -> Result<Ordinal> {
bail!(ErrorKind::Expression(format!("The '{}' field does not support using names. '{}' \
specified.",
Self::name(),
name)))
Self::name(),
name)))
}
fn validate_ordinal(ordinal: Ordinal) -> Result<Ordinal> {
//println!("validate_ordinal for {} => {}", Self::name(), ordinal);
match ordinal {
i if i < Self::inclusive_min() => {
bail!(ErrorKind::Expression(format!("{} must be greater than or equal to {}. ('{}' \
specified.)",
Self::name(),
Self::inclusive_min(),
i)))
Self::name(),
Self::inclusive_min(),
i)))
}
i if i > Self::inclusive_max() => {
bail!(ErrorKind::Expression(format!("{} must be less than {}. ('{}' specified.)",
Self::name(),
Self::inclusive_max(),
i)))
Self::name(),
Self::inclusive_max(),
i)))
}
i => Ok(i),
}
Expand All @@ -70,20 +70,25 @@ pub trait TimeUnitField
All => Ok(Self::supported_ordinals()),
Point(ordinal) => Ok((&[ordinal]).iter().cloned().collect()),
NamedPoint(ref name) => {
Ok((&[Self::ordinal_from_name(name)?]).iter().cloned().collect())
Ok((&[Self::ordinal_from_name(name)?])
.iter()
.cloned()
.collect())
}
Period(start, step) => {
let start = Self::validate_ordinal(start)?;
Ok((start..Self::inclusive_max() + 1).step_by(step).collect())
Ok((start..Self::inclusive_max() + 1)
.step_by(step as usize)
.collect())
}
Range(start, end) => {
match (Self::validate_ordinal(start), Self::validate_ordinal(end)) {
(Ok(start), Ok(end)) if start <= end => Ok((start..end + 1).collect()),
_ => {
bail!(ErrorKind::Expression(format!("Invalid range for {}: {}-{}",
Self::name(),
start,
end)))
Self::name(),
start,
end)))
}
}
}
Expand All @@ -94,9 +99,9 @@ pub trait TimeUnitField
(Ok(start), Ok(end)) if start <= end => Ok((start..end + 1).collect()),
_ => {
bail!(ErrorKind::Expression(format!("Invalid named range for {}: {}-{}",
Self::name(),
start_name,
end_name)))
Self::name(),
start_name,
end_name)))
}
}
}
Expand Down