From 230b8ac48abc2714b86ca5d3f07cb996a04cd45a Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Fri, 9 Jun 2023 02:19:55 -0400 Subject: [PATCH] Progress on Time parser --- src/time/parser.rs | 60 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/src/time/parser.rs b/src/time/parser.rs index 7faed83..37055c8 100644 --- a/src/time/parser.rs +++ b/src/time/parser.rs @@ -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!() }