Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
baoyachi committed May 10, 2024
1 parent b104c55 commit 58a0af4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ impl CondUnit {
(CondUnit::Star, ONE_SECOND_NANOSECOND)
}

fn contain(c: char) -> bool {
Self::expect_val().contains(&&*c.to_string())
}

fn change_duration(&self) -> u64 {
match self {
CondUnit::Plus => 0,
Expand Down
4 changes: 2 additions & 2 deletions src/unit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::error::PError;
use crate::{
DError, DResult, ExpectErr, ONE_DAY_NANOSECOND, ONE_HOUR_NANOSECOND,
CondUnit, DError, DResult, ExpectErr, ONE_DAY_NANOSECOND, ONE_HOUR_NANOSECOND,
ONE_MICROSECOND_NANOSECOND, ONE_MILLISECOND_NANOSECOND, ONE_MINUTE_NANOSECOND,
ONE_MONTH_NANOSECOND, ONE_SECOND_NANOSECOND, ONE_WEEK_NANOSECOND, ONE_YEAR_NANOSECOND,
};
Expand Down Expand Up @@ -112,7 +112,7 @@ pub(crate) fn opt_unit_abbr<'a>(input: &mut &'a str) -> PResult<TimeUnit, PError
return Ok(TimeUnit::default());
}

if peek((multispace, one_of(|c| c == '+' || c == '*')))
if peek((multispace, one_of(CondUnit::contain)))
.parse_next(input)
.is_ok()
{
Expand Down

0 comments on commit 58a0af4

Please sign in to comment.