Progress on Time parser
This commit is contained in:
parent
669fa0889b
commit
230b8ac48a
1 changed files with 56 additions and 4 deletions
|
@ -193,15 +193,67 @@ impl<'a> Parser<'a> {
|
|||
Format::Basic => self.text.get(13..15),
|
||||
Format::Extended => self.text.get(17..19),
|
||||
};
|
||||
todo!()
|
||||
if let Some(s) = second {
|
||||
let second = match s.parse() {
|
||||
Ok(s) => s,
|
||||
Err(_) => {
|
||||
self.mode = Mode::TimeZone;
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
if second > 60 {
|
||||
return Err(Error::InvalidSecond);
|
||||
}
|
||||
self.second = Some(second);
|
||||
}
|
||||
self.mode = Mode::TimeZone;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn parse_timezone(&mut self) -> Result<(), Error> {
|
||||
assert_eq!(self.mode, Mode::TimeZone);
|
||||
let tz = match self.format {
|
||||
Format::Basic => self.text.get(15..),
|
||||
Format::Extended => self.text.get(19..),
|
||||
let idx = if self.second.is_some() {
|
||||
match self.format {
|
||||
Format::Basic => 17,
|
||||
Format::Extended => 21,
|
||||
}
|
||||
} else if self.minute.is_some() {
|
||||
match self.format {
|
||||
Format::Basic => 15,
|
||||
Format::Extended => 19,
|
||||
}
|
||||
} else if self.hour.is_some() {
|
||||
match self.format {
|
||||
Format::Basic => 13,
|
||||
Format::Extended => 16,
|
||||
}
|
||||
} else if self.day.is_some() {
|
||||
match self.format {
|
||||
Format::Basic => 9,
|
||||
Format::Extended => 11,
|
||||
}
|
||||
} else if self.month.is_some() {
|
||||
match self.format {
|
||||
Format::Basic => 6,
|
||||
Format::Extended => 8,
|
||||
}
|
||||
} else {
|
||||
4
|
||||
};
|
||||
match self.text.chars().nth(idx) {
|
||||
Some('Z') => {
|
||||
if self.text.len() > idx + 2 {
|
||||
return Err(Error::TrailingGarbage);
|
||||
} else {
|
||||
self.tz = Some(TimeZone::UTC);
|
||||
return Ok(());
|
||||
}
|
||||
},
|
||||
Some('-') => todo!(),
|
||||
Some('+') => todo!(),
|
||||
None => self.mode = Mode::Finish,
|
||||
_ => return Err(Error::InvalidTimezone),
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue