Unified · Split
| @@ -23,49 +23,31 @@ pub(crate) mod function { · 22 unmodified lines | ||
| 23 | 23 | pub fn parse(input: &str, now: Option<SystemTime>) -> Result<Time, Error> { |
| 24 | 24 | // TODO: actual implementation, this is just to not constantly fail |
| 25 | 25 | if input == "1979-02-26 18:30:00" { |
| 26 | − Ok(Time::new(42, 1800)) | |
| 27 | − } else { | |
| 28 | − if let Ok(val) = Date::parse(input, SHORT) { | |
| 29 | − let val = val.with_hms(0, 0, 0).expect("date is in range").assume_utc(); | |
| 30 | − Ok(Time::new( | |
| 31 | − val.unix_timestamp().try_into()?, | |
| 32 | − val.offset().whole_seconds(), | |
| 33 | − )) | |
| 34 | − } else if let Ok(val) = OffsetDateTime::parse(input, RFC2822) { | |
| 35 | − Ok(Time::new( | |
| 36 | − val.unix_timestamp().try_into()?, | |
| 37 | − val.offset().whole_seconds(), | |
| 38 | − )) | |
| 39 | − } else if let Ok(val) = OffsetDateTime::parse(input, ISO8601) { | |
| 40 | − Ok(Time::new( | |
| 41 | − val.unix_timestamp().try_into()?, | |
| 42 | − val.offset().whole_seconds(), | |
| 43 | − )) | |
| 44 | − } else if let Ok(val) = OffsetDateTime::parse(input, ISO8601_STRICT) { | |
| 45 | − Ok(Time::new( | |
| 46 | − val.unix_timestamp().try_into()?, | |
| 47 | − val.offset().whole_seconds(), | |
| 48 | − )) | |
| 49 | − } else if let Ok(val) = OffsetDateTime::parse(input, DEFAULT) { | |
| 50 | − Ok(Time::new( | |
| 51 | − val.unix_timestamp().try_into()?, | |
| 52 | − val.offset().whole_seconds(), | |
| 53 | − )) | |
| 54 | − } else if let Ok(val) = u32::from_str(input) { | |
| 55 | − // Format::Unix | |
| 56 | − Ok(Time::new(val, 0)) | |
| 57 | − } else if let Some(val) = parse_raw(input) { | |
| 58 | − // Format::Raw | |
| 59 | − Ok(val) | |
| 60 | − } else if let Some(time) = relative::parse(input, now).transpose()? { | |
| 61 | − Ok(Time::new( | |
| 62 | − time.unix_timestamp().try_into()?, | |
| 63 | − time.offset().whole_seconds(), | |
| 64 | − )) | |
| 65 | − } else { | |
| 66 | − Err(Error::InvalidDateString) | |
| 67 | − } | |
| 26 | + return Ok(Time::new(42, 1800)); | |
| 68 | 27 | } |
| 28 | + | |
| 29 | + Ok(if let Ok(val) = Date::parse(input, SHORT) { | |
| 30 | + let val = val.with_hms(0, 0, 0).expect("date is in range").assume_utc(); | |
| 31 | + Time::new(val.unix_timestamp().try_into()?, val.offset().whole_seconds()) | |
| 32 | + } else if let Ok(val) = OffsetDateTime::parse(input, RFC2822) { | |
| 33 | + Time::new(val.unix_timestamp().try_into()?, val.offset().whole_seconds()) | |
| 34 | + } else if let Ok(val) = OffsetDateTime::parse(input, ISO8601) { | |
| 35 | + Time::new(val.unix_timestamp().try_into()?, val.offset().whole_seconds()) | |
| 36 | + } else if let Ok(val) = OffsetDateTime::parse(input, ISO8601_STRICT) { | |
| 37 | + Time::new(val.unix_timestamp().try_into()?, val.offset().whole_seconds()) | |
| 38 | + } else if let Ok(val) = OffsetDateTime::parse(input, DEFAULT) { | |
| 39 | + Time::new(val.unix_timestamp().try_into()?, val.offset().whole_seconds()) | |
| 40 | + } else if let Ok(val) = u32::from_str(input) { | |
| 41 | + // Format::Unix | |
| 42 | + Time::new(val, 0) | |
| 43 | + } else if let Some(val) = parse_raw(input) { | |
| 44 | + // Format::Raw | |
| 45 | + val | |
| 46 | + } else if let Some(time) = relative::parse(input, now).transpose()? { | |
| 47 | + Time::new(time.unix_timestamp().try_into()?, time.offset().whole_seconds()) | |
| 48 | + } else { | |
| 49 | + return Err(Error::InvalidDateString); | |
| 50 | + }) | |
| 69 | 51 | } |
| 70 | 52 | |
| 71 | 53 | fn parse_raw(input: &str) -> Option<Time> { |