Skip to content

Commit

Permalink
increment parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
NYBACHOK committed Nov 1, 2024
1 parent 0f18e3f commit 484c240
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions process/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,18 @@ mod timespec {
}
}

impl From<std::num::ParseIntError> for TimespecParsingError {
fn from(_value: std::num::ParseIntError) -> Self {
Self
}
}

impl From<std::char::TryFromCharError> for TimespecParsingError {
fn from(_value: std::char::TryFromCharError) -> Self {
Self
}
}

pub enum IncPeriod {
Minute,
Minutes,
Expand Down Expand Up @@ -392,15 +404,31 @@ mod timespec {
type Err = TimespecParsingError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.contains("+") {
true => todo!(),
let result = match s.starts_with("+") {
true => {
let number: u16 = s
.chars()
.skip(1)
.take_while(|this| this.is_numeric())
.collect::<String>()
.parse()?;

let period = s
.chars()
.skip(1)
.skip_while(|this| this.is_numeric())
.collect::<String>()
.parse::<IncPeriod>()?;

Self::Plus { number, period }
}
false => match s.starts_with("next") {
true => Self::Next(IncPeriod::from_str(&s.replace("next", ""))?),
false => Err(TimespecParsingError)?,
},
};

todo!()
Ok(result)
}
}
}
Expand Down Expand Up @@ -669,18 +697,6 @@ mod tokens {
}
}

/// The inc_number is the number of times the succeeding increment
/// period is to be added to the specified date and time.
pub struct IncNumber(u16);

impl FromStr for IncNumber {
type Err = TokenParsingError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
u16::from_str(s).map(Self).map_err(TokenParsingError::from)
}
}

/// The name of an optional timezone suffix to the time field, in an
/// implementation-defined format.
pub struct TimezoneName(String);
Expand Down

0 comments on commit 484c240

Please sign in to comment.