Add several parser methods for Time
This commit is contained in:
parent
5daa6ca377
commit
669fa0889b
1 changed files with 64 additions and 4 deletions
|
@ -70,7 +70,13 @@ impl<'a> Parser<'a> {
|
||||||
Format::Extended => self.text.get(5..7),
|
Format::Extended => self.text.get(5..7),
|
||||||
};
|
};
|
||||||
if let Some(m) = month {
|
if let Some(m) = month {
|
||||||
let month = m.parse()?;
|
let month = match m.parse() {
|
||||||
|
Ok(m) => m,
|
||||||
|
Err(_) => {
|
||||||
|
self.mode = Mode::TimeZone;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
if month > 12 {
|
if month > 12 {
|
||||||
return Err(Error::InvalidMonth);
|
return Err(Error::InvalidMonth);
|
||||||
}
|
}
|
||||||
|
@ -89,7 +95,13 @@ impl<'a> Parser<'a> {
|
||||||
Format::Extended => self.text.get(8..10),
|
Format::Extended => self.text.get(8..10),
|
||||||
};
|
};
|
||||||
if let Some(d) = day {
|
if let Some(d) = day {
|
||||||
let day = d.parse()?;
|
let day = match d.parse() {
|
||||||
|
Ok(d) => d,
|
||||||
|
Err(_) => {
|
||||||
|
self.mode = Mode::TimeZone;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
let max = match self.month {
|
let max = match self.month {
|
||||||
Some(1|3|5|7|10|12) => 31,
|
Some(1|3|5|7|10|12) => 31,
|
||||||
Some(2) => {
|
Some(2) => {
|
||||||
|
@ -127,21 +139,69 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
fn parse_hour(&mut self) -> Result<(), Error> {
|
fn parse_hour(&mut self) -> Result<(), Error> {
|
||||||
assert_eq!(self.mode, Mode::Hour);
|
assert_eq!(self.mode, Mode::Hour);
|
||||||
todo!()
|
let hour = match self.format {
|
||||||
|
Format::Basic => self.text.get(9..11),
|
||||||
|
Format::Extended => self.text.get(11..13),
|
||||||
|
};
|
||||||
|
if let Some(h) = hour {
|
||||||
|
let hour = match h.parse() {
|
||||||
|
Ok(h) => h,
|
||||||
|
Err(_) => {
|
||||||
|
self.mode = Mode::TimeZone;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if hour > 24 {
|
||||||
|
return Err(Error::InvalidHour);
|
||||||
|
}
|
||||||
|
self.hour = Some(hour);
|
||||||
|
self.mode = Mode::Minute;
|
||||||
|
} else {
|
||||||
|
self.mode = Mode::TimeZone;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_minute(&mut self) -> Result<(), Error> {
|
fn parse_minute(&mut self) -> Result<(), Error> {
|
||||||
assert_eq!(self.mode, Mode::Minute);
|
assert_eq!(self.mode, Mode::Minute);
|
||||||
todo!()
|
let minute = match self.format {
|
||||||
|
Format::Basic => self.text.get(11..13),
|
||||||
|
Format::Extended => self.text.get(14..16),
|
||||||
|
};
|
||||||
|
if let Some(m) = minute {
|
||||||
|
let minute = match m.parse() {
|
||||||
|
Ok(m) => m,
|
||||||
|
Err(_) => {
|
||||||
|
self.mode = Mode::TimeZone;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if minute > 60 {
|
||||||
|
return Err(Error::InvalidMinute);
|
||||||
|
}
|
||||||
|
self.minute = Some(minute);
|
||||||
|
self.mode = Mode::Second;
|
||||||
|
} else {
|
||||||
|
self.mode = Mode::TimeZone;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_second(&mut self) -> Result<(), Error> {
|
fn parse_second(&mut self) -> Result<(), Error> {
|
||||||
assert_eq!(self.mode, Mode::Second);
|
assert_eq!(self.mode, Mode::Second);
|
||||||
|
let second = match self.format {
|
||||||
|
Format::Basic => self.text.get(13..15),
|
||||||
|
Format::Extended => self.text.get(17..19),
|
||||||
|
};
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_timezone(&mut self) -> Result<(), Error> {
|
fn parse_timezone(&mut self) -> Result<(), Error> {
|
||||||
assert_eq!(self.mode, Mode::TimeZone);
|
assert_eq!(self.mode, Mode::TimeZone);
|
||||||
|
let tz = match self.format {
|
||||||
|
Format::Basic => self.text.get(15..),
|
||||||
|
Format::Extended => self.text.get(19..),
|
||||||
|
};
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue