Skip to content

Commit

Permalink
fix: Move step check to appropriate function
Browse files Browse the repository at this point in the history
  • Loading branch information
bombsimon committed Oct 28, 2024
1 parent 89e7a8b commit 117679c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
15 changes: 0 additions & 15 deletions src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,6 @@ where
}
let mut ordinals = OrdinalSet::new();
for specifier in field.specifiers {
if let RootSpecifier::Period(_, interval) = specifier {
// Having an interval of 0 is not valid and at the same time, having intervals
// below 1970 is valid for years so instead of using `validate_ordinal` for the
// interval we allow 1-<inclusive max>.
if interval < 1 || interval > T::inclusive_max() {
return Err(ErrorKind::Expression(format!(
"{} must be between 1 and {}. ('{}' specified.)",
Self::name(),
Self::inclusive_max(),
interval,
))
.into());
}
}

let specifier_ordinals: OrdinalSet = T::ordinals_from_root_specifier(&specifier)?;
for ordinal in specifier_ordinals {
ordinals.insert(T::validate_ordinal(ordinal)?);
Expand Down
10 changes: 10 additions & 0 deletions src/time_unit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ where
"range step cannot be zero".to_string(),
))?,
RootSpecifier::Period(start, step) => {
if *step < 1 || *step > Self::inclusive_max() {
return Err(ErrorKind::Expression(format!(
"{} must be between 1 and {}. ('{}' specified.)",
Self::name(),
Self::inclusive_max(),
step,
))
.into());
}

let base_set = match start {
// A point prior to a period implies a range whose start is the specified
// point and terminating inclusively with the inclusive max
Expand Down

0 comments on commit 117679c

Please sign in to comment.